Thursday, November 29, 2007

Random colors

Most people did random colors by selecting one from a set of several using if statments (e.g., if :rn = 2 [...set pen to second color choice...]), but here's a way of making an even more unknown color:


to randomColor

make "myRed random 256
make "myGreen random 256
make "myBlue random 256

setpc (list :myRed :myGreen :myBlue)
setfc (list :myRed :myGreen :myBlue)

end


The syntax of making a list took a little while to figure out!

Supposing that you are calling the code for making a square frame in the center of the screen centerSquare, this code will fill it with color, over and over:


to go
cs

repeat 50 [
randomColor
centerSquare
fill

wait 35
]

end

No comments: