- #1
MarkFL
Gold Member
MHB
- 13,288
- 12
I thought it would be nice to begin a thread where we can post examples of TikZ code that the community can use as templates or jumping off points for their own images. I would recommend not posting a huge number of images in the same post, so we don't strain the rendering server (maintained by I like Serena), or MHB's server.
I'll begin with a Sudoku 3D cube:
\begin{tikzpicture}[every node/.style={minimum size=1cm},on grid]
%preamble \usetikzlibrary{positioning}
\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5]
\shade[right color=gray!10, left color=black!50] (0,0) rectangle +(3,3);
\node at (0.5,2.5) {9};
\node at (1.5,2.5) {7};
\node at (2.5,2.5) {1};
\node at (0.5,1.5) {2};
\node at (1.5,1.5) {4};
\node at (2.5,1.5) {8};
\node at (0.5,0.5) {5};
\node at (1.5,0.5) {3};
\node at (2.5,0.5) {6};
\draw (0,0) grid (3,3);
\end{scope}
\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]
\shade[right color=gray!70,left color=gray!10] (3,-3) rectangle +(3,3);
\node at (3.5,-0.5) {3};
\node at (4.5,-0.5) {9};
\node at (5.5,-0.5) {7};
\node at (3.5,-1.5) {6};
\node at (4.5,-1.5) {1};
\node at (5.5,-1.5) {5};
\node at (3.5,-2.5) {8};
\node at (4.5,-2.5) {2};
\node at (5.5,-2.5) {4};
\draw (3,-3) grid (6,0);
\end{scope}
\begin{scope}[every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\shade[bottom color=gray!10, top color=black!80] (6,3) rectangle +(-3,-3);
\node at (3.5,2.5) {1};
\node at (3.5,1.5) {4};
\node at (3.5,0.5) {7};
\node at (4.5,2.5) {5};
\node at (4.5,1.5) {6};
\node at (4.5,0.5) {8};
\node at (5.5,2.5) {2};
\node at (5.5,1.5) {3};
\node at (5.5,0.5) {9};
\draw (3,0) grid (6,3);
\end{scope}
\end{tikzpicture}
And a belt and pulley system:
\begin{tikzpicture}
% Definitions
\pgfmathsetmacro{\b}{75}
\pgfmathsetmacro{\a}{15}
\pgfmathsetmacro{\R}{2}
\pgfmathsetmacro{\r}{1}
\pgfmathsetmacro{\P}{\R*tan(\b)}
\pgfmathsetmacro{\Q}{\R/cos(\b)}
\pgfmathsetmacro{\p}{\r/tan(\a)}
\pgfmathsetmacro{\q}{\r/sin(\a)}
% Pulleys
% Big pulley
\draw (0,0) circle (\R) ;
\fill[left color=gray!80, right color=gray!60, middle
color=white] (0,0) circle (\R) ;
\draw[thick, white] (0,0) circle (.8*\R);
\shade[ball color=white] (0,0) circle (.3) node[left,xshift=-5] {$P$};
% small pulley
\draw (\Q+\q-.3, 0) circle (\r);
\fill[left color=gray!80, right color=gray!60, middle
color=white] (\Q+\q-.3, 0) circle (\r) ;
\draw[thick, white] (\Q+\q-.3,0) circle (.8*\r);
\shade[ball color=white] (\Q+\q-.3,0) circle (.15)
node[right, xshift=2] {$Q$};
% belt and point labels
\begin{scope}[ultra thick]
\draw (\b:\R) arc (\b:360-\b:\R) ;
\draw (\b:\R) -- ( \P, 0 );
\draw (-\b:\R) -- ( \P, 0 );
\draw (\Q-.3,0) -- + (\a:\p) arc (105:-105:\r) ;
\draw (\Q-.3,0) -- + (-\a:\p);
%\draw (\b:\R) arc (\b:360-\b:\r) ;
\end{scope}
\draw (0,0) -- (\b:\R) node[midway, above,sloped] {$R$} node[above] {$A$};
\draw (-\b:\R)--(0,0) ;
\draw (\Q+\q-.3,0) -- +(105:\r) node[midway,above, sloped] {$r$}
node[above] {$E$};
\draw (\Q+\q-.3,0) -- +(-105:\r) node[below] {$D$};
\node[below] at (-\b:\R) {$B$};
\node[below] at (\Q-.3,0) {$C$};
% center line
\draw[dash pattern=on5pt off3pt] (0,0) -- (\Q+\q-.3,0);
% angle label
\node[fill=white] at (0.73*\Q, 0) {$\theta$} ;
\draw (\Q-1.8,0) arc (180:195:1.5);
\draw (\Q-1.8,0) arc (180:165:1.5);
\end{tikzpicture}
I'll begin with a Sudoku 3D cube:
\begin{tikzpicture}[every node/.style={minimum size=1cm},on grid]
%preamble \usetikzlibrary{positioning}
\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5]
\shade[right color=gray!10, left color=black!50] (0,0) rectangle +(3,3);
\node at (0.5,2.5) {9};
\node at (1.5,2.5) {7};
\node at (2.5,2.5) {1};
\node at (0.5,1.5) {2};
\node at (1.5,1.5) {4};
\node at (2.5,1.5) {8};
\node at (0.5,0.5) {5};
\node at (1.5,0.5) {3};
\node at (2.5,0.5) {6};
\draw (0,0) grid (3,3);
\end{scope}
\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]
\shade[right color=gray!70,left color=gray!10] (3,-3) rectangle +(3,3);
\node at (3.5,-0.5) {3};
\node at (4.5,-0.5) {9};
\node at (5.5,-0.5) {7};
\node at (3.5,-1.5) {6};
\node at (4.5,-1.5) {1};
\node at (5.5,-1.5) {5};
\node at (3.5,-2.5) {8};
\node at (4.5,-2.5) {2};
\node at (5.5,-2.5) {4};
\draw (3,-3) grid (6,0);
\end{scope}
\begin{scope}[every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\shade[bottom color=gray!10, top color=black!80] (6,3) rectangle +(-3,-3);
\node at (3.5,2.5) {1};
\node at (3.5,1.5) {4};
\node at (3.5,0.5) {7};
\node at (4.5,2.5) {5};
\node at (4.5,1.5) {6};
\node at (4.5,0.5) {8};
\node at (5.5,2.5) {2};
\node at (5.5,1.5) {3};
\node at (5.5,0.5) {9};
\draw (3,0) grid (6,3);
\end{scope}
\end{tikzpicture}
And a belt and pulley system:
\begin{tikzpicture}
% Definitions
\pgfmathsetmacro{\b}{75}
\pgfmathsetmacro{\a}{15}
\pgfmathsetmacro{\R}{2}
\pgfmathsetmacro{\r}{1}
\pgfmathsetmacro{\P}{\R*tan(\b)}
\pgfmathsetmacro{\Q}{\R/cos(\b)}
\pgfmathsetmacro{\p}{\r/tan(\a)}
\pgfmathsetmacro{\q}{\r/sin(\a)}
% Pulleys
% Big pulley
\draw (0,0) circle (\R) ;
\fill[left color=gray!80, right color=gray!60, middle
color=white] (0,0) circle (\R) ;
\draw[thick, white] (0,0) circle (.8*\R);
\shade[ball color=white] (0,0) circle (.3) node[left,xshift=-5] {$P$};
% small pulley
\draw (\Q+\q-.3, 0) circle (\r);
\fill[left color=gray!80, right color=gray!60, middle
color=white] (\Q+\q-.3, 0) circle (\r) ;
\draw[thick, white] (\Q+\q-.3,0) circle (.8*\r);
\shade[ball color=white] (\Q+\q-.3,0) circle (.15)
node[right, xshift=2] {$Q$};
% belt and point labels
\begin{scope}[ultra thick]
\draw (\b:\R) arc (\b:360-\b:\R) ;
\draw (\b:\R) -- ( \P, 0 );
\draw (-\b:\R) -- ( \P, 0 );
\draw (\Q-.3,0) -- + (\a:\p) arc (105:-105:\r) ;
\draw (\Q-.3,0) -- + (-\a:\p);
%\draw (\b:\R) arc (\b:360-\b:\r) ;
\end{scope}
\draw (0,0) -- (\b:\R) node[midway, above,sloped] {$R$} node[above] {$A$};
\draw (-\b:\R)--(0,0) ;
\draw (\Q+\q-.3,0) -- +(105:\r) node[midway,above, sloped] {$r$}
node[above] {$E$};
\draw (\Q+\q-.3,0) -- +(-105:\r) node[below] {$D$};
\node[below] at (-\b:\R) {$B$};
\node[below] at (\Q-.3,0) {$C$};
% center line
\draw[dash pattern=on5pt off3pt] (0,0) -- (\Q+\q-.3,0);
% angle label
\node[fill=white] at (0.73*\Q, 0) {$\theta$} ;
\draw (\Q-1.8,0) arc (180:195:1.5);
\draw (\Q-1.8,0) arc (180:165:1.5);
\end{tikzpicture}
Last edited by a moderator: