oneshotlm
Compare all models on this prompt →

L-system tree · kimi-k2.7-code

Using the pre-provided p5.min.js (global p5), grow a procedural L-system fractal tree that branches recursively and sways gently in the wind.

⛨ sandboxed Open in new tab ↗
transcript · 12 messages
user

Using the pre-provided p5.min.js (global p5), grow a procedural L-system fractal tree that branches recursively and sways gently in the wind.

assistant
thinking
 Let me check the current directory to see p5.min.js is there.

bash {"command":"ls -la"}
toolResult

total 1028 drwxrwxrwx 3 node node 96 Jul 10 00:24 . drwxr-xr-x 1 root root 4096 Jul 10 00:24 .. -rw-r--r-- 1 node node 1034532 Jul 10 00:24 p5.min.js

assistant
thinking
  Good, p5.min.js is in the directory. Now I need to create a single index.html file with inline CSS and JS that loads p5.min.js from the local file. I need to build an L-system fractal tree that branches recursively and sways in the wind.

Let me create a nice, self-contained app:
- Use p5.js in global mode
- Implement an L-system with rules like F -> FF+[-F+F+F]+[+F-F-F] or similar classic tree
- Render using turtle graphics, recursive orientation
- Add wind sway by applying a time-varying rotation
- Add controls maybe for generation/angle
- Use full window canvas

Let me plan L-system:
Axiom: F
Rules: F -> FF+[-F+F+F]+[+F-F-F]
Angle: 25 degrees (PI/7)
Length decreases with generation? I'll keep length constant-ish but shrink based on generation.

Actually a simpler classic tree L-system:
Axiom: X
Rules:
X -> F+[[X]-X]-F[-FX]+X
F -> FF
Angle: 25 degrees
This produces bushy tree.

But to make it more visually tree-like and swaying, I'll use a recursive drawing approach with stack.

Implementation:
1. Generate L-system string up to 5 iterations
2. Draw using turtle with p5 line/vertex
3. For wind: apply small noise-based or sin-based rotation at base, increasing for higher branches (multiply by depth)
4. Add falling leaves maybe
5. Add background gradient in draw

I'll make generation variable accessible via slider maybe? Let's add controls: angle slider, generation slider (requires regen), wind strength slider. But since it needs to be self-contained and single file, I'll include HTML controls.

Let me write the file.

write /workspace/index.html (10703 bytes)
toolResult

Successfully wrote 10703 bytes to /workspace/index.html

assistant
thinking
   I should verify the file exists and perhaps test it with a quick static server / open a browser preview if possible. Since I don't have a browser directly, I can at least confirm p5.js loads when serving. Let me run a python http server and curl index.html to ensure no obvious errors (though JS runtime errors won't show in curl). I can also use node with simple validation. But mainly I should check syntax. I'll use a simple node HTML parse check... or just validate it reads.

Actually I should run python -m http.server briefly and curl, just to verify the file serves and references p5.min.js correctly. Then also run an HTML syntax check maybe.

Let me do a quick bash:
- ls to ensure index.html
- start python server in background, curl index.html
- maybe use python to parse.

Let me do that.

bash {"command":"cd /workspace && ls -la && python3 -c \"from html.parser import HTMLParser; data=open('index.html').read(); parser=HTMLParser();
toolResult

total 1040 drwxrwxrwx 4 node node 128 Jul 10 00:25 . drwxr-xr-x 1 root root 4096 Jul 10 00:24 .. -rw-r--r-- 1 node node 10705 Jul 10 00:25 index.html -rw-r--r-- 1 node node 1034532 Jul 10 00:24 p5.min.js /bin/bash: line 1: python3: command not found Command exited with code 127

assistant
thinking
  Python not installed. Maybe python is? Or node? Let's try node and a simple HTML validator package? Easier: use node to read file and check script. Also serve with npx? No network. But we can verify p5.min.js content presence. Maybe run node -e with require html parser? Node has no built-in HTML parser. But I can use regex/basic checks. Let's do node.

bash {"command":"cd /workspace && node -e \"const fs=require('fs'); const html=fs.readFileSync('index.html','utf8'); console.log('Length:',html.l
toolResult

Length: 10703 Contains p5.min.js: true Contains <script> 1 2

assistant
thinking
   Good. HTML structure counts include inline script and p5 script. But note: the first `<script src="p5.min.js"></script>` is self-closing, the second inline script is `<script>...</script>`. Matches fine.

One concern: In global mode, `new p5((p) => { ... })` creates an instance. That's fine. However, because p5 script is loaded before inline script, p5 is defined.

L-system: with generation 5, the string can be huge? Let's estimate: X -> F+[[X]-X]-F[-FX]+X length 21, F remains? RULES F: FF. The grammar applies to all characters including F. For gen iterations:
- gen0 length 1.
- gen1 applies to X producing length 21.
- gen2 each X -> 21, each F -> 2. In gen1 there are how many F? F appears 4 times? Let's count. Actually it's mostly X. So length grows ~20*21 each gen. Gen 5 would be huge (millions). My code uses direct iteration and then a stack-based render. Gen 5 might be huge and cause memory/performance issue. User wants procedural L-system fractal tree. Gen 5 might be okay? Let's check length. Maybe gen 4 is okay, gen 5 maybe too large. Let's compute.

bash {"command":"cd /workspace && node -e \"\nconst AXIOM='X';\nconst RULES={X:'F+[[X]-X]-F[-FX]+X',F:'FF'};\nlet current=AXIOM;\nfor(let i=1;i<=
toolResult

gen 1 len 18 gen 2 len 89 gen 3 len 379 gen 4 len 1551 gen 5 len 6263 gen 6 len 25159 gen 7 len 100839

assistant
thinking
   Good, gen 5 is 6k characters, reasonable. Gen 7 100k maybe heavy but slider max 7, might be slow due to drawing 100k commands each frame but user can choose lower. Maybe cap max generations to 6? 100k in JS canvas frame could be slow (maybe ok?). But we can handle generation 7 by not drawing too huge? Probably fine if user chooses. To keep performance, I'd lower default to 5.

Another concern: `p.lerpColor` signature? `p.lerpColor(c1, c2, amt)` works. I used `p.lerpColor(p.color('#1a2342'), p.color('#05070d'), inter)` for y gradient. Good.

Stroke color set inside drawTree; Stroke fill not an issue.

The stacked branch drawing uses direct parsing. Branch color and tip leaves every frame. Good.

Wind sway: heading plus sway * depth. But depth increments only on '[' and we push depth. Starting depth=0, when [ we push then depth++. For a tree that ends with many branches, depth values are correct. For each 'F', we compute sway based on depth. Good.

But there's a subtle issue: the heading rotation from '+' and '-' doesn't account for wind; then each segment's 'effectiveHeading' adds wind. That's okay for sway. Could also be more natural to push heading with wind for sub-branches, but since wind is added per segment, children also get wind relative to new heading.

Need to see if p.ellipse with thickness = 0.6 or p.noFill/stroke inside drawTree conflicts with leaves. Leaves use noStroke/fill. Good.

The background gradient draws every frame line by line. It's heavy? Height maybe 1080; every 2 pixels -> 540 lines. Fine.

Moon glow loops 20 ellipses. Fine.

Could there be an issue with color alpha in p5: `p.fill(255, 255, 230, alpha)` where alpha 0-40, default colorMode RGB 0-255. Fine.

Check if p.color works with hex including alpha? Not used.

Button layout okay.

One potential issue: I used `new p5((p) => {...})`. When p5.js is in global mode, this creates instance mode. This is correct. But the function `drawTree` and others call p methods, using p argument passed in closure. Good.

Maybe I should add a fallback if p5 not loaded? Not necessary.

Let me think if the string generation should reset when page loads? Yes, rebuildTree in setup.

Could add a small loading? Not needed.

Now I need to return a concise response. The user asked to build a single-page web app using pre-provided p5.min.js, grow a procedural L-system fractal tree that branches recursively and sways gently in the wind. I created index.html. I should describe what it does and controls.

I should not output too much. Provide path. Good.

Created `/workspace/index.html` — a self-contained single-file app using your local `p5.min.js`. **What it does** - Builds a procedural L-system tree with axiom `X` and rules: - `X → F+[[X]-X]-F[-FX]+X` - `F → FF` - Renders the full grammar each frame with a turtle-graphics stack, tapering branches from trunk to tips. - Adds gentle wind sway that increases higher up the branches using time-based sine offsets. - Draws a twilight gradient, moon glow, ground silhouette, and animated falling leaves. - Provides live controls for generations, branch angle, branch length, and wind strength. Open `index.html` in a browser to watch the tree grow and sway.

TAKE IT TO CODE

A single self-contained HTML file — copy it and open in any browser, or reuse the prompt with your own pi-agent run.

RUN

modelkimi-k2.7-code
vendorMoonshot · Kimi
harnesspi-agent
generated2026-07-10

EVALUATION

4/5 working

L-system tree with sliders for generations/angle/length/wind, subtle sway, no clear input response beyond tree regen.

Vision grade · anthropic/claude-sonnet-5

MEASUREMENTS

Raw readings from the capture, not a verdict — the grade above is the only judgement. Percentages are how much of the screen changed; the measure under-reports sparse motion on a dark background.

idle motion1.6%
on click7.6%
on drag9.9%
on wheel11.1%
on enter + space10.7%
on arrow keys8.0%
on w/a/s/d4.9%
frame spread25.3 / 255
console errors0
js errors none

METRICS

runtime101.0s
tokens in5.4k
tokens out5.6k
cached20k
cost / run$0.0265