Skip to content

Instantly share code, notes, and snippets.

@drorata
Last active August 29, 2015 13:55
Show Gist options
  • Save drorata/8709182 to your computer and use it in GitHub Desktop.
Save drorata/8709182 to your computer and use it in GitHub Desktop.
Colorful drawing of the spiral of roots using TikZ
% The Spiral of Roots (https://gist.github.com/drorata/8709182)
%
% Inspired by Felix Lindemann (http://www.texample.net/tikz/examples/rooty-helix/)
%
% Author: Dror Atariah, drorata@gmail.com
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\xdefinecolor{darkgreen}{RGB}{175, 193, 36}
\def\couleur{darkgreen}
\newcounter{prev}
\begin{tikzpicture}
\def\numTs{120}
\def\angTol{0} % Allows a randomized spiral
\coordinate (o) at (0,0);
\coordinate (p0) at (0:1);
\foreach \i in {1,...,\numTs}
{ % Compute the vertices of the spiral
\pgfmathsetcounter{prev}{\i-1}
\pgfmathparse{rand}
\let\rand\pgfmathresult
% Randomizes the angle to be used with at most +/-\anglTol
\pgfmathsetmacro{\angle}{270+(1-\rand)*(-\angTol)+\angTol*\rand}
\coordinate (p\i) at ($(p\theprev)!1cm!\angle:(o)$);
}
\foreach[count=\j from 1] \i in {\numTs,...,1}
{ % Draw the triangles and color them in a REVERSE order.
\pgfmathsetcounter{prev}{\i-1}
\pgfmathparse{1*\j}
\filldraw[draw=gray,fill=\couleur!\pgfmathresult] (o) -- (p\theprev) -- (p\i) -- cycle;
\fill (p\i) circle (2pt);
}
\fill (p0) circle (2pt);
\fill (o) circle (2pt);
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment