summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tikzbricks
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-08-10 21:13:23 +0000
committerKarl Berry <karl@freefriends.org>2021-08-10 21:13:23 +0000
commitc7c9c5632a60eb536489e03d30c96c92e70b1d3f (patch)
tree1908646f15c4934ef73c57c56ea99e8e3ac8933a /Master/texmf-dist/tex/latex/tikzbricks
parentc8bd4c1c3adabafbf923c2b113765baf5db7a317 (diff)
tikzbricks (10aug21)
git-svn-id: svn://tug.org/texlive/trunk@60211 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/tikzbricks')
-rw-r--r--Master/texmf-dist/tex/latex/tikzbricks/tikzbricks.sty101
1 files changed, 101 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/tikzbricks/tikzbricks.sty b/Master/texmf-dist/tex/latex/tikzbricks/tikzbricks.sty
new file mode 100644
index 00000000000..261f29780f4
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/tikzbricks/tikzbricks.sty
@@ -0,0 +1,101 @@
+ % !TeX root = ./test.tex
+\ProvidesPackage{tikzbricks}[2021/08/10 version v0.1 Drawing bricks with TikZ]
+
+\RequirePackage{tikz}
+\RequirePackage{tikz-3dplot}
+\tdplotsetmaincoords{70}{160}
+\newcounter{brickx}
+\newcounter{bricky}
+\newcounter{brickz}
+\setcounter{brickx}{0}
+\setcounter{bricky}{0}
+\setcounter{brickz}{0}
+
+\newcommand*{\brick}[3][]{%
+ \setcounter{brickx}{0}%
+ \setcounter{bricky}{0}%
+ \setcounter{brickz}{0}%
+ \begin{scope}%
+ \tikzset{/brick/.cd,#1}%
+ \brick@draw{#2}{#3}%
+ \end{scope}%
+}
+
+\newcommand*{\wallbrick}[3][]{%
+ \begin{scope}%
+ \tikzset{/brick/.cd,#1}%
+ \brick@draw{#2}{#3}%
+ \end{scope}%
+ \addtocounter{brickx}{#2}%
+}
+
+\newenvironment{wall}[1][]{%
+ \setcounter{brickx}{0}%
+ \setcounter{bricky}{0}%
+ \setcounter{brickz}{0}%
+ \newcommand{\newrow}{%
+ \setcounter{brickx}{0}%
+ \addtocounter{brickz}{1}%
+ }%
+ \begin{tikzpicture}[#1]
+}{%
+ \end{tikzpicture}%
+}
+
+\tikzset{
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %
+ % Pass unknown keys on to tikz
+ %
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ /brick/.search also={/tikz,/pgf},
+ /brick/.cd,
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %
+ % brick options
+ %
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ color/.code = \def\brick@color{#1},
+ color = red,
+ brickheight/.code = \def\brick@height{#1},
+ brickheight = 1.3,
+ studtext/.code = \def\brick@text{#1},
+ studtext = {},
+}
+
+\newcommand{\brick@draw}[2]{%
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %
+ % store the current scale factor
+ % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
+ %
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
+ \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
+ \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
+ \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
+ %
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %
+ % Drawing the brick
+ %
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ \begin{scope}[tdplot_main_coords]
+
+ % drawing faces
+ \fill[\brick@color!60,thick] (0+\value{brickx},#2+\value{bricky},0+\brick@height*\value{brickz}) -- ++(#1,0,0) -- ++(0,0,\brick@height) -- ++(-#1,0,0) -- cycle; % top
+ \fill[\brick@color!40,thick] (0+\value{brickx},0+\value{bricky},\brick@height+\brick@height*\value{brickz}) -- ++(0,#2,0) -- ++(#1,0,0) -- +(0,-#2,0) -- cycle; % front
+ \fill[\brick@color,thick] (#1+\value{brickx},0+\value{bricky},0+\brick@height*\value{brickz}) -- ++(0,0,\brick@height) -- ++(0,#2,0) -- ++(0,0,-\brick@height) -- cycle; % right
+
+ %drawing studs
+ \foreach \x in {1,...,#1}{
+ \foreach \y in {1,...,#2}{
+ \fill[\brick@color] (\x-0.5+\value{brickx},\y-0.5+\value{bricky},\brick@height+\brick@height*\value{brickz}) circle [radius=0.35];
+ \fill[\brick@color] (\x-0.5+\value{brickx},\y-0.5+\value{bricky},\brick@height+\brick@height*\value{brickz}) ++(canvas cs:x=-10) -- ++(canvas cs:y=3) -- ++(canvas cs:x=20) -- ++(canvas cs:y=-3);
+ \fill[\brick@color!60] (\x-0.5+\value{brickx},\y-0.5+\value{bricky},\brick@height+\brick@height*\value{brickz}) ++(canvas cs:y=3) circle [radius=0.35] node[\brick@color,scale=\scalingfactor*0.5, font=\sffamily] {\brick@text};
+ }
+ }
+
+ \end{scope}
+}
+