panthema / 2013 / 0627-TikZ-Pythagoras-Tree
Small TikZ Drawing of a Pythagoras Tree

Small TikZ Drawing of a Pythagoras Tree

Posted on 2013-06-27 23:23 by Timo Bingmann at Permlink with 0 Comments. Tags: fun

This post just contains a simple TikZ/LaTeX program to construct a Pythagoras tree. I wrote it to figure out how to write recursive TikZ drawings. The rest is rather pretty.

Without further ado:

% Draw Pythagoras Trees using TikZ
% Author: Timo Bingmann <>, 2013-06-27


% recursively draw a Pythagoras Tree fractal
% \PythagorasTree{levels}{angle}
    % randomly pick a color, prefer green and blue shades

    % draw the rectangle of this level
    \draw[draw=MyColor] (0,0) rectangle (1,1);

    % decrement level counter

    % transform scope for left branch: move origin (1cm,0cm), rotate and scale
    % with the length of the left cathetus.

    % now for the tricks: transform scope for right branch: move origin to the
    % top point of the triangle, rotate reverse and scale with length of right
    % cathetus.
      yshift={1cm * (1 + sin(#2)*cos(#2))},
      xshift={1cm * (cos(#2)*cos(#2))},



% draw just a single Pythagoras Tree
  % recursively draw tree

% macro to draw and annotate a Pythagoras Tree
  % minipage to keep things together
    \textbf{Pythagoras Tree, order #1, angle #2:}

        % recursively draw tree
        #3 % add some extra tikz code


% draw some more trees with different parameters

% draw animated growing Pythagoras Tree
  The following frame is an animated growing Pythagoras Tree, properly
  viewable with Adobe Acrobat or other advanced PDF viewers:

      \MakeTree{\i}{40}{\useasboundingbox (-3,0) rectangle (3.5,4.5);}


Post Comment
E-Mail or Homepage:

URLs (http://...) are displayed, e-mails are hidden and used for Gravatar.

Many common HTML elements are allowed in the text, but no CSS style.
RSS 2.0 Weblog Feed Atom 1.0 Weblog Feed Valid XHTML 1.1 Valid CSS (2.1)
Copyright 2005-2019 Timo Bingmann - Impressum