Guest User

Untitled

a guest
Oct 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. var acc, vel, xpos, ypos;
  2.  
  3. var balls= [];
  4.  
  5. function setup() {
  6. createCanvas(400, 400);
  7. //for(i=0;i<10;i++){
  8. // balls[i] = new Balls;
  9. }
  10.  
  11.  
  12. function mouseDragged(){
  13. balls.push(new Balls(mouseX,mouseY));
  14. }
  15.  
  16.  
  17.  
  18.  
  19. function draw() {
  20. background(0);
  21. for(i=0;i<balls.length;i++){
  22. balls[i].displ();
  23. balls[i].bounce();
  24. }
  25. }
  26.  
  27.  
  28. function Balls(x,y) {
  29. this.xpos = x;
  30. this.ypos = y;
  31. this.acc = 0.1;
  32. this.vel = 0;
  33. this.displ= function(){
  34. fill(255,random(0,255),random(0,255),100);
  35. ellipse(this.xpos,this.ypos,25,25);
  36. };
  37. this.bounce = function() {
  38. this.ypos += this.vel;
  39. this.vel += this.acc;
  40. if(this.ypos>400){
  41. this.vel*= -0.9;
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment