How to shade a parallelogram in TIKZ

Using the key shading angle=<> you can rotate the shading in whatever direction you want. If you need even more fine control, you could also define you own shading, see section 109.3 of the tikz manual for this.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
\node[trapezium, draw,trapezium left angle=120, trapezium right angle=60,shade,shading=axis,shading angle=100] at (0,0) {};
\end{tikzpicture}

\end{document}

enter image description here


An option using basic iterative tricks, to make fake shading, but it is pure 2D, If you want a real 3D result you must see Asymptote to obtain results like this How to create horn torus in latex?, also pgf-plots allows to manage surface colors like in example_171.pdf.

RESULT: enter image description here

MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: animate: {density: 200, delay: 20, other: -background white -alpha remove}
% arara: showanimate
\documentclass[tikz,border=20pt]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{calc}
\usetkzobj{all}

\begin{document}
\foreach \A in {0,1,...,15,14,13,...,0}{
\begin{tikzpicture}
    % Set limits.
    \tkzInit[xmax=7,xmin=-2,ymax=4, ymin=-3.5]
    \tkzGrid[sub,color=blue!20!,subxstep=.5,subystep=.5]
    \tkzClip

    %Define principal points.
    \tkzDefPoint(\A*0.05,-1+\A*0.1){A} 
    \tkzDefPoint(2-\A*0.2,-\A*0.15){B}
    \tkzDefPoint(3+\A*0.08,2-\A*0.1){C}
    \tkzDefLine[parallel=through C](B,A) \tkzGetPoint{D}  

    %Label the points
    \tkzLabelPoints[color=blue,below=5pt](A,B)
    \tkzLabelPoints[color=blue,above=5pt](C,D)

    % Draw all the shades.
    \foreach \i in {0,1,...,30}{
        \node(m) at ($(D)!\i/30!(A)$){};
        \node(n) at ($(C)!\i/30!(B)$){};
        \fill [blue, fill opacity=1/30] 
        (A) -- (m.center) -- (n.center) -- (B) -- cycle;
    }
    %Draw the segments
    \tkzDrawSegments[thick](A,B B,C C,D D,A)
\end{tikzpicture}}
\end{document}

PSD: It generates a pdf document with animation frames, to convert into .gif I use Imagemagick converter


A PSTricks solution.

\documentclass[pstricks,border=10mm]{standalone}
\begin{document}
\foreach \i in {0,10,...,170}{%
\begin{pspicture}(6,4)
    \pspolygon[fillstyle=vlines,hatchangle=\i](0,0)(4,0)(6,4)(2,4)
    \rput*(3,2){$\i^\circ$}
\end{pspicture}}
\end{document}

enter image description here

Another version

\documentclass[pstricks,border=10mm]{standalone}
\begin{document}
\foreach \i in {0,10,...,80}{%
\begin{pspicture}(6,4)
    \pspolygon[fillstyle=crosshatch,hatchcolor=red,hatchangle=\i](0,0)(4,0)(6,4)(2,4)
    \rput*(3,2){$\i^\circ$}
\end{pspicture}}
\end{document}

enter image description here

Tags:

Tikz Pgf