Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Tuesday, November 3, 2015

Loop-de-loop festival (math games and programming classes)

who: all grades at Baan Pathomtham
when: throughout the school day

First, Apologies! With other obligations, this is over a week late.

Second, I've already written about loop-de-loops here and here. You can find the basic explanations and background there.

In this write-up, I just want to explain how we played with loop-de-loops in the classroom and the reaction of the students. With pictures! Our experiences come in two flavors, based on the two different kinds of classes we were leading:

  • Math games/exploration, for grades 1-3, notes here
  • Programming, for grades 5 and 6, notes here

Math games and exploration

In these classes, I started at the front of the class with a small(ish) whiteboard to show them the simple rules. Following Anna Weltman's instruction page, I drew a 2-3-4 loop-de-loop as follows:
  1. Draw a line up the page for 2 units (I marked ticks to provide a reference for 2 units)
  2. Turn the whiteboard clockwise 90 degrees
  3. Draw a line up the page for 3 units
  4. Turn the whiteboard clockwise 90 degrees
  5. Draw a line up the page for 4 units
  6. Pause and ask the kids what they thought I would do next, with a little discussion, then ...
  7. Turn the whiteboard clockwise 90 degrees
  8. Ask them how long a line I should drawwith a little discussion, then ...
  9. Draw a line up the page for 2 units
  10. Ask them, if I continue this 2, rotate, 3, rotate, 4, rotate, 2, rotate, 3, rotate, etc, will I get back to my starting place? After a little debate amongst the kids with opposing views expressed, I turned them loose to try it out on their own graph paper.
For the rest of the class, the kids asked me for more seeds and/or experimented with their own ideas. A couple are worth noting:
  • 3-5-2: This is on Anna's instruction page. The kids found it surprisingly challenging. The issue comes during one step where you end on a pre-existing line, but not at one of the endpoints. That seemed to make it easy for people to lose their place or get confused about what they should do next.
  • 4 number sequences: both closed loops (like 4-7-4-7) and open ones (1-2-3-4) really interested the kids. I have a (mild) reputation for teasing them, so they were somewhat on the look-out for a twist like this.
  • 6 number sequences: they discovered these on their own or had a more experienced friend suggest them.
Why was this a great activity for the kids?
First, mathematically, there are tons of patterns waiting to be discovered, almost all of which are easily accessible and where the kids can set their own direction for exploration. We will write up an example in next post about the math classes.

Second, this shows some important aspects of mathematics that we often forget: it isn't just about calculating and it has a deep aesthetic (artistic) side.

Programming

The basic introduction was similar for the two programming classes. I showed the essential rules, then the kids drew some loop-de-loops on paper. Of course, the natural next step is writing a program to generate the pictures.

After more or less coaching, all the kids wrote a double for loop to draw their loop-de-loops.

Why was this a great activity for the kids?
First, it was a very natural context to use double for loops, including an outer loop where the steps are just repeated exactly and the other where the iterating variable changes as it moves through a list of step sizes.

Second, repeating, exactly, a list of instructions over and over shows off the power of the machine over hand-calculating. In this sense, it was easier to create programs to draw loop-de-loops than to draw them by hand. When doing them manually, almost all of us occasionally lost track of where we were, turned the wrong way, or made a line the wrong length.

Which brings us to: third, we got to use the computers as a tool to support our own investigation of the loop-de-loop patterns. This was because it was so easy to draw so many versions so quickly. One example was comparing the 1-2-4 shape with the 4-1-2 shape and the 4-2-1 shape. Wait for the next post for another example.

Fourth, when writing their programs, all the kids scaled their drawings.  For example, in the 1-2-4 shape, some chose to make the step lengths 100-200-400, while others chose 25-50-100, while others made different choices. This gave us a chance to talk about these scaling choices and to introduce an explicit scaling variable. Some of this continued into the next class.

Finally, in the 6th grade class, the use of computers gave them free rein to explore much longer and more complicated step sequences than they could have considered by hand.

Pictures

Oh, right, you just wanted to see pictures. Here you go!






Sunday, August 9, 2015

Bullseyes and spirals

Fifth grade

The class focused on using variables and for loops in our spiral programs from the homework. Here are the programs the kids wrote:

More Variables and Loops

For the class, we worked on "refactoring" the spiral programs. First, we noticed that the spirals consisted of repeating lines of code that were all similar, for example:
rt 180, 20
rt 180, 40
rt 180, 60
rt 180, 80
rt 180, 100
Whenever we see the same code repeated, we should think about using a loop in some from. In this case, however, the code isn't perfectly identical, each line changes the size of the arc. That gives us the idea to make that size into a variable that can change in each iteration of the loop. Playing withthe basic programs, we learned the following about variables:

  • variables can have (almost) any name. The name is just a label, the computer can't interpret the label to figure out what the variable is supposed to do. We tested loops that used variables name size, howBig, and our names (in English and Thai).
  • if you use a variable without telling the computer what it is (either defining the values in a loop or with an explicit assignment) then the computer can't make sense of the variable. This is particularly a danger if we change the name of our variable, but accidentally leave some uses of the earlier name.
  • pencilcode already understands some words (dot, fd, rt, green, etc). We are allowed to use those as variable names, but it will create strange effects if we also try to use the default definitions. A great example is here: http://tatia512.pencilcode.net/edit/forrube and here http://jung.pencilcode.net/edit/green
In the for loops, we mostly played with different ways of specifying the list of values to iterate:

  • explicit list [20, 40, 60, 80, 100]
  • [100..20] by -20
  • using a reference variable (e.g,. for x in [1..4] and howBig = 100 - 20 * x). This is something we will expand in the future.
  • also, a key issue we considered was what happens when a command is in or outside the for loop!
Note: almost all of these observations and forms arose naturally from things the kids were trying in their investigations.

For future discussions

Homework

Reproduce the bullseye using a for loop and variables instead of individual lines of code. Recall this picture: 


We want to use for loops and variables so that we can easily change the size or colors of the bullseye.

Sixth grade

bullseye loops

We recalled the code paradigm
for x in [1..10]
  write x #don't forget the indentation!
We continued to test variations of the use of variables and for loops, quite similar to the discussion in Fifth Grade. The bullseye is giving a particular challenge because we want to take similar, but not identical action on alternating iterations of the loop. Here are a collection of techniques we identified:

  1. each iteration, create both the black and the white dots. The challenge here is to control the sizes so that all the bands end up with reasonable/pleasing sizes.
  2. find a way to alternate which color is used. Titus figure out he could do this with an if statement.
  3. Use a double for loop, possibly taking advantage of the counter reference variable that pencilcode for loops give us. That is, for color, iteration in [black, white] will loop two times with the following values: color = black and iteration = 0, then color = white and iteration =1. here is an implementation that solves our bullseye problem: http://titusorc.pencilcode.net/edit/project/dot/8-dots

A key point of confusion was whether to have the looping values increase or decrease.

Homework

Create your own version of this spiral team program:


It is possible that the kids won't be able to complete the whole program, but I would like to see how much progress they can make decomposing the picture and separating components of the program.

Other notes
flowers
change an old polygon program to a star maker

Monday, August 3, 2015

Variable Ladder of abstraction (Programming classes)

Fifth grade

We started by discussing the homework from last time: drawing a 5 pointed star:
The students had two key questions from this activity:
  1. How do we get the star to close up exactly, making the final stroke end at the starting point? This question we are saving for a later class.
  2. how do we make a regular star (all sides and angles equal)? This served as the focal activity for the rest of the class.
Start with regular polygons
We noticed that a regular pentagram has a pentagon inside. How can we make a regular pentagon? As they wrote programs to meet this challenge, they quickly recognized that they could repeatedly move forward and turn, but the key issue is how much to turn.

I had already prepared this toy to help us investigate that question:

The code is here: Exterior Angles Toy. As desired, they noticed that the exterior angles have to add up to 360 degrees. To get every angle the same, we divide by 5 to get 72 degrees.

As a next step, we had them modify the program to use a for loop.  This opened up an opportunity to explore regular polygons with more (or fewer) sides and, again, the question of what the exterior angles should be.

Variables to the rescue
As we played with examples, we noticed that there are two key part of their code that need to change when they change the number of sides: the number of repeats in the loop and the angle. This leads us to two ideas that we will develop further next week:

  1. use a variable (numberOfSides, or something similar): how, when, why?
  2. get the computer to calculate the correct angle: how, why?


Here are our whiteboard notes from the class:



For reference next time, we will also talk about these ideas based on our flower programs from the prior session (our final session of last term):
Homework
  1. Draw a spiral that starts from the inside and grows outward
  2. Draw a spiral that starts outside and shrinks to the center
You can see where we explained the spirals on the whiteboard above.

Grade 6

Variables
Parallel to the discussion in Grade 5, we set a sequence of challenges around the use of variables. As it turned out, this was hugely helpful in revealing gaps in the students' understanding.

We started with a simple bullseye program: manual bullseye.

An easy program, now, what if we suddenly decide we want the bullseye to be bigger? The students came up with three solutions:
  1. add a command scale 3, for example, to the beginning of the program. This is a good approach because we then control the size with a single parameter in one location. One problem using this is that we then scale any other movement or drawing in the rest of the program, though that can also be fixed with a "closing" scale command to shrink back to normal size.
  2. manually change all of the parameters for the dots. This actually encompasses many different changes, depending on what relationships you want to preserve between the size of the layers. For the most part, the students chose to preserve the absolute difference in the sizes (e.g., 90-72-54 got changed to 108-90-72). The weakness of this approach shows up right away when the "client" asks to have the size changed again.
  3. add a variable to control the size. 
Again, there were many different ways to incorporate a size variable: linear differences (size - 15), proportional differences (size * 2), or inverse proportionality (300/size). We investigated these different approaches and talked about strengths and differences.

Non-numeric variable
After sorting out some ways to control size, the next "client" demand was to change the color of the black layers to blue and, later, to green. This flagged the fact that we could have a variable that is a number, as with size, or a color, or a string.

Variables allow flexibility
One of the key ideas from using variables is that they give our programs greater flexibility. That's particularly true when we combine with a loop, so, naturally, our last challenge was to try to reproduce the bullseye with a for loop. That was left for homework.

Homework
Finish the bullseye version using a for loop, get ready for some unreasonable demands from the teachers to change the number of layers, the sizes, and the colors!


Side note and future reference: 
Other interesting things the students have discovered, but which we didn't have time to discuss:
  • http://chunly.pencilcode.net/edit/triangle
  • donut loop: http://jung.pencilcode.net/edit/O./donut
  • nice fish: http://tatia512.pencilcode.net/edit/FISH
  • input/output: http://jung.pencilcode.net/edit/O./myprogram
6th Grade Projects
  • Gan chase game
  • Boongie animal sound recognition
  • Titus: space invaders variation
  • Win: car driving game

Tuesday, July 7, 2015

Yin-yang and lasers (programming class)

Grade 5

Yin-yang programs from homework
As before, everyone did a really great job attacking the yin-yang challenge. As with last year, this turned up some interesting questions about using the fill command.

A creative variant from Chun (this is my slight recreation, she edited her own program during the class):


One of Jung's programs, with the other versions faded and tricky:


Classic from Tatia:


Interestingly, Pitchee used a different method to create the same picture. It is worth taking a look at her program in the editor so you can see the animation difference: Pitchee's YinYang.
In particular, this illustrates a method of building up more complicated pictures using simple elements that you already understand.

Inspired by Jung's name last week, I made my own version with a pair of dancing turtles:
http://jgplay.pencilcode.net/home/class/koreaYinYangDuo

Fill investigation
Based on the questions from the homework, we wanted to do some investigation of different fill variations. These are versions we looked at:

  1. What happens if you have a program without a pen command, but you end a series of movements with fill red? The answer we found was that the fill doesn't do anything.
  2. Does it matter where, within a sequence of moves, you order your command pen path? Yes, it matters very much. Movements prior to that command will only position the turtle for the start of the fill.
  3. What if we use pen blue (or some other color) instead of pen path? This still creates a filled shape, but now we get an outline of our chosen pen color.
  4. What if we make a path that doesn't have a clear "inside" and "outside," what will get filled? We made an "N" shape and were all a bit surprised about what got filled. The key point is that the computer will still follow whatever algorithm it has for determining where to fill, but it may not do what you expect. The solution is to control the output by creating cases where you know what the computer will do.

More for loops
Finally, we worked through these:
- look at range program http://guide.pencilcode.net/edit/loops/range, also looked at see [5..1]
- replicate dandelion picture: http://guide.pencilcode.net/home/loops/dandelion

Homework
Finish the flower and replicate this star: http://jgplay.pencilcode.net/home/class/goldStar
Try to use loops for both!

For next time
We will continue working on loops, probably in next term.
- look at rectangle: http://guide.pencilcode.net/edit/loops/rectangle
- replicate rainbow: http://guide.pencilcode.net/home/loops/rainbow

Grade 6

Laser attributes
Our focus today was on creating a new object with various attributes and then getting objects to interact.

In the first investigation, we simply created a new object and then changed the attributes to see what would happen: http://jgplay.pencilcode.net/edit/class/spriteTidbit
We had to do a deeper investigation of the function rgb() to make sure we understood what colors were getting produced. One of the ideas we discovered was that we could make our laser sprite larger so that it is easier to see the color changes, then change the size back once we are satisfied with the color choice.

As with for loops, the attribute investigation was a reminder of the key difference between code lines that are subsidiary to an earlier line (in the loop, a property of the object) and lines that are independent.

Interaction
Building up our program, we added another element and a simple interaction. Now there is a wall and the laser shoots whenever we click the mouse, but then disappears when it hits the wall. Here is Titus's version:

Homework
The final homework is to add a target for the laser, something exciting when the target gets hit, and any other embellishments you like. For inspiration, here is my version, modified a bit during the class:

Monday, June 29, 2015

Programming class (grade 5 and 6)

Grade 5

Homework
We started out with everyone showing their homework programs (drawing our names in Thai and English) and telling us one thing they really liked about the program and one thing that they found challenging.



Here are a couple of highlights from the discussion

  1. Repurposing commands: Tatia and Chunly both made use of dots instead of drawing explicit curves. This led us to talk about two different approaches: getting a program to implement a known method (e.g., draw your name the way you would move your hand) vs inventing a new method that uses the tools the computer already knows. There are strengths and weaknesses of each approach and the name programs show a mix.
  2. Reusing code: when do you write something new or just use code you have already written? We compared these two programs พิชชี่  and Pitchee. In the first, every component/character of the name is drawn with unique code, even though there are two identical letters (ช) and the vowel _ิ is a subcomponent of _ี. In contrast, the English version has two e's that are drawn with identical code. 
  3. Simultaneity: Jung was the only one (including last year) to have the idea of using multiple turtles to draw different components of her name. This extends the first point of our discussion: doing things with the computer differently than our organic methods. we only touched on this briefly, but it will be good to return to it.


Multiple turtles
Again, we talked about syntax related to hatching multiple turtles. This time, we started with this code:
e = hatch plume.b = hatch redb.fd 100
The puzzle was: why doesn't turtle b (our red one) move? Two possible corrections:

  • change the second line to b = hatch red
  • change the third line to e.b.fd 100

We talked a little about what e.b meant in the second line and whether we would prefer the first correction or the second correction.

For loops
After the homework conversation, I wanted to continue the theme of using repeated code, the idea that the computer will faithfully and precisely repeat the same commands again and again. The idea that this is a major difference between a machine and a person, and to start finding ways to make use of that.  Naturally, looping provides a key example.

To start, we wanted to get the mechanics right with a simple square:
pen blue
for [1..4]
  fd 100
  rt 90
Even doing this, there are a lot of little details to discuss:

  • what is this funny punctuation: "[" ".." and "]"
  • why do the third and fourth lines have to be indented? what if they aren't?
  • the different views between code and blocks. This is one case where the blocks really work nicely to show the commands captured by the loop

After this, we did several experiments:

  1. adding a new command to the loop (for example, making a dot at each vertex)
  2. changing into a triangle instead of a square
  3. modifying the size of the shape
  4. moving commands into and out of the loop

Possibilities for next time
There were many ideas I'd prepared for class that we didn't have time to cover:
Homework
The challenge this week is to draw a 2 color yin-yang like in the center of the Korean flag. This is mostly an exercise in understanding arcs, but let's see if anyone uses a for loop or multiple turtles!

Grade 6

Debugging
I wanted to continue some of the if and or ideas from last time. In addition, all of the students have been a bit stuck on their projects because they are having trouble understanding code examples from other people's programs. I thought that some debugging work would be helpful for both of these.

Challenge 1: This program (from last week) has an error: TurtleRace. What is wrong? How can we investigate?

Since we had seen a complete example of this program last time, everyone understood that turtle boongie was not making the dots that were intended.

We explored several strategies to investigate why this was happening:

  1. comment out lines of code using # or sections of code using ###: This let's us investigate whether a particular code is causing a problem, not doing what we intend, or simply not doing anything. For example, in our turtle race program. commenting out line 30 does not change the output. That tells us something is wrong.
  2. Add test code that has a function we clearly understand. In particular, for conditional statements, we can add code that helps us verify whether the conditions are being treated the way we want. In this case, we could have added a new drawing command at line 31 or a write to give us a message.
  3. reduce the number of iterations and trace line by line: this is a brute force approach. 

The error in this program is subtle and an example of something that often happens: we have a slight error, but the overall line of code looks familiar, so it makes it harder to spot the problem.

Challenge 2: My program doesn't work properly: FactorGameWindows.
  1. How do the windows move and how does the program make them stay along one line?
  2. What doesn't work properly?
  3. Can we fix it?


This is a much more complicated challenge, partly because the code is more complex, but also because the program itself is less familiar. However, investigating this program was part of the homework for both Titus and Win, so really this challenge amounted to working on the homework together.

Some of the earlier techniques for debugging came back into play. In particular, Win experimented by commenting out code and seeing the effect.

Projects:
Challenge 2 amounted to project work for Titus and Win. For the other two, we had private conversations about
- The program Sounds with Boongie
- Correction to bomb program for Gun

Homework
- Titus: (same as last week) make a rocket that moves side to side
- Win: (same as last week) make a care that moves side to side
- Gan: combine the bomb code with the target+points programs to complete his project
- Boongie: get more sound-file links from

Wednesday, June 24, 2015

Class notes (grades 5 and 6 programming)

Fifth Grade

Ideas and questions from homework

  1. How do we make multiple turtles? This was actually the second exercise I planned for the day, so we reserved it for later in the session.
  2. What does dot() mean, compared with dot green, for example?
  3. Why were all three of the dots in our exercise different colors?
  4. How can we change the color of the background? For example, pink?

Background: make it big!
We started with the last question. I asked the group if they could come up with ways of doing this. The first idea was to try typing a command "background." In pencilcode, that doesn't work as this function isn't defined so they got an error message. I suggested that they already know commands they could use and then gave them more time. Shortly after that, each came up with a variation, using either dot or box to draw a very large shape of the right color.

Note: I have since noticed that background is a function in processing.JS, used in Khan Academy. I wonder if that was the source of this idea?

Dotty dots
We tackled questions 2 and 3 together. In a fairly quick discussion, the students explained to each other than dot <color> makes a dot of that color and "lightgray" is different from "gray." That left dot() a little bit unclear.

P and I explained that the parentheses told pencilcode that we had just entered a command (or function.) We had already seen another example of this with home(). Usually we would have to tell dot a color and a size. However, the system seems to have built-in defaults in case we call the command without giving extra parameters.

We explored a couple of other commands we know, fd and rt to see if they also had built in defaults and found that they do! fd()  is equivalent to fd 100 and rt() is the same as rt 90.

We also talked about which version is easier to understand and everyone was clear that it was easier to understand if we made the parameters explicit.

The Plum triangle redux
A fairly short discussion that the plum triangle was an artifact of the fact that we could only move by whole pixels, so any irrational distance can only be approximated. We all agreed that this was fine, but needs to be handled carefully in two cases:

  • If we suddenly make our drawings much larger, then the approximations may be visible and need adjustment
  • If we have a series of approximate moves, then the little errors might accumulate. One habit is to return the turtle to the origin using home() between drawing different elements of a complicated drawing.

Hatching new turtles
Falling in perfectly with my plans, the kids wanted a reminder about how to create new turtles. One student hadn't seen this before, but the others quickly remembered something like
e = hatch 'yellow'
e = rt 90
We corrected the second line to e.rt 90 and talked about the syntax (hatch creates a new turtle wearing the indicated color, e =  gives it a name, e. is how you tell the turtle e that there is a command for it to execute.
As a challenge, we got them to draw a square with the old turtle and a triangle with the new one.

Homework
The homework this week is for everyone to draw their names in Thai and English.
Last year, I had created 5 different programs that drew my name and/or animated it in different ways. Unfortunately, 2 of those seem to be broken, so I also have homework this week!

Sixth Grade

Trying to be logical
After the discussion last week, we saw that we would need to spend more time on while and logical conditions (if, and, or).  This time, I gave them sample code (you can play here):


I asked them to just focus on the gun turtle and to figure out what it does. Most of the action is in lines 22-24.
Ultimately, this led to a discussion of how many dots it would draw. We got 2 votes for 5 dots and 2 votes for 10. In the end, we created code to cover that part of the program and saw the turtle actually draws 6, so we needed to do some work to figure out why.

We stepped through the while loop and checked to see what was happening each stage.

Before moving on, we tried changing line 21 so that innerLoop would iterations from 1 to 100. Would that change turtle gun's output? Why or why not?

Projects
There was very limited progress on the projects this week. As a result, most of the homework assignments were the same, but with some extra guidance:

  • Titus and Win: look at this example program to see if you can figure out a way to get your game characters to follow the mouse, but to stay on a fixed horizontal line.
  • Boongie: look at this Thai flag program to see how to play sound files you find on the web
  • Gun: figure out a way to integrate bombs into your game


Here is Gun's progress so far:

Wednesday, June 17, 2015

Drawing, While and Music (5th and 6th Grade Programming)

Who: Baan PathomTham 5th and 6th grades
Where: at school
When: Monday morning

Fifth Grade

Questions and observations from the homework
This week, the students had noticed two things. First, though everyone was asked to draw a triangle as part of the homework, all the versions were different. They've seen this before, but I really like to emphasize that there is no single right answer.

Second, Jung had been playing with message program from the homework and noticed: "it doesn't do anything!" We talked about what they expected would happen (it would write "Hello you" twice). Then I showed them the test panel, where the output from see gets displayed. For some reason, this panel is often closed, so it wasn't surprising that Jung didn't see any output. However, now, they got a surprise because the output still wasn't what they expected. That led us to talk about literal strings and variables and then do an example with write instead of see.

Challenge 1: A map puzzle
For our first challenge of the day, we used a program that Chunly wrote:

My question: can they make this same picture, but without the purple tail on the green dot?
Everyone completed this challenge, but, given the many ways to move the turtle and to draw something, they all had different approaches:

  1. Movement: adjust the purple line from the start, jump back to the origin, use home() to get back, or retrace the path the turtle had originally followed
  2. Drawing: draw a new dot, draw green over the dot, start drawing the purple line only at the edge of the green dot

This simple example got us to experiment with several new commands: home(), pu(), pd(). Again, it reinforced the message that there are many paths to the target destination.


Challenge 2: A plum triangle
For the second challenge, we used Pitchee's triangle from the homework. She had created an isosceles right triangle through trial and error on the hypotenuse length:

For this challenge, we added scale 10 at the start of the program (to make all the drawing elements gigantic) and ht() at the end so that the turtle wouldn't block our view. Following this, we started discussing:
What did we notice? Why was it like that? What could we do to fix it? Is this a bug or a feature?
This is something we will continue next class.

Homework
For this week, the homework is to test out the code on the right side of this page:

Sixth Grade

While we make music
Last week, students noticed the play command. I wanted to build on this by giving them more examples of ABC notation,  but I also wanted to review while and logic keywords if, and, or. In retrospect, this idea was too ambitious for one class.

Through a series of stages, I wanted them to think about how many times each line of music got played based on when and how often the conditions in the if statements were true. This was actually hard to tell and it would have been better to give them visual signals instead (or in addition).

I think we will have to return to these key words again next week. We will also discuss the guessing game that we've been writing.

Projects begin
Last week, the kids submitted outlines for their term projects. These are the ideas:

  • Boongie: a clue-and-guess game where the computer plays different animal sounds and then the player enters the name of the animal.
  • Win: a driving game where we control a car that drives along a path avoiding obstacles. The screen mechanism he wants is  to keep the car fixed vertically and have the path scroll down.
  • Gan: a chasing game where we try to move around the screen collecting point-objects while avoiding bombs and keeping away from an enemy turtle who is chasing us. 
  • Titus: a version of space invaders.

Homework
The homework for each depends on their project:




  • Boongie: Find sound files for as many animal sounds as he can locate
  • Win: work on how to control the car's left-right position with the mouse, while keeping the vertical position fixed.
  • Gan: he had found a program that did many of the things he wants in his game. One homework element is to go through that code and come up with questions about thins he doesn't understand. The second component is to figure out how to create point-objects to appear randomly on the screen.
  • Titus: Create a sprite that can shoot lasers. 

Wednesday, June 10, 2015

Sunburst and guessing (5th and 6th grade programming)

Who: Baan PathomTham 5th and 6th grades
Where: at school
When: Monday morning

Fifth Grade

Note: My original intention was to focus on discussing the homework and making some extensions. Because one student wasn't in school and I had especially wanted to use her code, we changed plan slightly.

Other interesting code
Between classes, the students spent a lot of time exploring code they found from other people. I started by asking whether they saw anything that was interesting and they wanted to understand better. There was a quick response, focusing on two programs:

  1. The jump command in this sun: http://jung.pencilcode.net/home/sun
  2. How to make new turtles, like in this chasing game: http://tatia512.pencilcode.net/home/otherpeople/Chase1

These were really great questions and gave us two interesting examples of how to understand code that we find.

Jump (jump, jump)
Basically, I walked the student through the process I follow for understanding a new command: play with it, test it, put it in a bunch of different situations, and see what happens. We created new files (mostly with names like jumpPlay) and then started adding jump commands. It quickly became clear that we needed something to help us see what was happening, where the turtle was jumping from and to, so we started adding dot between the jump commands.

I asked them to keep playing and testing until they thought they understood jump.  While waiting, I wrote a little code with some jump lines and, for a twist, an rt 90 in between. When they said they understood, I asked them to guess what my code would do. The effect of changing the turtle's direction surprised everyone, but soon they had a new explanation.

We wrapped up this section by briefly discussing a picture of grid coordinates, but this will have to be continued next session.

Hatch
The chase game uses 3 turtles, so how do we create the extra 2? I pointed out the hatch command and then we followed some of the same steps as for jump. We didn't have time for me to do a challenge program to test their understanding, but we can include that in the next session as well.

Context
Both jump and the chase program illustrate the importance of context to understanding the code. In the case of jump, copying an isolated line from the sun program will still create sensible code, but it might not do the same thing if the turtle isn't starting in the same location or pointing in the same direction. For the chase program, though, there are many lines of code that simply can't be interpreted if taken out of context. For example, line 15:
e.jumpto -250,-100
Because this requires an object e, it has to be preceded with code that defines or creates that object.

Homework
For homework, I asked the students to notice and wonder about any interesting code they find. In addition, I wanted them to try to create the pictures on the left hand side of this set of exercises:

Sixth Grade

Guest Teacher
For sixth grade, we had a guest teacher: Win. They are currently trying to solve a problem that he attacked in his project from last term, so I asked him to talk about his prior solution. In that case, he had two loops running, one for loop to ask many calculation questions and an inner while loop to give the student several chances to get the right answer. In our case, we are currently working on improving our guessing games so that the player has multiple chances to guess.

A musical interruption
As Grade 5 had found, there is a lot of interesting code out there. Several students had found a snippet of music playing code and wanted to investigate. I have to admit I didn't handle this unexpected interest as well as I had for the earlier class. I will craft an exercise related to ABC notation and the play command for next class.

homework
Since I want to build on the guessing game, we need to finish that code. Homework this week is to add the right components so that the basic guessing game is complete:

  • a random number is chosen
  • the player gets several chances to guess the number
  • after each guess, they get feedback on whether their guess was too high or too low (if it wasn't correct)
The part that is currently challenging is to create a loop that will allow multiple chances.

Monday, May 25, 2015

Home construction and guessing game (5th and 6th grade programming)

Who: Baan Pathomtham 5th and 6th grade classes
Where: at school
When: Monday morning

We had our first class of the near year today! This term, we have an hour for each grade; initial impressions are that this will work well.

Fifth Grade

We started the new class slightly differently than last year (notes here). Our agenda for the day:
  1. talk briefly about what we will be doing in the class
  2. get everyone set up with a computer and account
  3. start playing with code based on this worksheet.
What will we be doing?
None of the students seemed to know what we would be doing, so I got to set the agenda:
  • telling computers what to do
  • playing and making games
  • experimenting and exploring
  • learning about programming, geometry and algebraic thinking
  • creating art
I'm sure there are other things, but this is enough to anticipate now.

Setting up
Pretty mundane, but a reminder for anyone who wants to follow along at home:

  1. open a browser
  2. go to pencilcode.net
  3. click the New Account link in the upper right part of the page, enter your username, make up a password, and you are running. 

We experimented with dragging in blocks of code and typing directly. You play (run) your code by pushing the blue triangle button in the middle of the screen. during the class, I showed a couple of examples of typing commands into the test panel, but will flag that more explicitly next time.

Don't forget to save your work! Just hit the handy save button on the top of the page.

Our play
The essential structure of our class is that we give everyone selected code or concepts to explore, usually with some mini-project as an organizing objective. As the kids play, we will flag ideas that someone has discovered or highlight difficult points. During this class, three of these came up:

  • computers are dumb. Sure, they can do calculations precisely and quickly, but they only do exactly what you tell them. If you try to tell pencilcode pen pank to set the pen color, the machine won't know what to do, even if your friend could read that and understand you meant pink.
  • Order matters. getting dressed and then taking a bath is not the same as taking a bath and getting dressed. Similarly, these two snippets of code don't do the same thing, even though they each have the same lines of code:
First Version
Second Version
fd 100
rt 90
rt 90
fd 100
fd 50
fd 50

  • Some angle chat: How many degrees in a circle? What does it mean to turn right (clockwise) 90 degrees? What about left (counterclockwise) 180 degrees?
5th Grade Homework
The homework is to do the third and fourth exercises on the worksheet:
  1. make a sailboat
  2. draw and code your own picture

Sixth Grade

All four students are with us once again, so we are continuing their studies from last term. We will be reinforcing concepts such as if-statements, for loops, and functions (love, love, love functions!) Of course, there will be a lot of mathematics in the work as a natural part of their programs. The other area we will discuss explicitly is the process of writing developing a program. I'm not dogmatic about a set recipe, so mostly we practice different strategies, tools, and concepts.


Guessing Game
One initial focus will be building and extending a simple guessing game. I gave them this sample output:
Guess my number.
You get 5 guesses.
⇒ 25
Too big!
4 left.
⇒ 10
Too big!
3 left.
⇒ 5
Too small!
2 left.
⇒ 7
Too small!
Last guess!
⇒ 8
Too small!
Game over.
It was 9.
Their challenge: figure out the rules for this game and create a program to implement it.
This is a simple game, but a great review as it necessarily uses if statements and loops. If you want, you can even throw in a function.

Where will we take the guessing game?
We will also follow the ideas that the students have, but here are some of my plans:

  • helping game 1: as long as the user makes sensible choices based on the feedback (Too small!, Too big!) then you always let the user win on their last choice. You can choose whether it is possible for the user to win earlier.
  • cheating game: you always lose. The computer keeps track of your guesses and then tells you that the real answer was something you didn't choose. Of course, this would be easy for them to do with pencil, paper, and a friend, but how do you code it?
  • Visual game: create a way to show, visually, which numbers have been guessed. Some easy choices are list, number line, grid, but I'm sure there are other fancy things we can do.
  • Helping game 2: make the hints more detailed. Is the number even or odd, a multiple of 3, a square, etc. This will involve creating a collection of interesting facts about the numbers.
  • Pico-Fermi-Bagel/Mastermind: we've written about this type of game in our math class posts. It seems a reasonable project given the general theme of "guessing" games.

6th Grade Homework
Two homework assignments:

  1. Everyone is going to choose a project for this term and write a brief description
  2. Win is going to review his game from last term and explain to the class how to create a loop that will ask the user to keep guessing. (This opportunity to explain an idea will rotate through the class)

Monday, March 9, 2015

Projects: Finale (programming class 18)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

This was our last class of the term, so we spent the time working on finishing the projects.
For each project, there are many potential extensions, but everyone has made a complete program (or very, very nearly complete).

Programs can all be found here: Class Projects.

Plan of work today:
  • Titus: (1) instructions for the game (2) webcam version?
  • Win: (1) correct flow, (2) add fractions?
  • Boongie: (1) how do players win? (2) is the penalty condition working the way you want?
  • Gun: (1) penalty for hitting the walls, (2) winning condition, (3) finish maze 

Monday, February 23, 2015

Send me a message and projects 3 (programming class 17)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

Reminder, this is our standard lesson plan for the rest of the term:
  1. New or review concepts
  2. Exercises related to the projects
  3. Project work

New/Review

Today, we had three new concepts: while loops, objects, and message passing. This was clearly too much for everyone to understand everything, so I focused on the while loops. My reason for introducing the other ideas and short programs was to give Titus some tools for his project.
These exercises and discussions were based on these two programs from the pencilcode guide:
While
Talking about while gave a natural opportunity to talk about for again. We had two segments to the conversation, first comparing while vs for, then deciding which is best for different scenarios.
  • Do you know how many iterations you want, before you start to loop? If so, use a for loop, if not, while.
  • Eating: while hungry, eat. If you use a for loop, you may either still be hungry or explode!
  • brushing teeth: while mouth feels dirty, brush your teeth.
  • Putting on socks: for [1..2] put on a sock
  • Cleaning vegetables for stir fry: while veggie bowl has food, clean and chop veggies
  • Adding eggs to a cake: for [1..numEggs], crack an egg and add it to your wet ingredients
  • etc 
This was a really good conversation as each kid had a chance to think about the funny outcome if you used a for when while was more sensible.

Shared Memory
We didn't talk extensively about the concept of an object. Like while/for, objects would pair naturally with arrays, but we also haven't talked a lot about them. For now, the kids should understand that the object is something like a chest of drawers with the drawers given their own names.

As our exercise, we extended the pencilcode guide program to use a button and add an extra value to create this program where the turtle's angle of rotation is entered through the input boxes and the distance moved each step is increased by the button:

Message Passing
Like shared memory,we didn't spend a lot of time on this new concept. However, inspired by Kan wondering why the program stopped responding to his button clicks, we slightly modified the guide program to use a while loop instead of the for loop. Our version is here.

Project exercises

Next week, I will focus the practice/exercises/review on concepts we've learned that are being used in the projects.

Projects and homework

As a reminder, I have stored copies of their work up to the start of today's class in this folder: Project Directory. The homework this week:
  • Kan: finish drawing his maze. Next module is to decide what penalty he wants when the turtle runs into the wall. This is the same assignment as last week. Unfortunately, he overwrote his maze drawing program sometime during the week.
  • Boongie. implement the penalty when the turtle runs into the wall, the turtle bounces back to a previous shell in the maze. There are several ways to do this and I'm curious to see his approach.
  • Win: create functions to ask subtraction, multiplication, and division questions. Another area to think about are gradations in how hard the questions are.
  • Titus: Use the shared memory and message passing code ideas we learned about today to check to see if the player chooses a match.

Monday, February 16, 2015

Functions review and projects 2 (programming class 16)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

Reminder, this is our standard lesson plan for the rest of the term:
  1. New or review concepts: For loops, functions, if statements. Often, this will be integrated with the exercises.
  2. Exercises related to the projects
  3. Project work

New/Review

The new concept today was the random function. We played with three snippets of code to understand how this works and, of course, keep practicing for loops:

  1. Generate 4 random integers between 1 and 10 (inclusive)
  2. Modify the previous program to multiple your random numbers by 10
  3. Change the first program to generate numbers in [10, 100]
We had a good discussion about these programs: first identifying the ranges for possible values, then drawing Venn diagrams and talking about intersections and subsets. This opportunity to talk about additional math concepts is one of the extra dividends from the programming class.

Using the random function has many applications for games. In the projects this term, I expect that Kan and Boongie will use it to help create new mazes each time the program is run, Win will use it to generate a new set of math questions, and Titus will use it to shuffle the picture cards.

For our review, I wanted to reinforce the ideas related to functions. In one of our last sessions, we realized that the kids didn't really understand function definitions, calls, and variables. This time, i gave them three code snippets:

  • Define hypotenuseStep1(a, b) = a+b
  • Define hypotenuseStep2(a,b) = a*a + b*b
  • Define hypotenuseFinal(a,b) = sqrt(a*a+b*b)
I wanted to see if they could figure out how to call the function and whether they would do anything with the output. After many interesting attempts, we went through the details again and explained how the components work. In retrospect, I should have given them a function that would generate visual output once called. As it was, they needed to get two things right (call the function correctly and write the output) in order to get positive feedback.

Project Exercises

As noted above, the exercises on random have several potential applications in the projects. The other exercise today was most directly related to Win's project. We combined for loops, random, and write statements to loop through some math statements.

Here are some ideas for future project exercises, particularly using functions:
(1) reset/restart the game
(2) B: draw random gaps in circles for maze
(3) Gan: maybe randomize drawing of maze, depends on how he plans to structure the maze
(4) T: check to see if chosen cards match the next picture symbol

Projects and homework

The students are all making reasonable progress on their projects. I have stored copies of their work up to the start of today's class in this folder: Project Directory. The homework this week:

  • Kan: finish drawing his maze. Next module is to decide what penalty he wants when the turtle runs into the wall.
  • Boongie. implement the penalty when the turtle runs into the wall, the turtle bounces back to a previous shell in the maze. There are several ways to do this and I'm curious to see his approach.
  • Win: create a looping function so that they get a second chance for an incorrect answer. Next module is to think about gradations in how hard the questions are.
  • Titus: arrange the memory cards into a grid, randomize each time the game is played, if possible. Next module is to think about how to check to see if the player chooses a match. 


Sunday, February 8, 2015

Magic Cards (programming 15, projects 1)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

Today, we began to focus on the projects for this term. These are the kids project ideas:
  • Gun and Boongie are both making mazes
  • Win is making a math worksheet game to quiz the younger students in arithmetic
  • Titus is making a version of the memory match game
We plan to follow this agenda for the rest of the term:
  1. New or review concepts
  2. Exercises related to the projects
  3. Project work

New/Review

Today, we integrated this activity with the project exercises. For the future sessions, the three concepts we want to keep discussing are:
  • For loops: the kids are close to mastering these
  • Functions: still some confusion about the essential features, function calls and arguments
  • If statements: introduced this week, but will take more discussion.

Project Exercises

These exercises have several objectives. First, I want to help the students with their projects. Each exercise has at least one idea that can be used directly, or with small modification, in someone's project.

Second, I wanted them to really understand the concepts in the exercises. This group does best when they have a mix of experimentation, discussion, and explanation. Short snippets of code serve very well to catalyze these. It is also very useful to have them work on some material in common. In particular, during the experimentation, it is nearly guaranteed that at least one of the students will do something that nicely illustrates a critical aspect of the idea they are learning.

Third, I wanted to continue to make sure that everyone would have exposure to the interesting ideas in each project.

Here are student examples of the three exercises:
Clicking done by Boongie

If...Else done by Win

Forever and Turn done by Titus

Project Work

Boongie focused his time on drawing his maze. Gun tried to figure out a way to block the turtle from going through the barriers once he has drawn his maze. Win expanded the if-else pattern from the exercises, introducing variables to his write statements and random values. Titus added mini pictures to the outside of his memory game playing area.

Homework

For the most part, each student has different homework based on their project.
  • Gun and Boongie: draw the outline of the mazes
  • Win: work on how to respond when the player enters an incorrect answer and think about how to loop for multiple questions.
  • Titus: fill out the pictures on the boundary circle

Monday, January 26, 2015

Programming project ideas

1. Make a version of this game:
original source

2. make a program to simulate multi-hinge machines
3. create a blog reader that removes gender and racial identifiers.
4. mathman game
5. fighting monsters
6. animation of a body part/system (J1 suggested heart and blood circulation)
7. game avoiding oncoming bullets/arrows, like this
8. Pico/Fermi/Bagel
9. the finger game
10. draw a picture of something from nature (bird, flower, plant) from Ajarn Wachara
11.

Creepy Eyes (programming class 14)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

Note: These activities were based on this program I found in the pencilcode activity directory: Son of Eyes. This was a very productive class because it helped tease out many misconceptions about functions and variables.

Homework Discussion

Reviewing the students' accounts this weekend, I saw some programs written for geometry (great!) but no more progress on the function machines and nothing that indicated they had thought about their projects for this term. As a result, we did not discuss homework today ;-<

Simple Function

The first challenge was to figure out what this program does:
makeeye = (x, y) ->
    b = new Sprite
    drawon b
    dot black, 30
    dot white, 28
    fd 7
    dot limegreen, 14
    b.clip()
    home()
    drawon window
    b.moveto x, y
    forever ->
        b.turnto lastmouse
makeeye -1, 45
ht() 
As usual, reproducing the program and watching it perform was an acceptable strategy. Through the course of this warm-up, we had a chance to review a lot of the mechanics of writing programs, particularly the use of spacing Coffeescript/pencilcode.

Creepy functions and power loops

As a next version, I gave them a suggestion to integrate this code snippet into their earlier program:
for [0...10]    x = random [-200..200]
    y = random [-200..200]
For the most part, they understood what the loop was doing and were comfortable with that piece. However, integrating it with the makeeyes function proved to be a significant challenge and was really helpful for showing that none of the students yet understand the structure of a function. Essentially, no one knew how to run the function again or to run it with new input variables. We stopped the experimenting and talked about the key components of a function:
  1. Name and definition
  2. Input variables
  3. Body
  4. function call: function name and inputs
After this discussion, they seemed to be clearer about how functions work, but we will need to review again at least one more time.

A funny surprise

I showed the students one version I made of the creepy eyes program. Gun was the first to test it out. I encourage you to try it out several times with different input variables. See if you can find the little surprise I included for one of our precocious learners.

Homework

This term, we want each of the students to work on a project of their own. The homework this week is to write out a detailed description of the project they want to develop. As no one had previously thought about potential projects, we gave them the following categories as suggestions:
  • A game: there are many types, including animated games, text-based games, playing against a computer or against a friend, etc
  • An animation or a movie
  • A drawing (for example, an animal or plant they've learned from Ajarn Wachara)
  • A tool to explain some mathematics to the younger students

Wednesday, January 7, 2015

How a hacker gets started?

who: J1
when: early afternoon
where: online

J1 came up with a fun and surprising word game.

You know those promotions where you eat/buy something, then get a code to enter online for a game or drawing? Recently, one of J1's favorite snacks has been doing a treasure/pirate themed contest. Each "serving" comes with a code that, once entered, gives him 1-5 plays of a little game.
Pre-processed form of fav snack


Three interesting tidbits:
  1. We know there are 20 code words and we don't have all of them
  2. Only one valid code can be entered each day, but it seems an unlimited number of attempts can be made
  3. The codes are all related to treasure
What has this inspired? J1's first hacking attempts (to my knowledge).

Hacking + Pirates ≅ Win! (mod LittleBoy)

He has been thinking of treasure words and trying them in the system.  He was successful today and that's sure to encourage him for tomorrow.

Sunday, December 14, 2014

Our function machines (programming class 13)

who: Baan Pathomtham Grade 5 class
where: at school
when: Monday morning (bright and early!)

Ah, lucky number 13.

Homework discussion

We started by trying to figure out Titus's function machine.  This was a good continuation of our function game last time as he didn't have a chance to present a mystery function. Why don't you have a go:

Here is a link to his function machine so you can test more inputs.

While examining the output of the function S, we noticed that the results often included a repeating decimal.  For example, putting 5 into the machine gives us 12.142857142857142 (which should continue, up to the precision of the computer's calculation). This gave us a chance for a short conversation about repeating decimals and rational numbers.

I'd note that figuring out the underlying function was quite hard for the kids.

We then talked about where the other three got stuck on the homework and then spent the rest of the class helping them work through different associated issues.

The four function machines

Eventually, everyone got their function machines working, at least to the level of taking an input and giving us an output. Of course, Titus's is linked above. He is working on extensions, particularly making a loop.

Here is Gun's:
 
Boongie's:

and Win's:


My function machine

As an example with some extra functionality, I showed them my function machine. At first, we entered numbers as input and it seemed pretty silly.  Then, they got a surprise when they tried something else:

Homework

The kids have two homework assignments:
  1. Extend their function machines to incorporate functionality from my program fctMchn_2.  Example extensions: add a loop so the user can try multiple inputs, animate the input and output, keep a list of the input-output pairs that have already been tried. They should feel free to make changes as this code isn't necessarily as clean or simple as it could be.
  2. Think of a project for next term. Perhaps they want to build a game, an animated presentation, something to demonstrate more mathematical concepts, a beautiful picture or they have other ideas? Encourage them to explore the following to spark some thoughts: gym.pencilcode.net, guide.pencilcode.net, other pencilcode user accounts, or have them do an online search.

Sunday, December 7, 2014

The function game (programming Class 12)

who: Baan Pathomtham Grade 5 class
where: at school
when: Monday morning (bright and early!)

Functions

As with loops, we are spending time focused on functions to make sure that the students master these concepts.  Today, we started with a function game. I drew a function machine on the board and gave it a name. Each student took turns giving me the value of an input, then I would tell them the output. Their objective was to figure out the function rule. Early on, I added a table showing our input and output values, to keep all the information organized.



The picture shows our starting function: constant 5.  I was pleased that, even on this simple function, we got to see an example where an invalid input was tried, so we could talk briefly about the domain of definition.

Other functions we tested were LIN(x) = 20 - x and Pyth(z) = z^2 + 1.  The students were pretty fast about guessing all of these.

Next, Boongie and Win got to lead the game.  This was a lot of fun, though calculation time slowed us down a little bit, especially when students input large numbers.  I'd note that there was little systematic thinking about what inputs to use, but this was the first time we've played.

Next time we play, I will use a non-numerical function to remind them that functions aren't only about arithmetic.

Homework review

Homework links: TitusBoongieWin, and Kan (not done!)

Our usual opportunity to talk about the code that the kids wrote.  There wasn't much to report here, though Win got a bit stuck (he didn't finish his code) and Kan didn't write the program. We did talk a bit more about Kan's boxbox program which nicely illustrated three things about pencilcode functions:
  1. They can have multiple inputs
  2. Numbers, words, arrays can all be inputs (indeed, the possibilities are much broader than this)
  3. Inputs can be left out and the program will still run.
Of course, we already knew most of these things, but it is nice to have rediscovered them by accident and it makes a break from the number-centric functions that were used in our number game.

There's a link above to the program, this is what it produces (press the button to run):

I showed them a couple of programs I wrote.  This one piggy-backs off their use of switch-when-then-else to build a long list of people and birthdays: long list. This other one was an attempt to add some additional functionality and include an example of composition of functions: bells-and-whistles.

spike and starburst sequence

The main challenges of the day were to replicate these animations: SpikeSB0SB1

Spike
We were lucky that Kan chose to write all the steps explicitly, while Titus used a for loop. This allowed us to compare and contrast and we saw that the for loop wins out because:
  • it takes fewer lines of code (9 vs 27)
  • it is easier to debug (consequence of the fewer lines of code)
  • it can be changed easily. For example, sending all the spikes out 10x farther required 6 key strokes, while the other program required a lot of changes (nearly every line of code)
Starbursts
These were a bit of a challenge and there is still more work to do for most of the students. Next time, we will continue with these and move on to the third starburst version (passing a function as an argument to another function.)

Homework

The homework this week is very challenging: to create an animated function machine. The program should draw a picture of their machine, ask the user for an input into the function, use animation to show that input going into the function and animation to show the output coming out of the function machine.

For user input, they can use the requester( ) function and program phrase from this code: http://jgplay.pencilcode.net/edit/class/jgBirthdaySwitch.

Saturday, November 29, 2014

Flowers, Squares, and Functions (programming class 11)


who: Baan Pathomtham Grade 5
when: Monday morning
where: at school



Homework review
Forests/flower gardens (some of these were old?): 

Boongie made two versions: 
The first led very nicely into functions, the topic of the day as he had put the petal drawing into a function.  The second was a really nice cap to our discussions about for loops. In his original version, it drew one lime flower and three blue ones. Working together, the class modified the code so that all the flowers were a different color.

Win showed us his flower program, cryptically named untitled5: http://win.pencilcode.net/edit/untitled5

This is a good candidate for streamlining using a function.  Something for him to consider over the week.

To round out the discussion, I showed two related programs that I had found from other users and modified: http://jgplay.pencilcode.net/edit/otherPpl/flowerPattern
and http://jgplay.pencilcode.net/edit/otherPpl/forestRand


We didn't discuss this program as Titus thought it had gotten lost: http://titusorc.pencilcode.net/edit/flower/flowers

Focus for the day: Functions and vectors
Today, our plan was to build up a more complex function structure based around drawing some simple squares.

The first task was just to create a function that would draw a single red square. This code is an example.

Once completed, we added an input variable that would allow them to control the size of the square. Finally, we wanted them to make nested squares that would show why it is useful to capture a block of generic code in a function.  Here's our example.

At this point, Kan had two interesting ideas: First, he wanted to add the color as a parameter to the function.  That was pretty easy, but it was a nice way to see that functions can take numbers and words (in this case a color keyword) as arguments and that they can take multiple arguments.  His next idea was to include a variable that would tell the turtle to move after drawing the square. I've copied his code here 

http://jgplay.pencilcode.net/edit/class/kanBoxboxboxbox1234

He wasn't quite sure how to properly call the function.  Notice what he did: three arguments to the function, one of which is a vector!  Good stuff . . . and we will discuss this more next time.


We also talked about the idea of functions in mathematics and worked through three examples:

  • f(x) = x+2
  • goal(y) = 2y
  • birthday(name) = {the day of that person's birthday}


Homework
The challenge this week is to write the birthday function that will work whenever a member of their immediate family is entered as the input variable.  This is not going to be easy, so we expect them to experiment, explore, and ask questions if they get stuck.

Some other interesting code
In preparation for the class today, I noticed Kan had created this program:
http://jgplay.pencilcode.net/edit/otherPpl/kanthapStinky

Both Win and Kan had these programs

At some point, we will return to these programs to talk about what they do and why.  I know the two were experimenting with them at the end of class and I'm eager to see what they can discover.

Monday, November 24, 2014

Nested Loops Review (Programming Class 10)

who: Baan Pathomtham Grade 5
when: Monday morning
where: at school



Reviewing last week assignment

Last week, students were asked to draw this shape using double for loops if possible.  Only 1 in 4 students managed to use double for loops but none of them see this as drawing a triangle 3 times.


                                      

Nested for loops revisit

Using the homework as a starting point, I simplified the task by having them imagine the triangle to be just a line.  After they wrote the simplified program, I asked them to change the line into a triangle.  Eventually, we made our program to take any number of petals.

    num_petals = 3
    speed 10
    pen blueviolet
    for [1..num_petals]
      for [1..3]
        fd 50
        rt 120
      rt 360/num_petals

The next task is to get the students to understand how the use the counter in the for loops and the importance of placement of commands and indentation inside the for loops.  I actually had them do a simplified program before we get to the one below which creates 3 rows of colored dots (I first asked for one row of all the colored dots.)  Even these few lines of codes, it's still useful to breakdown the task into smaller, more simplified programs to learn the concepts.

    rt 90
    for x in [blue,green,pink]
      jump 25,-75
      for y in [yellow,orange,red]
        dot x, 21
        dot y, 7
        fd 25

Homework

Draw a flower garden using at least double loops.  I encouraged students to use triple loops or as many as they fancy.  I also mentioned that I didn't get to review functions but that could be handy for them to use for this homework.  Some of them seemed intrigued and I am hopeful that they will do their own review of functions to do this homework.