D3athStrok3
D3athStrok3

Reputation: 41

my if condition is not working on processing language

I'm working on Processing language for my assignment. It's an animation. The animation object(a ball) needs to go from top to bottom. I have declared variable as float x,y. Whenever I put if condition to increase size of it by 1 but it's not moving a single inch.

float x;
float y;

size(600, 400)

x = 0.4*width/8;
y = 0.4*height/8;


ellipse( width/2, x, 0.8*width/8, 0.8*width/8);
ellipse( y, height/2, 0.8*height/8, 0.8*height/8);



if(x < height){
    x = x+1;
}

if(y < width){
   y=y+1;
}

I am expecting the output as- the ball located on top moves towards down and stops at the bottom and the left ball moves to right and stops at the rightmost point.

Upvotes: 1

Views: 99

Answers (1)

Kevin Workman
Kevin Workman

Reputation: 42174

You're using Processing in "static mode" which means your code runs once and then is done. Nothing happens after you reach the end of your code.

To take advantage of Processing's 60 FPS rendering loop, you need to specify setup() and draw() functions. Something like this:

float circleY;

void setup(){
  size(200, 200);
  circleY = height/2;
}

void draw(){
  background(200);
  ellipse(100, circleY, 20, 20);

  circleY = circleY + 1;
}

Shameless self-promotion: here is a tutorial on animation in Processing.

Upvotes: 4

Related Questions