A Two-Dimensional Folding Visualization
This site’s 2D Benesi implementation colours a plane using repeated box folds, sphere folds and scaling. It is a simplified folding experiment, rather than a rendering of the original 3D Benesi Pine Tree formula. The visible colour bands record how quickly points escape. The separate 3D Pine Tree explorer renders the quadratic formula as a rotatable, shaded surface; the two formulas therefore look different.
The formula does two things on each iteration:
- Box fold: Clamp each coordinate to [-1, 1], then reflect:
z = clamp(z, -1, 1) * 2 - z. This creates sharp creases and symmetry breaks. - Sphere fold: If the point falls inside a minimum radius, scale it outward. If it's between the minimum and fixed radius, invert it through a sphere. Points outside pass through unchanged.
After both folds, multiply everything by a scale factor and repeat. The box fold produces angular branching. The sphere fold rounds and inflates the branches. Together they generate structures that split and subdivide like wood grain.
What This Implementation Shows
Each pixel supplies an initial x and y coordinate with z fixed at zero. The shader repeats box and sphere folds, then applies scale. Since these operations keep the starting z coordinate at zero, the result is a two-dimensional view. There is no 3D camera or ray-marched surface in this explorer.
For a rotatable Pine Tree surface, open the Benesi 3D explorer, which uses coordinate multipliers and per-iteration rotation. Compare the Mandelbox explorer for box and sphere folds in 3D. The 2D images above illustrate the folding experiment, not the quadratic Pine Tree surface.
Reading the Pattern
Interior points are those that do not cross the bailout radius within the iteration limit. Escaping points receive a smooth iteration value and are coloured by the selected palette. A colour change may reflect a different escape count rather than a new geometric feature.
Scale multiplies the point after each fold. The minimum and fixed radii choose the regions where sphere folding rescales it. Start from the balanced preset, change one setting at a time, and compare the boundaries. Keep minimum radius smaller than fixed radius for a useful starting point.
Rotation rotates the input plane before the fold calculation. It changes the orientation of the view; it does not create a third spatial dimension.
Exploring It
Smoothly varies the scale and folding radii, so the fractal grows, thins, and restructures in real time. Useful for seeing how the fold calculation responds to different settings.
Pan, zoom, and rotate the 2D view. In the explorer, enable Interact for gestures, or use the visible zoom buttons and offset sliders.
How the Renderer Works
The shader runs the box-fold/sphere-fold loop for each pixel, tracking how fast the point escapes to a bailout radius. Points that never escape get colored as interior (the "tree" itself). Escaped points get a smooth iteration count that feeds into the color palette.
At high zoom levels, the renderer switches to 2x2 supersampling to keep edges clean. Iteration counts scale with zoom depth automatically, so deep zooms don't lose detail. The whole thing runs per-pixel on the GPU, which is why parameter changes update in real time.