Debian Codegraph @

texmf-dist/doc/latex/luatikz/luatikz.tex

raw
1 \documentclass[a4paper,11pt]{ltxdoc}
2
3 \usepackage[utf8]{inputenc}
4 \usepackage{makeidx}\makeindex
5 \usepackage{luatextra}
6 \usepackage[margin=1in]{geometry}
7
8 \usepackage{fancyvrb}
9 \fvset{frame=single,numbers=left,numbersep=3pt,tabsize=4}
10
11 \usepackage{tikz}
12 \usetikzlibrary{math,backgrounds,calc,intersections,arrows.meta,external,decorations.pathreplacing,shadings}
13 \directlua{dofile('./luatikz.lua')}
14
15 \newcommand{\example}[2]
16 {
17 \par#2
18 \VerbatimInput{example/#1.lua}
19 {\centering
20 \begin{tikzpicture}[framed,scale=1]
21 \directlua{dofile('example/#1.lua')tikz.without()}
22 \end{tikzpicture}\par}
23 }
24
25 \newcommand{\examplecode}[2]
26 {
27 \bigskip\par\noindent #2
28 \VerbatimInput{example/#1.lua}
29 }
30
31
32 \title{luatikz}
33 \author{Axel Kittenberger}
34 \def\version{2.12.0}
35 \date{luatikz version \version}
36
37 \setlength{\parindent}{0pt}
38 \setlength{\parskip}{1ex}
39
40 \begin{document}
41
42 \maketitle
43
44 \section{Introduction}
45 Luatikz is a graphics library to draw tikz graphics using the Lua programming language.
46
47 \example{intro}
48 {Following code draws two lines by specifying begin and end points. First using intermediatery variables and the second line within a single codeline:}
49
50 Following \TeX{} wrapper can be used to compile the luatikz Lua code.
51 \VerbatimInput{example/wrapper.tex}
52
53 Luatikz obviously needs \LuaLaTeX{} to compile.
54
55 Note that 2D graphics is a vast topic, functionality to luatikz has been and will be added on a per need basis.
56
57 \section{Pointer math}
58
59 Mathematical operations are possible with points, adding them with each other or multiplying them with a scalar.
60 \example{spiral}{This example uses pointer math to create a spiral:}
61
62 \newpage
63 \section{Immutability}
64
65 In luatikz pointers like all objects are immutable. That means a object once created in memory can no longer be changed.
66 However the variable holding an object can be changed to another object with different attributes.
67
68 \examplecode{immute1}{Thus following example is invalid:}
69 \examplecode{immute2}{This on the other hand are two valid methods to change the value of p1}
70
71 \newpage
72 \section{luatikz objects}
73
74 \subsection{Bezier (quatratic)}
75 \example{bezier2}{A quadratic bezier curve is defined by it begin, end and a control point:}
76
77 \newpage
78 \subsection{Bezier (cubic)}
79 \example{bezier3a}{A cubic bezier curve is defined by it begin, end and two control points:}
80
81 \newpage
82 A cubic bezier has the functions pt and phit that return the point and angle ranging from 0..1 on the curve.
83 \example{bezier3b}{This example draw 10 normal lines onto the bezier curve:}
84
85 \newpage
86 \subsection{BLine}
87 \example{blinea}{A bline is defined by it's begin and it's end. Additionally to the standard line it is bend}
88
89 \newpage
90 \subsection{Circle}
91 \example{circle}{A circle is defined by it's center (``at'') and the circle ``radius'':}
92
93 \newpage
94 \subsection{Curve}
95 \example{curvea}{A curve is defined by a list of points:}
96
97 \newpage
98 \example{curveb}{A curve can cycle and has a changeable tension:}
99
100 \newpage
101 \subsection{Ellipse}
102 \example{ellipse}{An ellipse is difined by it's center (``at'') and a x- and yradius:}
103
104 \newpage
105 \subsection{EllipseArc}
106 \example{ellipseArc}{An ellipse arc is a an ellipse limited by it's ``from'' and ``to'' angle:}
107
108 \newpage
109 \subsection{Line}
110 \example{linea}{A line is defined by it's begin and it's end. There are two basic variants to define a line:}
111
112 \example{lineb}{You can use intersectLine() to find the intersection of a line with another. If there is none ``nil'' will be returned:}
113
114 \newpage
115 \example{linec}{A line can also be defined by it's starting point, angle and length:}
116
117 \example{lined}{``length'' and ``phi'' are attributes of a line:}
118
119 \newpage
120 \subsection{Plot}
121 \example{plota}{A plot uses a function to determine a series of points on a curve. It takes values going ``from''--``to''. The function is to be a lua function that takes the input scalar and returns a point. The whole curve is offset ``at'' a point:}
122
123 %\newpage
124 %\subsection{SuperEllipse}
125 %\example{superEllipse}{A ``super'' ellipse is just as an ellipse, but additionally has a strength factor ``n'' that ranges from diamond, to ellipse to rectangle:}
126
127 \newpage
128 \subsection{Polyline}
129 \example{polylinea}{A polyline is a list of points to be connected via straight lines. If the string ``cycle'' is given at the end, it cycles:}
130
131 \newpage
132 \subsection{Rect}
133 \example{recta}{Rectangles have various creation options. Also they provide a wide range of attributes of their points ``pnw'', ``pne'', ``psw'', ``pse'', ``pn'', ``pe'', ``ps'', ``pw'', ``pc'', ``height'', and ``width'':
134 }
135
136 \newpage
137 \section{Labels a.k.a Nodes}
138
139 Labels are created as nodes. Contrary to all other objects they do not need the ``draw'' command to be printed, but the ``put'' command. This is due any call to ``draw'' is turned into exactly one ``draw'' command to tikz and nodes in tikz are not using the ``draw'' command.
140
141 \example{nodea}{In it's simplest form a node is specified by it's position and text. The double square brackets are Lua's way to make string constants that may contain simple blackslashes:}
142
143 All constructors options of node are as follows; they correspond to the standard tikz options:
144 \begin{itemize}
145 \item above
146 \item anchor
147 \item align
148 \item at
149 \item below
150 \item color
151 \item draw
152 \item left
153 \item minimum\_height
154 \item node\_distance
155 \item name
156 \item right
157 \item rotate
158 \item text
159 \item text\_width
160 \end{itemize}
161 \newpage
162
163 \example{nodeb}{Another node example}
164
165 \newpage
166 \section{Styling}
167
168 Styling is applied to draw commands by specifying style options, luatikz autodetects the difference between objects and styles.
169
170 \example{stylea}{An example using arrows and dashes}
171
172 \newpage
173 \section{Shades}
174
175 The ``shade'' command works analogous to classical tikz.
176
177 \example{shadea}{For example a ball:}
178
179 Recognized shade options are:
180 \begin{itemize}
181 \item ball\_color
182 \item left\_color
183 \item lower\_left\_color
184 \item lower\_right\_color
185 \item opacity
186 \item right\_color
187 \item shading
188 \item upper\_left\_color
189 \item upper\_right\_color
190 \end{itemize}
191
192 \newpage
193 \section{Some larger examples}
194
195 \subsection{A radon projection}
196 \example{radon1}{A radon projection, calculating correct projection curves:}
197
198 \newpage
199 \subsection{A sierpiński fractal}
200 \example{sierpinski}{A sierpiński fractal. This one creates own temporary lua objects:}
201
202 \printindex
203
204 \end{document}