summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/luatikz/luatikz.tex
blob: d4bf734b1dd93f9d5b515d08b7466bd669547143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
\documentclass[a4paper,11pt]{ltxdoc}

\usepackage[utf8]{inputenc}
\usepackage{makeidx}\makeindex
\usepackage{luatextra}
\usepackage[margin=1in]{geometry}

\usepackage{fancyvrb}
\fvset{frame=single,numbers=left,numbersep=3pt,tabsize=4}

\usepackage{tikz}
\usetikzlibrary{math,backgrounds,calc,intersections,arrows.meta,external,decorations.pathreplacing,shadings}
\directlua{dofile('./luatikz.lua')}

\newcommand{\example}[2]
{
\par#2
\VerbatimInput{example/#1.lua}
{\centering
\begin{tikzpicture}[framed,scale=1]
\directlua{dofile('example/#1.lua')tikz.without()}
\end{tikzpicture}\par}
}

\newcommand{\examplecode}[2]
{
\bigskip\par\noindent #2
\VerbatimInput{example/#1.lua}
}


\title{luatikz}
\author{Axel Kittenberger}
\def\version{2.12.0}
\date{luatikz version \version}

\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}

\begin{document}

\maketitle

\section{Introduction}
Luatikz is a graphics library to draw tikz graphics using the Lua programming language.

\example{intro}
{Following code draws two lines by specifying begin and end points. First using intermediatery variables and the second line within a single codeline:}

Following \TeX{} wrapper can be used to compile the luatikz Lua code.
\VerbatimInput{example/wrapper.tex}

Luatikz obviously needs \LuaLaTeX{} to compile.

Note that 2D graphics is a vast topic, functionality to luatikz has been and will be added on a per need basis.

\section{Pointer math}

Mathematical operations are possible with points, adding them with each other or multiplying them with a scalar.
\example{spiral}{This example uses pointer math to create a spiral:}

\newpage
\section{Immutability}

In luatikz pointers like all objects are immutable. That means a object once created in memory can no longer be changed.
However the variable holding an object can be changed to another object with different attributes.

\examplecode{immute1}{Thus following example is invalid:}
\examplecode{immute2}{This on the other hand are two valid methods to change the value of p1}

\newpage
\section{luatikz objects}

\subsection{Bezier (quatratic)}
\example{bezier2}{A quadratic bezier curve is defined by it begin, end and a control point:}

\newpage
\subsection{Bezier (cubic)}
\example{bezier3a}{A cubic bezier curve is defined by it begin, end and two control points:}

\newpage
A cubic bezier has the functions pt and phit that return the point and angle ranging from 0..1 on the curve.
\example{bezier3b}{This example draw 10 normal lines onto the bezier curve:}

\newpage
\subsection{BLine}
\example{blinea}{A bline is defined by it's begin and it's end. Additionally to the standard line it is bend}

\newpage
\subsection{Circle}
\example{circle}{A circle is defined by it's center (``at'') and the circle ``radius'':}

\newpage
\subsection{Curve}
\example{curvea}{A curve is defined by a list of points:}

\newpage
\example{curveb}{A curve can cycle and has a changeable tension:}

\newpage
\subsection{Ellipse}
\example{ellipse}{An ellipse is difined by it's center (``at'') and a x- and yradius:}

\newpage
\subsection{EllipseArc}
\example{ellipseArc}{An ellipse arc is a an ellipse limited by it's ``from'' and ``to'' angle:}

\newpage
\subsection{Line}
\example{linea}{A line is defined by it's begin and it's end. There are two basic variants to define a line:}

\example{lineb}{You can use intersectLine() to find the intersection of a line with another. If there is none ``nil'' will be returned:}

\newpage
\example{linec}{A line can also be defined by it's starting point, angle and length:}

\example{lined}{``length'' and ``phi'' are attributes of a line:}

\newpage
\subsection{Plot}
\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:}

%\newpage
%\subsection{SuperEllipse}
%\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:}

\newpage
\subsection{Polyline}
\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:}

\newpage
\subsection{Rect}
\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'':
}

\newpage
\section{Labels a.k.a Nodes}

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.

\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:}

All constructors options of node are as follows; they correspond to the standard tikz options:
\begin{itemize}
	\item above
	\item anchor
	\item align
	\item at
	\item below
	\item color
	\item draw
	\item left
	\item minimum\_height
	\item node\_distance
	\item name
	\item right
	\item rotate
	\item text
	\item text\_width
\end{itemize}
\newpage

\example{nodeb}{Another node example}

\newpage
\section{Styling}

Styling is applied to draw commands by specifying style options, luatikz autodetects the difference between objects and styles.

\example{stylea}{An example using arrows and dashes}

\newpage
\section{Shades}

The ``shade'' command works analogous to classical tikz.

\example{shadea}{For example a ball:}

Recognized shade options are:
\begin{itemize}
	\item ball\_color
	\item left\_color
	\item lower\_left\_color
	\item lower\_right\_color
	\item opacity
	\item right\_color
	\item shading
	\item upper\_left\_color
	\item upper\_right\_color
\end{itemize}

\newpage
\section{Some larger examples}

\subsection{A radon projection}
\example{radon1}{A radon projection, calculating correct projection curves:}

\newpage
\subsection{A sierpiński fractal}
\example{sierpinski}{A sierpiński fractal. This one creates own temporary lua objects:}

\printindex

\end{document}