add animation to the picture:
I add keyboard function and the draw function to the picture.
code:
animation:
homework
scale:
I first writes: d++. In order for it to get smaller, I add a if statement: if d>=400, d–, . but it turns out to be that the circle only scale once. When it reaches the largest (d=400), it stops there and doesn’t turns smaller. Rody tells me the situation happens because that when d reaches 400, it tries to get smaller, but once it reaches 399, it will +1 and becomes 400 again. so d is jumping between 399 and 400.
The solution is to define a int variable:
change color:
I first want to use the random function to change the color, but later I notice the colors are changing gradually, so random is not the right choice. As the hint suggest, I changed the color mode to HSB. HSB stands for: Hue, Saturation and Brightness. Knowing this, things become easier. we are not going to change the saturation and brightness, only the hue. So I set the rest of the two to maximum:100 and defined a variable: H, using the same method as the “d” to achieve the final outcome.
keyboard interaction (below), not reach the boarder (above)
the final animation:
list of interesting functions:
void keyPressed() { if (keyCode ==xxx) yyy; }
void draw () { rect (x , y, mousex, mousey);