Source of: Interactive Colorful Circles, by Command A
47 lines, no comments ยท 383 tokens, written in 7 seconds for $0.0038
1 let circles = [];
2
3 function setup() {
4 createCanvas(windowWidth, windowHeight);
5 noStroke();
6 }
7
8 function draw() {
9 background(240);
10 for (let i = circles.length - 1; i >= 0; i--) {
11 circles[i].display();
12 circles[i].update();
13 if (circles[i].isFinished()) {
14 circles.splice(i, 1);
15 }
16 }
17 }
18
19 function mouseClicked() {
20 circles.push(new Circle(mouseX, mouseY));
21 }
22
23 class Circle {
24 constructor(x, y) {
25 this.x = x;
26 this.y = y;
27 this.size = 0;
28 this.maxSize = random(50, 150);
29 this.color = color(random(255), random(255), random(255), 150);
30 this.growSpeed = 3;
31 }
32
33 display() {
34 fill(this.color);
35 ellipse(this.x, this.y, this.size);
36 }
37
38 update() {
39 if (this.size < this.maxSize) {
40 this.size += this.growSpeed;
41 }
42 }
43
44 isFinished() {
45 return this.size >= this.maxSize;
46 }
47 }