Binary Fractal Tree
Generate and customize interactive binary fractal trees with adjustable depth, angles, wind animation, and color gradients in real time.
About
A binary fractal tree is a recursive geometric structure where each branch spawns exactly two child branches at a specified angle θ. The branch length decreases by a ratio factor r at every recursion level, producing self-similar patterns characteristic of fractal geometry. At depth d the tree contains 2d − 1 total segments. Misconfigured parameters produce degenerate or visually collapsed trees. This tool renders the full recursive structure on an HTML5 Canvas with real-time wind simulation and HSL color interpolation from trunk to canopy.
The rendering uses trigonometric endpoint calculation per branch. Wind is modeled as a time-varying sinusoidal perturbation Δθ = A ⋅ sin(ωt + φdepth) applied per recursion level, creating a natural swaying effect. Depth beyond 15 is capped to prevent rendering > 32,768 branches per frame. The tool approximates organic tree forms under the assumption of uniform branching symmetry.
Formulas
Each branch endpoint is computed via polar-to-Cartesian conversion from the parent endpoint. Given a parent tip at (x0, y0) with direction angle α and branch length L:
At each recursion level, two child branches are created with angles α − θ (left) and α + θ (right), and the new length is scaled:
The total number of segments in the tree is a geometric series:
Wind perturbation per level at time t:
Where α is the current branch direction angle, θ is the branching spread angle, r is the length ratio (0 < r < 1), d is the maximum recursion depth, A is the wind amplitude, ω is the wind frequency, and k is the current recursion level.
Reference Data
| Depth d | Total Branches | Tip Branches | Length Ratio r = 0.67 | Length Ratio r = 0.75 | Typical Angle θ |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 100 px | 100 px | 25° |
| 2 | 3 | 2 | 67 px | 75 px | 25° |
| 3 | 7 | 4 | 44.9 px | 56.3 px | 30° |
| 4 | 15 | 8 | 30.1 px | 42.2 px | 30° |
| 5 | 31 | 16 | 20.2 px | 31.6 px | 30° |
| 6 | 63 | 32 | 13.5 px | 23.7 px | 35° |
| 7 | 127 | 64 | 9.1 px | 17.8 px | 35° |
| 8 | 255 | 128 | 6.1 px | 13.3 px | 25° |
| 9 | 511 | 256 | 4.1 px | 10.0 px | 25° |
| 10 | 1,023 | 512 | 2.7 px | 7.5 px | 20° |
| 11 | 2,047 | 1,024 | 1.8 px | 5.6 px | 20° |
| 12 | 4,095 | 2,048 | 1.2 px | 4.2 px | 20° |
| 13 | 8,191 | 4,096 | 0.8 px | 3.2 px | 15° |
| 14 | 16,383 | 8,192 | 0.5 px | 2.4 px | 15° |
| 15 | 32,767 | 16,384 | 0.4 px | 1.8 px | 15° |