Saturday, February 5, 2011

Lesson 2: Objects

Last week, we learned pixels, and painted a copy of The Pear.  She looks great, so The Monster was ready to put her into Scratch!

Now was the time to talk about what an object is, or at least an object in the language of Scratch.  We talked about how computer programs are comprised of data and instructions, and that when we think of an object, it's about combining the data and instructions into one thing.  In Scratch, this works very cleanly with the fact that scripts are attached directly to sprites.  The programmer never dictates what data (sprite) is being addressed by the script, because the script is tied directly to the sprite (no sprites = no code).

Scratch is imperfect here too... it's actually quite tricky to instantiate a new sprite, and I made the mistake last week of having The Monster create a new "costume" (new sprite animation state) from the original default sprite, rather than starting anew with a fresh sprite.  A little tomfoolery though and The Pear was its own sprite, and we were ready to go.

I was amazed at how quickly The Monster was able to get The Pear under her command.  I gave her the assignment to make The Pear do a complete spin and though she didn't do it the most elegant way (hmm, looks like maybe loops are a future lesson?), her solution does indeed have The Pear spin, just about right:

(sorry for the lousy photo quality)

Well, almost.  The Pear was spinning a little bit too much.  Each of the steps she plopped in was rotating the sprite 15 degrees, and she was overspinning a bit.  Time for a lesson in measuring angles of a circle.

Being a modern soul, I couldn't even find a protractor on my desk... but the internets quickly remedied that.  We looked at a picture of a protractor and talked about one circle equaling 360 degrees, and the various subdivisions of that, including the 15 degree increments her script was using.  I then took out a pocket calculator (which doubles as an iPhone) and asked her if she could determine how many of these 15 degree steps would really be required to get to exactly 360 degrees.

This was a tough one.  She knew that the problem was division, but had to work her way through what gets divided by what.  Eventually she sorted out it was 360/15, which provided the answer:  there should be 24 steps.  When we made sure there were exactly 24 steps, sure enough, The Pear spins perfectly.

I thought that was enough for a day, but The Monster wanted to plow forward!  So, sticking with today's lesson of objects, she imported a new sprite, gave it its own behaviors, and we watched the two sprites operate independently on the screen, not interfering with each other, as proper objects shouldn't.  Right now, she's making a brand new sprite, which she says is an enemy.  It'll apparently get its own behaviors too.

Go Monster, go!

First Week's Lesson: Pixels

The Little Monster is creating her software in Scratch, which means that she needs to start by having a Sprite to control.  Scratch works by having Sprites and their behaviors tightly linked (sort of a primitive object-oriented structure).  It comes with a default kitty cat (who we conveniently just call "Scratch") but it didn't feel right to have the Monster work just with some other person's sprite.

So it was time to create The Pear.

To create the Pear, we first need an understanding of what a pixel is.  We had a couple routes for this.  First we talked about what the word "pixel" means.  It took a while but the Monster now knows, "picture element".  Then I had her lean way forward and look closely at the screen of the iMac, right up where she could see the little square blocks that make up the screen image.  This was a revelation!  Wow, the whole screen is just a bunch of those little blocks!  Yup, those are pixels.

Next, it was time to create the Pear.  For this, we had a secret weapon.  The Monster's very creative mom had hit think geek for xmas ideas and had gifted the Monster and Daddy D with the toy called pixelblocks. These things are a fun toy, and a great tool for understanding the concept of pixels.

Using pixelblocks, The Monster and I had already built a prototype of The Pear.  It looks like this:

This prototype was great because we could talk about the concept of X and Y coordinates, and the fact that the computer scans left to right as it draws the image.  So just like how the computer draws one pixel at a time, we can count the pixels in The Pear here, and replicate that on the computer.

We started at the top of the head, and, counting as we went, The Monster re-created the pixel blocks version on the computer.

This turned out to be very difficult and awkward.  Single pixels weren't going to work very well on this high-res screen, and I couldn't find a decent pixel editing program (what ever happened to Dpaint, anyway?).  So we had to draw large squares in Scratch's primitive bitmap editor.  It was a lot of work, and I had to help out the Monster quite a bit in getting those squares lined up correctly.

But, success!


There The Pear is, in all her glory!  (Yes, The Pear is a girl.  The Monster says so.)

Next week... time to get The Pear into the software!

Saturday, January 29, 2011

The Monster Wants to Make a Game

A couple of months ago, my daughter (for the purposes of this blog I'll refer to her using her nickname, "The Monster") and I were on the train heading into San Francisco for a day of sightseeing, and she said to me, "Daddy, I want to make an app."

"You mean, like an iPhone app?"

"Yes."

"What sort of app?  What does it do?"

"Well, I want to make an app where you point the camera at a plant or a flower, and it tells you what that flower is."

"Wow, that would be an amazing app!  But, that would be very hard to make.  Can you think of something a little bit easier?"

"Well, I like playing games on your iPhone Daddy.  Do you think I could make a game?"

"I do.  I think that's a fun idea."

So for the next half hour, and then the ride back to my place south of the city, we designed a game together.  It's got a pear as the main character, and it uses tilt and physics to solve puzzles.  It seemed kind of neat, and I enjoyed the process, and she seemed to too.  And I thought, that's the end of it.

Then, in November, a good friend of mine and fellow game designer talked me into joining him in giving a workshop.  The workshop was for local high school teachers, to talk to them about how to help their students make games.  The sponsor of the workshop was the Alliance for Young Artists and Writers , who have sponsored a wonderful and famous contest for creative high school students for many years, and have recently added the creation of games to their awards.

In preparation and then at the workshop, my colleague and I ultimately despaired.  The hurdles are too high to tell the teachers a few simple steps to turn their students into creators of computerized interactive art.  The teachers were grateful, and gracious, but I felt like I had failed.

In the days after the workshop I thought, this task would have been so much easier if only kids were taught to program.  If kids had programming literacy, we could put a tool like Flash or Torque or Unity in front of the kids and just watch what wonder they'd create.  Yet programming is still viewed as an advanced, or niche, skill.  But I've done programming... I know... it really isn't that hard!

So I started to think, maybe we should make The Monster's game, she and I.  And a few days later, I installed Unity and we started to experiment with the editor.  I mixed in some lessons about what hardware is, and software, and things like that.  But this was way too much, way too fast.

So I took a step back, and discovered the marvelous tool from the MIT Media Lab called Scratch.  It's a graphical, object-oriented programming tool that's perfect for elementary school kids.  The Monster spent some time with it and started having success, creating programs, debugging them, and learning about the process.

Now, every Friday afternoon after school, The Monster and I spend an hour or so doing programming.  This week, we started on The Monster's game, and I started this blog.  We'll let you know how it goes!