View difference between Paste ID: XmTCG5V1 and 246rbTZP
SHOW: | | - or go back to the newest paste.
1-
var circles = [];
1+
var circles = [];
2-
2+
3-
function setup() {
3+
function setup() {
4-
  createCanvas(400, 400);
4+
  createCanvas(400, 400);
5-
  var count = 0;
5+
  var count = 0;
6-
  while (count < 20) {
6+
  while (count < 20) {
7-
    circles.push({
7+
    circles.push({
8-
      x: random(width),
8+
      x: random(width),
9-
      y: height,
9+
      y: height,
10-
      vx: 0,
10+
      vx: 0,
11-
      vy: random(4),
11+
      vy: random(4),
12-
      r: random(4,10),
12+
      r: random(4,10),
13-
      h: random(360)
13+
      h: random(360)
14-
    });
14+
    });
15-
    count = count + 1;
15+
    count = count + 1;
16-
  }
16+
  }
17
}
18-
18+
19-
function mouseDragged() {
19+
function mouseDragged() {
20-
  circles.push({
20+
  circles.push({
21-
      x: mouseX,
21+
      x: mouseX,
22-
      y: mouseY,
22+
      y: mouseY,
23-
      vx: 0,
23+
      vx: 0,
24-
      vy: -random(4),
24+
      vy: -random(4),
25-
      r: random(4,10),
25+
      r: random(4,10),
26-
      h: random(360)
26+
      h: random(360)
27-
    });
27+
    });
28
}
29-
29+
30-
function draw() {
30+
function draw() {
31-
  background(255);
31+
  background(255);
32-
  noStroke();
32+
  noStroke();
33-
33+
34-
  circles.forEach(paint);
34+
  circles.forEach(paint);
35-
  circles.forEach(move);
35+
  circles.forEach(move);
36-
  circles.forEach(bounce);
36+
  circles.forEach(bounce);
37
}
38-
38+
39-
function isClickedOn(circle) {
39+
function isClickedOn(circle) {
40-
  if (dist(mouseX, mouseY, circle.x, circle.y) < circle.r) {
40+
  if (dist(mouseX, mouseY, circle.x, circle.y) < circle.r) {
41-
    circle.r = 0;
41+
    circle.r = 0;
42-
  }
42+
  }
43
}
44-
44+
45-
function mousePressed() {
45+
function mousePressed() {
46-
  circles.forEach(isClickedOn);
46+
  circles.forEach(isClickedOn);
47
}
48-
48+
49-
function paint(circle) {
49+
function paint(circle) {
50-
  colorMode(HSB);
50+
  colorMode(HSB);
51-
  fill(circle.h, 100, 100);
51+
  fill(circle.h, 100, 100);
52-
  ellipse(circle.x, circle.y, circle.r*2, circle.r*2);
52+
  ellipse(circle.x, circle.y, circle.r*2, circle.r*2);
53
}
54-
54+
55-
function move(circle) {
55+
function move(circle) {
56-
  circle.x += random(-2, 2); // vibration
56+
  circle.x += random(-2, 2); // vibration
57-
  circle.x += circle.vx; // circle.x = circle.x + circle.vx
57+
  circle.x += circle.vx; // circle.x = circle.x + circle.vx
58-
  circle.y += circle.vy;
58+
  circle.y += circle.vy;
59
}
60-
60+
61-
function bounce(circle) {
61+
function bounce(circle) {
62-
  if (circle.x > width || circle.x < 0) {
62+
  if (circle.x > width || circle.x < 0) {
63-
    circle.vx = - circle.vx;
63+
    circle.vx = - circle.vx;
64-
  }
64+
  }
65-
  if (circle.y > height || circle.y < 0) {
65+
  if (circle.y > height || circle.y < 0) {
66-
    circle.vy = - circle.vy;
66+
    circle.vy = - circle.vy;
67-
  }
67+
  }
68
}