The aim of this puzzle: Draw two boxes with colors that are randomly generated.
Walkthrough of the solution:
pickRandom() randomly selects a value from a list, while
color holds a list of different colors.
pickRandom(color) will randomly select one color, such as blue or purple. To make a box have a random color,
pickRandom(color) needs to go inside
drawBox(pickRandom(color)). This is called Call Nesting; when a function —
pickRandom() — is put inside another function —
drawBox(). The function
pickRandom(color) runs and a color is selected, this color is then “given” to the
drawBox() function. If, for example, the random color selected was red, the computer would “see”
drawBox(red) rather than
drawBoxes(pickRandom(color)). This means a red box would be drawn.
Sample code solution:
(Tap below to reveal)
Grasshopper Concepts: pickRandom(), drawBox()