4

I have latex code:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document} \pgfdeclarelayer{background} \pgfdeclarelayer{foreground} \pgfsetlayers{background,main,foreground} \xdefinecolor{darkgreen}{RGB}{175, 193, 36} \newcounter{cntShader} \newcounter{cntRoot} \setcounter{cntShader}{20} \def\couleur{darkgreen}

\begin{tikzpicture} \foreach \y in {86,38,15}{ \setcounter{cntShader}{1} \coordinate (a) at (0,0); \coordinate (b) at (0:1); \foreach \x in {1,...,\y}{% \coordinate (c) at ($ (b)!1cm!270:(a) $); \begin{pgfonlayer}{background} \draw[fill=\couleur!\thecntShader] (a)--(b)--(c)--cycle; \end{pgfonlayer} \setcounter{cntRoot}{\x} \addtocounter{cntRoot}{1} \node[fill=white,draw,circle,inner sep=1pt] at (c) {$\sqrt{\thecntRoot}$}; \coordinate (b) at (c); \pgfmathsetcounter{cntShader}{\thecntShader+4} \setcounter{cntShader}{\thecntShader} } } \node[fill=white,draw,circle,inner sep=1pt] at (0:1) {$\sqrt{1}$}; \end{tikzpicture}

\end{document}

it turns out the following picture: enter image description here

I don't know the line \coordinate (c) at ($ (b)!1cm!270:(a) $); mean. And I am confused about why to use \pgfdeclarelayer{foreground} and \pgfsetlayers{background,main,foreground}. I just see the code use background layer in \begin{pgfonlayer}{background}.

yllgl
  • 41
  • 1
    Do not use \documentclass{minimal} - it is a special class -not for minimal examples. - use standalone or article. – hpekristiansen Sep 22 '21 at 03:39
  • Just for reference: https://tex.stackexchange.com/questions/42114/why-should-the-minimal-class-be-avoided?noredirect=1&lq=1 and https://tex.meta.stackexchange.com/questions/228/ive-just-been-asked-to-write-a-minimal-working-example-mwe-what-is-that – hpekristiansen Sep 22 '21 at 03:51

1 Answers1

3

P.151 in the manual:

⟨coordinate⟩!⟨dimension⟩!⟨angle⟩:⟨second coordinate⟩ When you write ⟨a⟩!⟨dimension⟩!⟨b⟩, this means the following: Use the point that is distanced ⟨dimension⟩ from ⟨a⟩ on the straight line from ⟨a⟩ to ⟨b⟩

As before, if you use a ⟨angle⟩, the ⟨second coordinate⟩ is rotated by this much around the ⟨coordinate⟩ before it is used.

Examples can be seen on page 151 in the manual.

\coordinate (c) at ($ (b)!1cm!270:(a) $);

means stand at (b) look in the direction of (a), turn 270 degrees and walk 1 cm. At this position place coordinate (c).


Yes the code would work without the foreground layer, but why not keep it as a standard way of having useful layers.