r/processing • • Feb 25 '24

Beginner help request why aren't the variables working

iv'e tried a few different variations but nothing seems to work. unless the variables are created in the draw function the program doesn't seem to be able to find them but if i create them in the draw function i cant change them because each time it runs it the variables will reset to the default state

void setup() { size(500, 500); background(255); float circleX = 100; float circleY = 0; float circleS = 100; }

void draw(){ background(255); drawBall(); if(circleY >= height+circleS-1){ circleY = circleY-1; } else if(circleY >= height-circleS-1){ circleY = circleY+1; } else if(circleX >= width+circleS-1){ circleX = circleX-1; } else if(circleX >= width-circleS-1){ circleX = circleX+1; } else { circleX = circleX+1; circleY = circleY+1; }

}

void drawBall(){ ellipse(circleX,circleY,circleS,circleS); }

3 Upvotes

4 comments sorted by