SmtC: Show me the Code
Ole Peter Smith
Instituto de Matemática e Estatística
Universidade Federal de Goiás
http://www.olesmith.com.br

TikZ (Palestra)
Viver é algo que se faz agora ou nunca...
Qual você faz?
Piet Hein
< Programming | Plotting | Filling >

Plotting Functions and Curves

  • Define command:
    \newcommand{\Percentage}[2]{
       \pgfmathparse{int(round(100*#2/#1))}
       \let\crel\pgfmathresult;
    }
  • Define RGB color:
    \definecolor{color1}{rgb}{1,0,0} %red
    \definecolor{color2}{rgb}{0,0,1} %blue
  • Change the Color:
    \tikzstyle{Curve}=[
       ---
       color=color1!\percent!color2,
       ---
    ];
  • Plot:
    \draw
       [
          Curve,
          %rotate=\Angle, %rotates around (0,0)
          rotate around={\Angle:(C)}
       ]
       plot
       (
          {\CX+\a*cos(\t)},
          {\CY+\b*sin(\t)}
       );
TiKZ Listing: Fig.tikz.tex. PDF   PNG   SVG   ZIP*  
%Rotated Ellipsis, C(\cx,\cy)
\tikzmath{\CX=0.5;};
\tikzmath{\CY=1;};

%Last angle (starts with 0)
\tikzmath{\Angle=135;};

%Number of Ellipsis to draw
\tikzmath{\N=10;};

%Half-axis \a \and \b
\tikzmath{\a=2;};
\tikzmath{\b=1;};

%Size of coordinate system
\tikzmath{\size=1.2*max(\a,\b);};


%Base colors
\definecolor{color1}{rgb}{1,0,0}
\definecolor{color2}{rgb}{0,0,1}

%Calculate color factor: percentage rounded
\newcommand{\Percentage}[2]
{
  \pgfmathparse{int(round(100*#2/#1))}
  \let\percent\pgfmathresult;
}

%Calculate color factor: percentage rounded
\draw[-Latex,very thin] (\CX-\size,0) -- (\CX+\size,0) node[right] {$x$};
\draw[-Latex,very thin] (0,\CY-\size) -- (0,\CY+\size) node[above] {$y$};

%Center
\coordinate (C) at (\CX,\CY);

\tikzmath{\dAngle=\Angle/\N;};

%Calculate color factor: percentage rounded
\foreach \n in {0,1,...,\N}
{
    \tikzmath{\Angle=\n*\dAngle;};
   
    \Percentage{\N}{\n}
    \tikzstyle{Curve}=[
       domain=-180:180,
       smooth,
       variable=\t,
       color=color1!\percent!color2
    ];

    \draw
       [
          Curve,
          %rotate=\Angle,
          rotate around={\Angle:(C)}
       ]
       plot
       (
          {\CX+\a*cos(\t)},
          {\CY+\b*sin(\t)}
       );
}
< Programming | Plotting | Filling >
Messages:
0 secs.