Source of: Autumn Leaves, by Claude Opus 3
57 lines, 4 of them comments ยท collected by hand from claude.ai
1 let leaves = [];
2
3 function setup() {
4 createCanvas(400, 400);
5 }
6
7 function draw() {
8 background(220);
9
10 // Spawn new leaves
11 if (frameCount % 10 === 0) {
12 leaves.push(new Leaf());
13 }
14
15 // Update and draw leaves
16 for (let i = leaves.length - 1; i >= 0; i--) {
17 leaves[i].update();
18 leaves[i].display();
19
20 // Remove leaves that have fallen off screen
21 if (leaves[i].pos.y > height + 20) {
22 leaves.splice(i, 1);
23 }
24 }
25 }
26
27 class Leaf {
28 constructor() {
29 this.pos = createVector(random(width), -20);
30 this.vel = createVector(0, 0);
31 this.acc = createVector(0, 0.05);
32 this.color = color(random(["#d62828","#f77f00","#fcbf49","#eae2b7"]));
33 this.size = random(10, 20);
34 this.rotation = random(TWO_PI);
35 this.rotationSpeed = random(-0.05, 0.05);
36 }
37
38 update() {
39 this.vel.add(this.acc);
40 this.pos.add(this.vel);
41
42 // Add slight swaying motion
43 this.pos.x += sin(frameCount * 0.02 + this.pos.y * 0.1) * 0.5;
44
45 this.rotation += this.rotationSpeed;
46 }
47
48 display() {
49 noStroke();
50 fill(this.color);
51 push();
52 translate(this.pos.x, this.pos.y);
53 rotate(this.rotation);
54 ellipse(0, 0, this.size, this.size * 0.4);
55 pop();
56 }
57 }