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