Skip to content

Instantly share code, notes, and snippets.

@kpym
Last active August 29, 2015 14:16
Show Gist options
  • Save kpym/bc01800a5d7980fb431e to your computer and use it in GitHub Desktop.
Save kpym/bc01800a5d7980fb431e to your computer and use it in GitHub Desktop.
\documentclass[tikz]{standalone}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}[scale=.03pt]
\tikzmath{
% --------------------------
% the parameters of the tree
% --------------------------
\power=2.3; % the scale base factor
\deviation=70; % the angle between the 3 child edges
\numsteps=7; % number of levels
let \startcolor=magenta; % the start color
let \endcolor=black; % the end color
% -------------------------------------------------------------------------
% the function that draw one edge and call itself to draw the 3 child edges
% -------------------------------------------------------------------------
function Branch(\x,\y,\rotate,\step){
\step=\step-1; % stops drawing if step < 0
if (\step >= 0) then {
\mix = int(100*\step/(\numsteps-1)); % the color mix parameter is in [0,100]
\scale = \power^\step; % the scale factor
{ % "print" the tikz command that draw the edge
\draw[shift={(\x pt,\y pt)}, rotate=\rotate, scale=\scale,
color=\startcolor!\mix!\endcolor, line width=\scale*.1 pt,
line cap=round]
(0,0)--(1,0) coordinate(newbase);
};
coordinate \b; \b1 = (newbase); % the new base point
for \a in {-\deviation,0,\deviation}{
Branch(\bx1,\by1,mod(\rotate+\a,360),\step); % draw one child edge
};
};
};
% ----------------------
% draw the four branches
% ----------------------
for \angle in {0,90,180,-90}{
Branch(0,0,\angle,\numsteps);
};
}
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment