Advertisement
fosterbl

millis() Processing timer example

Sep 26th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. int x, xVelocity, y, yVelocity;
  2.  
  3. void setup(){
  4.   size(640,480);
  5.   x = width/2;
  6.   y = height/2;
  7.   xVelocity = 0;
  8.   yVelocity = 0;
  9. }
  10.  
  11. void draw(){
  12.   background(0);
  13.   ellipse(x, y, 20, 20);
  14.   if( millis() <= 2000 ) xVelocity = 2;
  15.   else if( millis() <= 4000 ){
  16.     xVelocity = 0;
  17.     yVelocity = 2;
  18.   }
  19.   else if( millis() <= 6000 ){
  20.     xVelocity = -2;
  21.     yVelocity = 0;
  22.   }
  23.   else if( millis() <= 8000 ){
  24.     xVelocity = 0;
  25.     yVelocity = -2;
  26.   }
  27.   else noLoop();
  28.   x += xVelocity;
  29.   y += yVelocity;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement