47 lines, no comments ยท 448 tokens, written in 20 seconds for $0.0045


 1  let circles = [];
 2  
 3  function setup() {
 4    createCanvas(windowWidth, windowHeight);
 5    noStroke();
 6  }
 7  
 8  function draw() {
 9    background(240, 20);
10    for (let i = circles.length - 1; i >= 0; i--) {
11      circles[i].update();
12      circles[i].display();
13      if (circles[i].isFinished()) {
14        circles.splice(i, 1);
15      }
16    }
17  }
18  
19  function mouseMoved() {
20    let r = map(mouseX, 0, width, 5, 50);
21    let g = map(mouseY, 0, height, 50, 255);
22    let b = map(mouseX + mouseY, 0, width + height, 50, 255);
23    circles.push(new Circle(mouseX, mouseY, r, color(r, g, b)));
24  }
25  
26  class Circle {
27    constructor(x, y, r, c) {
28      this.x = x;
29      this.y = y;
30      this.r = r;
31      this.c = c;
32      this.alpha = 255;
33    }
34  
35    update() {
36      this.alpha -= 5;
37    }
38  
39    display() {
40      fill(red(this.c), green(this.c), blue(this.c), this.alpha);
41      ellipse(this.x, this.y, this.r * 2, this.r * 2);
42    }
43  
44    isFinished() {
45      return this.alpha < 0;
46    }
47  }