oneshotlm
Compare all models on this prompt →

L-system tree · gpt-5-mini

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 · 4 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
**Planning drawing mechanics**

I'm thinking about how to compute segments for drawing based on commands, interpreting them sequentially. I might draw lines as I encounter 'F', ensuring that I accurately draw a partial line for any last 'F' encountered. Also, I need to use a stack to preserve state while branching, and stop at renderIndex to draw partial lines. 

For performance, I should allow a maximum of 6 or 7 iterations. I wonder if I should implement a background gradient, though a simple UI may not be necessary. I also need to ensure p5.min.js is in the directory and incorporate retina scaling. I'll provide comments throughout and keep the file self-contained. Implementing an L-system generator sounds interesting! I’m thinking about how to compute the final string and ensure growth is procedural, increasing depth over time. 

Starting from depth 0, I can animate the sway and growth of each drawn string, using an array for sentences.**Developing L-system growth**

I’m planning the L-system with an axiom of "F" and a rule of F transforming into "FF-[-F+F+F]+[+F-F-F]". I think I’ll set the angle at 22.5 degrees and have the length decrease per depth, starting at around 120 and using a scale factor of about 0.5 each generation. I’ll generate sentences for every depth up to the max.

I need to track my current depth and implement a growth variable that increments between 0 and 1. Once growth reaches 1, I can pause before increasing the depth until it hits maxDepth, or I could keep it at maxDepth. The user wants to see a procedural fractal tree that sways gently, so I should aim for continuous growth from the trunk to the full tree, always swaying. 

To do this, I’ll precompute sentences and begin with currDepth set to 0, using a growth length variable to dictate how much of the sentence to render. I’ll progress the render index each frame, speeding up until it reaches the sentence length. After hitting the end, I could pause and possibly increase currDepth, repeating this process until I’ve reached maxDepth, while ensuring the tree keeps swaying continuously.**Animating sway for branches**

I want to ensure that even after fully drawing the tree, the branches still sway. To achieve this, I could modulate the branch angles during the drawing process, rather than just using the recorded angle. Sway should happen at runtime while interpreting the drawing.

I’ll implement a function called `renderSentence(sentence, length, angle)` that uses a render limit based on the current progress. I’ll loop through commands for drawing, handling a partial line when I reach the final 'F' command. 

I'll also maintain stack states while using a frameTime variable for calculating sway. When processing a '+' or '-', I can adjust the heading by the base angle plus a sway term. I’ll compute this sway term based on the current position and time so that sway can reflect real-time variations as I render.**Calculating sway and depth**

I’m thinking about how to compute the sway for my branches. The formula I have in mind is sway = sin(millis() * speed + x * spatial + y * spatial) * amplitude * branchFactor. It’s important to derive branchFactor from the current depth, which I’ll need to track in the stack containing position, angle, and depth.

I’m considering whether the depth should remain the same or increment when we push to the stack. For my L-systems, each 'F' corresponds to drawing and likely increases the depth along the branch. I need to track a local depth variable that I’ll start at 0, incrementing on each 'F' and decrementing when popping. 

Branching should reset to the stack's depth, so once I encounter 'F’, I can draw and then increment the depth by 1 after drawing. When I move forward, a bracket push will duplicate the depth. I think this approach will work well!**Managing depth and sway**

I'm organizing the stack state to include depth: when executing 'F', I’ll increment the depth for the next segment. When I encounter a branch push with '[', I’ll save the current position, angle, and depth. For a ']', I’ll pop the state. The angles will rotate right for '+' and left for '-'.

For sway, I plan to add a small varying amount based on depth—young branches should sway more. The amplitude could equal baseAmp scaled by depth. I’m considering whether the amplitude should increase or decrease with depth. Thinner, younger branches often sway more, which means as depth increases, the sway amplitude could be larger.

I’ll track the depth relative to maxDepth and use it for scaling. I need to ensure the stack operations are consistent too. Next, I’ll set up the canvas, translate it to the bottom center, and draw the trunk upward along the negative y-axis. I’ll also incorporate a color gradient based on depth, and add leaf rendering using small green ellipses at the end of segments.

I’ll time scale using p5's millis()/1000, and then I'll write the index.html file. I’ll use p5.js and code it under the <script> tag after the source. I’ll set the body margin to 0 and include an instruction text overlay. I need to be careful with bracket characters during file edits, so I’ll generate a new file using functions.write. It’s time to produce some content!
write index.html (8352 bytes)
toolResult

Successfully wrote 8352 bytes to index.html

assistant

I created index.html with a self-contained p5.js sketch that grows an L-system fractal tree and makes it sway in the wind. Open index.html in a browser (the provided p5.min.js is loaded) to view the animation.

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

modelgpt-5-mini
vendorOpenAI
harnesspi-agent
generated2026-07-22

EVALUATION

3/5 working

L-system tree grows and sways gently in wind; looks simplistic and thin, no real branching structure visible.

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 motion2.7%
on click0.7%
on drag0.6%
on wheel0.4%
on enter + space2.3%
on arrow keys4.5%
on w/a/s/d2.2%
frame spread16.4 / 255
console errors0
js errors none

METRICS

runtime57.7s
tokens in3.8k
tokens out4.0k
cached1.2k
cost / run$0.0090