On the third (and final) class in my series of teaching Shoes and Ruby to 4th/5th graders, I decided to teach them to create a game. I met with my two fifth grade helpers the afternoon before the day of the class. I taught them how to create text and buttons and add a click method and showed them the Shoes manual, then let them experiment. This was a good experience for them, but we ended the day with a more complicated program than I felt we could do with the class and it incorporated internet images which wouldn’t work in the classroom since Internet connectivity isn’t working right now. I also ended up getting beyond my Shoes experience and had to ask help of the Shoes list. After some help from some kind souls, this was the app the kids wrote:

class OurApp < Shoes
 url '/',  :index

 def index
   clear
   para "Which is correct?"
   stack {
     @correct = button "A bed of clams"
     @wrong1 =button "A coalition of cheetahs"
     @wrong2 =button "A gulp of swallows"
   }

   @correct.click {
     clear
     para "Correct"
     image "http://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/Balloons-aj.svg/550px-Balloons-aj.svg.png"
     button "Go Back" do
       visit "/"
     end

   }
   @wrong1.click {
     clear
     para "Wrong!"
     image "http://icanhascheezburger.files.wordpress.com/2007/05/cheez_doing_it_wrong.jpg"
     button "Go Back" do
       visit "/"
     end
   }
   @wrong2.click {
     clear
     para "Wrong, your consolation prize is..."
     image "http://farm2.static.flickr.com/1166/1230713908_083d7f6c53_o.jpg",
     :width => 500
     button "Go Back" do
       visit "/"
     end
   }

 end  # this is the end of the index method, which lays out the "/" page

end # this is the end of the subclass, which contains all the pages (well, one page)

Shoes.app

I ended up teaching the class a much more simplified version. I think the initial session with two students worked well as a great approach to developing a lesson plan. I improved it even more in my live coding session where I built up the app in stages (with compile and demo between each of the steps below):

  1. Shoes app with para “Which is correct?”
  2. Add three buttons
  3. Add stack around the buttons
  4. Move the app into Game subclass, show that it has the same behavior
  5. Add ‘/correct’ url, button click action, and show_correct method
  6. Add ‘/wrong’ url, button click action, and show_correct method

Then a student asked how to ask another question if after someone got the right answer. I just made another url and added a button with a visit action to the show_correct method.

After the demonstration, I gave them a copy of the program for reference and told them not to copy it — they had to come up with their own questions and answers. Of course, then they typed in the whole program verbatim only substituting different editorial and ended up with dozens of syntax errors.  I wish I had instructed them to do it just like I had and build up their app in several steps, and I did tell them to do that, after they started, but at first they were somehow convinced that all they needed to do was type it in to complete the assignment. Another approach would be to get them to follow along with me and get the whole class to complete each step before moving on the the next; however, once they have their hands on the keyboard it is really hard to get their attention.  I also forgot to accidentally on-purpose type things wrong and demonstrate debugging.   In any case, the students were engaged and reported having fun, even if most did not finish the game.

Here’s my revised version of the app (improvements were to name the url and the method differently to make it clear that they were different things and to create just one “wrong” url and method to show reusing a method).

class Game < Shoes
  url '/',  :index
  url '/correct',  :show_correct
  url '/wrong',  :show_wrong

  def index
    clear
    para "Which is correct?"
    stack { 
      @correct = button "A bed of clams" do
        visit "/correct" 
      end 

      @wrong1 =button "A coalition of cheetahs" do
        visit "/wrong" 
      end

      @wrong2 =button "A gulp of swallows"  do
        visit "/wrong" 
      end
    }
  end  # this is the end of the index method, which lays out the "/" page
   
  def show_correct
    para "Correct"
  end  # of the "correct" method, which lays out the "/correct" page
    
  def show_wrong
    para "Sorry, try again."
  end  # of the "wrong" method, which lays out the "/wrong2" page

end # this is the end of the "Game" subclass, which contains all pages

Shoes.app 

Report from the field on my ongoing adventure teaching Ruby and Shoes to a 4th/5th grade class of 28 students. Here’s a summary of last week’s class:

I started with a demonstration of red, green, blue color: 3 flashlights with colored gels over the front, mixing red + green to get yellow , then add blue to get white. I talked about how last week we made Shoes draw a colored rectangle on the screen. The screen is made up of lots of little dots. Does any one know what they are called? one hand, correct answer: pixels. Then I described how each pixel is a little light. A pixel was a single light in the old days when all monitors were black and white. Color screens, which are on most computers today, have pixels which each have three little lights. When we make colors on the computer, we are making colors with light, which is quite different than making colors with paint. Then we turned out all the lights and it got really fun.

I showed the flashlight with the blue gel covering the front and splashed a blue light on the ceiling. Then I took the cover off and showed how the flashlight emits white light, but it comes comes out blue when I put the blue gel over it. I asked them first what did they think happened that made a white light come out as a blue light when I put the blue plastic over the front of the flashlight? (lots of theories of magical color transformation and after a few tries, I supplied to correct answer which is that white light contains all of the colors and when it hits the blue plastic every color except blue bounces off and blue is the only color that gets through.)

When you mix red + green paint, what do you get? (several tries before one of them got the right answer: brown) I told them that light mixes differently than paint. We call mixing light “additive” and when you you add the colors together they get brighter, as opposed to subtractive color with paint where mixing them makes the colors darker. Then with the help of my two assistants we demonstrated color mixing with light (See on understanding rgb color for complete details.) It was way cool.

Then we moved on to the programming exercise which was about “computer generated art” making a loop with shapes that have random color, position and size. Fewer setup problems this time. I had 3 extra computers set up and still ended short one and ended up once again abandoning my idea of a coding demo yet again since I gave the “teacher” computer to a pair of students. I ended up writing code snippets on the board and spending more time with each group of 2-3 kids helping debug syntax errors and giving little impromptu explanations of what was going on.

I’m torn between how much time to spend explaining concepts (since they are always antsy to get onto the computers) and how much to let them wing it (which then is frustrating to them because they don’t know the rules. I would welcome suggestions from anyone on the right balance here. I suspect different people just learn differently, but what’s the best way to manage that in a classroom full of kids?

At the end of the class I asked them to raise hands to answer: who thought it was fun? (about 2/3s of the class) who thought it was frustrating? (maybe 40%) who thought it was fun even though it was frustrating (about 1/3). I really don’t know what impact these classes are having, but I will forge ahead nonetheless. The teacher seems to think the lessons are great and the kids report having more fun than it looks like they are having. I do feel like about half the class is starting to “get it.” Not sure if that is a lot or very few after 1.5 hours of programming experience.

I was still following my original lesson plan. Even though most of the kids haven’t gotten through the final exercise, I think I’ll switch it up next week to add some interactivity.

The Shoes list and whytheluckystiff himself have been very responsive in answering my technical questions, and everyone on those lists and Railsbridge have provided encouragement that really makes a difference.

Someone from the lists gave me the very awesome advice of training some of the kids to help with the lessons. I did this after school the day before the class with two of the fifth graders and it made a huge difference. They ran around and helped other kids debug their apps and I was freed up to spend more time on impromptu theory lessons and writing additional examples on the whiteboard. It was a great experience for the two TAs, and made the whole class more fun for me and the other kids.

Last week I wanted to teach the kids how to create a randomly colored shape, which (in Shoes) would use a fill color like this:

fill rgb(0..255.rand, 0..255.rand, 0..255.rand)

I figured they could easily grasp the random number syntax, but creating colors as a mix of red, green, and blue? They are used to primary colors of red, yellow and blue. It is totally weird that green and red make yellow, and downright amazing that red, green and blue make white. You have to be an old school graphics geek like me or someone who does stage lighting to have gained any intuition about how these kinds of colors mix. Most folks, elementary school students included, only have experience mixing colors with paint or dye, where red and green make brown. That is called “subtractive” color mixing. When we mix light (and pixel values), it is called additive color mixing.

To explain this, I put together a neat physical demonstration with the help of my friends, Paul & Glen, from Emotion Studios, and Janet from JCX Expendibles. (As a side note, I must say that if you live in San Francisco, enjoy this article and periodically need random materials for your crazy projects you must visit JCX on Harrison Street. It is awesome.)

My goal was to create three spots of color (red, green, and blue), then mix them to create white where they overlap. This looks much cooler in real life…

I ended up finding it could work using three Mini Maglight flashlights (about $14 each, which adds up but I figured I could use them for camping later). The front of each light is covered by a gel. I used the following colors from Lee Filters (the big sheets are $6 each, but I bet if you called them up they would send you a sampler). I used these colors:

  • Primary Green 139
  • Primary Red 106
  • Just Blue 079

I highly recommend this demonstration when teaching anyone about rgb color. This would even make a fun early physics experiment for first graders.