pythagoras-fractal
The Pythagoras tree is a fractal constructed from squares: place a square, attach two smaller squares on top at right angles forming a triangle (the Pythagorean theorem visualised), repeat on each child. The result resembles a stylized tree. Different angles produce dramatically different shapes — 45° gives the symmetric classic; other angles produce asymmetric "windswept" forms. The ZTools Pythagoras Tree generator builds the fractal in SVG up to depth 12 with configurable angle, color, and size.
Use cases
Decorative SVG
Background or hero element with mathematical / organic feel.
Teach the Pythagorean theorem
Visual demonstration of a² + b² = c² in fractal form.
Generative art
Tweak angles for unexpected shapes.
CS teaching — recursion
Each level is a recursive call. Watch the tree grow as depth increases.
How it works
- Pick parameters — Angle (default 45° for classic; 30° / 60° produce asymmetric trees). Depth (5-12). Colors. Stroke width.
- Render — Recursive draw: square → two children at angle → recurse.
- Export SVG — Vector for scaling / printing.
Examples
Input: angle 45°, depth 10
Output: Classic symmetric Pythagoras tree.
Input: angle 30°, depth 10
Output: Asymmetric "leaning" tree.
Input: angle 60°, depth 8
Output: Wide, bushy variant.
Frequently asked questions
Why does depth 12 freeze?
Depth N produces 2^N squares. Depth 12 = 4,095 squares; depth 15 = 32,767. Beyond ~12, SVG path count slows.
Privacy?
All in browser.
Tips
- 45° is the classic — most recognisable.
- For posters, depth 11+ at high resolution gives stunning detail.
- Combine with color gradient (depth-based) for added visual interest.
Try it now
The full pythagoras-fractal runs in your browser at https://ztools.zaions.com/pythagoras-fractal — no signup, no upload, no data leaves your device.
Last updated: 2026-05-06 · Author: Ahsan Mahmood · Edit this page on GitHub