MrThoe

Ball

Dec 1st, 2020
590
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Example of using variables to animate
  2.  * an object
  3.  */
  4.  
  5. //DECLARE VARIABLES (AT TOP)
  6. var x, y, r;
  7. var Vx, Vy;  //Velocity
  8. var count;  //accumlator variable
  9. https://pastebin.com/
  10. //INITIAL FUNCTION RAN ONCE (1st)
  11. function setup() {
  12.   createCanvas(400, 400);
  13.   x = 100;
  14.   y = 50;
  15.   r = 30;
  16.   Vx = 2;
  17.   count = 0;
  18.   background(220);
  19. }
  20.  
  21. //INFINITE LOOP
  22. function draw() {
  23.   background(220);  //WIPES THE BG
  24.   circle(x, y, r);
  25.  
  26.   if(count>100){
  27.     Vx *=-1;
  28.     count = 0;
  29.   }
  30.   Vy = 1;
  31.   x+= Vx;
  32.   y+= Vy;
  33.   count++;
  34.   //print(count);
  35. }
RAW Paste Data