Better Spirals
Have a go at reading over the code below and guessing what it does. Then run it to see if you were correct.
// Add your action code here.
int r = 255;
int g = 0;
int b = 0;
for (int i = 0; i < 1000; i++)
{
g += 1;
b += 1;
r -= 1;
setColor(r, g, b);
moveAndDraw(i);
turn(98);
}
Our code has made a multicoloured spiral by changing the r
, g
, and b
variables. The colours are a little one-dimensional, though. Can you do a better job?
Additionally, your code likely stopped early because of this error:
java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue
Can you modify the loop so it runs fewer times and doesn’t run out of colors? Eventually, we will see how to avoid running out of colors but for now shorten your loop.