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

No comments:

Post a Comment