Saturday, April 19, 2008

Random colors, filling an enclosed space

I usually do 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 your color even more unknown:

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

Here are methods for making a square frame in the center of the screen and then filling with random colors:

to centerSquare

penup

; go to lower right corner of square
bk 300 rt 90 fd 300 lt 90
pendown
repeat 4 [fd 600 lt 90]

; back to center
penup
fd 300 lt 90 fd 300 rt 90

end

to centerSquareColors
hideturtle
clearscreen
repeat 100 [
randomColor
centerSquare
fill
wait 75
]
showturtle
end

No comments: