Hi, im new to processing and i was wondering if anyone could help me out me in this task. I want to move an ellipse up and down, and basically every time i press the space bar the previous ellipse stops on its spot and another one appears to its right moving up and down as usual, then when i press the space bar again the same thing happens and the previous ellipse pauses and a new one appears to its right. My program is working but not correctly.
In my program every time i press the space bar a new ellipse appears, but the previous one doesn’t stop and my ellipse moves up and down but with the previous ellipse, they are all supposed to move down individually not attached to the previous ones. Each row of the ellipse is supposed to move up and down on its own, once the space bar is pressed and they appear, NOT attached to the previous one and it moves up and down with it. I think the problem may be within the steps part, where i make it move in steps slowly. I’ve tried many different ways but it doesn’t seem to work.
This is my code:
final int ellipseSize = 20, rowSize = 4;
int yspeed = 5;
int xPos=0, yPos;
int[] x = {xPos}, y = {0};
float wX, hY, Steps, yha =0;
boolean pause = true;
void setup() {
size(500, 400);
Steps = (float)height/720;
wX = (float)width/14.2;
hY = (float)height/8f;
}
void draw() {
background(255);
fill(0);
int ellipseSteps = ((int)(yha/hY+0.5))* (int) hY;
int index = y.length - 1;
y[index] += yspeed;
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < rowSize; j+=20) {
stroke(0);
fill(255,0,0);
ellipse(x[i], ellipseSteps + j , wX, hY);
}
}
if(pause) {
yha = yha + yspeed;
}
if ((yha > 350) || (yha < 0)){
//Turn around!
yspeed = yspeed*- 1;
}
}
void keyPressed() {
if (key == ' ') {
pause = !pause;
xPos += ellipseSize;
x = append(x, xPos);
y = append(y, yPos);
}
}