Staaarter

Generate a Pythagoras Tree Fractal

Builds the classic Pythagoras tree fractal: starting from one square, two smaller squares sprout from its top edge at a 45-degree angle (as if resting on the legs of a right triangle drawn on that edge), and the same branching repeats recursively from each new square, exported as SVG or PNG. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
fractalgeneratorsvg

Overview

Introduction

The Pythagoras tree turns one of the most familiar results in all of mathematics, the Pythagorean theorem, into a striking recursive fractal, built entirely from squares and right triangles rather than any exotic formula.

This tool renders the classic symmetric version at 45 degrees: pick a depth, and watch a single square branch into a full, tree-like silhouette of progressively smaller squares.

What Is Generate a Pythagoras Tree Fractal?

A generator for the Pythagoras tree, a classic plane fractal built by repeatedly placing two smaller squares on the legs of a right triangle drawn on a parent square's top edge.

This generator uses the 45-degree case, where the right triangle on top of every square is isosceles, so the two child squares at each branching are always equal in size.

How Generate a Pythagoras Tree Fractal Works

Starting from a single base square, a right triangle is imagined sitting on its top edge with its right angle pointing upward; at 45 degrees, that triangle's two legs are equal, meeting at a peak directly above the square's center.

A new, smaller square is erected on each of the triangle's two legs, angled outward from the parent square, these become the two child branches, each exactly half the parent square's area at the 45-degree angle.

The same construction repeats recursively on every new square: a right triangle on its top edge, two smaller squares on that triangle's legs, down to the chosen depth. The recursion is depth-first, generation by generation, until every branch reaches the target depth.

When To Use Generate a Pythagoras Tree Fractal

Use it to demonstrate a visually compelling, elementary-geometry-based fractal for a math class covering the Pythagorean theorem, since the construction makes the a^2 + b^2 = c^2 area relationship directly visible in every branching.

It's also a good source of a clean, tree-shaped SVG illustration for articles or teaching material about recursive geometric fractals.

Features

Advantages

  • Built entirely from elementary geometry, squares and right triangles, making the underlying math intuitive even without prior fractal background.
  • The 45-degree case produces a visually balanced, symmetric tree silhouette that's immediately recognizable.
  • Exports as clean vector SVG or a flattened PNG for use in illustrations or teaching material.

Limitations

  • This generator fixes the branching angle at the classic 45 degrees; other angles (which produce lopsided or even self-overlapping trees) aren't exposed as a separate control here.
  • Depth is capped at 11 for renderability, since the square count grows roughly geometrically with depth.

Examples

Depth 0

Input

Depth = 0

Output

A single square, the untouched starting shape.

At depth 0, no branching has happened yet.

Depth 8

Input

Depth = 8

Output

A full tree-shaped silhouette of squares fanning outward and upward from the base square, narrowing toward the branch tips.

Each generation doubles the number of new squares (two children per parent), so by depth 8 the tree has hundreds of squares across all generations.

Best Practices & Notes

Best Practices

  • Start around depth 6 to 8 to see the full recognizable tree silhouette before pushing toward the depth 11 maximum, where the smallest squares become very thin slivers.
  • Download as SVG if you want to recolor or trace individual squares afterward in a vector editor.

Developer Notes

Implemented as a recursive `square` function that takes a base edge (two points) and computes the triangle apex via `Math.atan2` plus the fixed branching angle, then recurses on the two new base edges formed by the parent square's far corner and the apex. The angle is clamped between 15 and 75 degrees internally for numerical stability, and this tool always calls it with exactly 45 degrees for the classic symmetric case.

Generate a Pythagoras Tree Fractal Use Cases

  • Teaching the Pythagorean theorem through a visual, recursive geometric construction
  • Generating a recognizable tree-shaped fractal illustration for an article or course
  • Demonstrating how simple, repeated elementary geometry produces complex emergent structure

Common Mistakes

  • Expecting an organic, randomized tree shape, this is a fully deterministic geometric construction, the same depth always produces exactly the same tree.
  • Setting depth to the maximum expecting a dramatically different silhouette from depth 8 or 9, past a certain depth the added squares become too small to noticeably change the tree's outline.

Tips

  • Compare it against the H-fractal Generator and V-tree Fractal Generator to see three different recursive branching structures built from very different underlying rules.
  • Look closely at any branch of the tree, it's a smaller, rotated copy of the whole tree, the defining property of a self-similar fractal.

References

Frequently Asked Questions