The aim of this puzzle: Create a 3 by 3 checkerboard using two random colors.
Walkthrough of the solution: You need to create a three rows of three boxes per row. To make a checkerboard pattern, each box you draw should be a different color than the last and you only have two colors total. You want the colors to be picked randomly at the beginning but then stay the same two colors while you draw your pattern. To do this, you create the variables called
y. You set each one equal to
pickRandom(color) – now
y each are storing a mystery color. Next you finish the pattern of drawing a box with
x color, then
y color, then
x color again, making sure you put a
newLine() every three boxes since that’s how wide each row should be.
Sample code solution:
(Tap below to reveal)
var x = pickRandom(color); var y = pickRandom(color); drawBox(x); drawBox(y); drawBox(x); newLine(); drawBox(y); drawBox(x); drawBox(y); newLine(); drawBox(x); drawBox(y); drawBox(x);
Grasshopper Concepts: drawBox(), newLine(), pickRandom()