Hello! I’m working on a simple exercise but I am stuck, basically my goal is to have an animation of a ellipse growing untill touch the square’s corner and shrinking in the opposite direction untill its diameter is 0 then starts again in a loop.
The second problem is the color releated to the keyboard. I never used this function! I would like to achive a interactive loop animation
int x;
int y;
int radius;
boolean ellipseDiameter = true;
color strokeColor;
void setup() {
colorMode (RGB);
smooth();
background(0);
size (500, 500);
}
void draw () {
translate(width/2, height/2);
if (ellipseDiameter) {
strokeColor();
ellipse(x, y, radius, radius);
radius=radius+10;
} else {
radius=radius-10;
}
}
void strokeColor () {
if ( key == '1') {
fill (0);
background (255);
}
if ( key == '2') {
fill (255, 0, 0);
background (0, 255, 0);
}
}
While providing full code solutions could be viewed as helpful, it denies the student the experience of working through a problem as well as the satisfaction of arriving at a solution on their own.
is the core of the loop animation but I can’t figure out why it is important the" radius Less than or equal to 0" for the !ellipseDiameter. Because if radius is greater of width it must come back, right, but why less to 0?
I tried to delete the <=0 and something wired happens. Basically the ball grows one time, it reachs the width, then it comes back but when arrives at 0 it grows again to infinite!! So the <=0 number makes the loop closed!!
I would assume that would mean that as the ball is shrinking, the number never actually hits 0. So the radius then becomes negative and grows likewise…