Source of: Recursive Bloom, by Claude Opus 4.7
60 lines, no comments ยท 782 tokens, written in 11 seconds for $0.021
1 let angleOffset = 0;
2
3 function setup() {
4 createCanvas(windowWidth, windowHeight);
5 angleMode(RADIANS);
6 }
7
8 function draw() {
9 background(15, 20, 35, 40);
10
11 let mx = map(mouseX, 0, width, -0.3, 0.3);
12 angleOffset = sin(frameCount * 0.01) * 0.2 + mx;
13
14 translate(width / 2, height);
15 stroke(220, 180, 120);
16 branch(height * 0.22, 9);
17 }
18
19 function branch(len, depth) {
20 if (depth === 0) {
21 noStroke();
22 let hueShift = (frameCount * 0.5 + len * 2) % 360;
23 fill((hueShift + 180) % 360, 150, 255, 180);
24 colorMode(HSB, 360, 255, 255, 255);
25 fill(hueShift, 200, 255, 200);
26 let r = 4 + sin(frameCount * 0.05 + len) * 3;
27 ellipse(0, 0, r, r);
28 colorMode(RGB, 255);
29 return;
30 }
31
32 strokeWeight(map(depth, 0, 9, 0.5, 5));
33 stroke(220, 180, 120, 180);
34 line(0, 0, 0, -len);
35 translate(0, -len);
36
37 let a = PI / 7 + angleOffset * 0.3;
38
39 push();
40 rotate(a);
41 branch(len * 0.72, depth - 1);
42 pop();
43
44 push();
45 rotate(-a * 1.1);
46 branch(len * 0.68, depth - 1);
47 pop();
48
49 if (depth > 5) {
50 push();
51 rotate(a * 0.2);
52 branch(len * 0.55, depth - 2);
53 pop();
54 }
55 }
56
57 function windowResized() {
58 resizeCanvas(windowWidth, windowHeight);
59 }
60