Advertisement
Guest User

AL_ArtGameThing

a guest
Jul 27th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ball = {
  2.     x: 0,
  3.     y: 0,
  4.     diam: 100
  5. }
  6.  
  7. var easing;
  8. var dx, dy;
  9. var xpos, ypos;
  10. var diam;
  11. var bgColor;
  12. // var xspeed, yspeed; //eventually use if statement to incrementally decrease speed as more ellipses merge
  13.  
  14. function setup() {
  15.     createCanvas(800,800);
  16.     easing = .25;
  17.     xpos = random(width);
  18.     ypos = random(height);
  19.     diam = random(25,75);
  20.     bgColor = color(random(0,200),random(0,200),random(0,200));
  21. }
  22.  
  23. function draw() {
  24.     background(bgColor);
  25.     drawSmall();
  26.     drawBall();
  27.     followMouse();
  28. }
  29.  
  30. function drawSmall() {
  31.     noStroke();
  32.     fill(255);
  33.     ellipse(xpos, ypos, diam, diam);
  34.  
  35.     if(dist(ball.x, ball.y, xpos, ypos) < ball.diam/2) {
  36.         // fill(0); //fill small ball black to make it seem like it "absorbed" into ball?
  37.         ball.diam += diam; //not sure WHY ball takes up the entire screen instead of just increasing ball.diam but it's really funny
  38.     }
  39. }
  40.  
  41. function drawBall() {
  42.     noStroke();
  43.     fill(255);
  44.     ellipse(ball.x,ball.y,ball.diam,ball.diam);
  45. }
  46.  
  47. function followMouse() {
  48.     dx = mouseX - ball.x;
  49.     ball.x += dx*easing;
  50.     dy = mouseY - ball.y;
  51.     ball.y += dy*easing;
  52. }
  53.  
  54. function mouseClicked() {
  55.     location.reload(); //reload page
  56. }
  57. // mouseClicked() stops followMouse()?
  58. // function mouseClicked() {
  59. //  this.x = random(width);
  60. //  this.y = random(height);
  61. //  this.diam = random(25,50);
  62. //  this.xspeed = random(-3,3);
  63. //  this.yspeed = random(-3,3);
  64.  
  65. //  this.draw = function() {
  66. //      fill(255);
  67. //      ellipse(this.x, this.y, this.diam, this.diam);
  68. //  };
  69.  
  70. //  bouncing not working?
  71. //  this.update = function() {
  72. //      this.x += this.xspeed;
  73. //      this.y += this.yspeed;
  74. //  };
  75.  
  76. //  this.bounce = function() {
  77. //      if(this.x > width-this.diam/2 || this.x < this.diam/2) {
  78. //          this.xspeed *= -1;
  79. //      }  
  80. //      if(this.y > height-this.diam/2 || this.y < this.diam/2) {
  81. //          this.yspeed *= -1;
  82. //      }
  83. //  }
  84. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement