Fifth gradeThe class focused on using variables and for loops in our spiral programs from the homework. Here are the programs the kids wrote:
- Chun ascending: http://chunly.pencilcode.net/edit/spiral-2
- Chun descending: http://chunly.pencilcode.net/edit/spiral
- Tatia's ascending: http://tatia512.pencilcode.net/edit/circle2
- Tatia's descending: http://tatia512.pencilcode.net/edit/shell1
- Jung descending: http://jung.pencilcode.net/edit/hw2
- Jung ascending: http://jung.pencilcode.net/edit/hw
- Pitchee ascending:http://pitchee.pencilcode.net/edit/shell2
- Pitchee descending: http://pitchee.pencilcode.net/edit/shell
More Variables and LoopsFor 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|
- 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
- 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!
For future discussions
- Josh's version of the spirals: http://jgplay.pencilcode.net/home/class/spiralTeam
- Someone else's code similar to spirals: http://jgplay.pencilcode.net/edit/class/BlowUp
- found code from Jung: http://jung.pencilcode.net/edit/6star
- Another use of for loops: http://jgplay.pencilcode.net/edit/class/sun-and-treeChun
- A different version from Chunly: http://chunly.pencilcode.net/edit/flower-3
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.
bullseye loopsWe recalled the code paradigm
for x in [1..10]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:
write x #don't forget the indentation!
- 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.
- find a way to alternate which color is used. Titus figure out he could do this with an if statement.
- 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.
HomeworkCreate 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.
change an old polygon program to a star maker