From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001
From: Norbert Preining <norbert@preining.info>
Date: Mon, 2 Sep 2019 13:46:59 +0900
Subject: Initial commit

---
 macros/latex/contrib/lapdf/turtle.tex | 90 +++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
 create mode 100644 macros/latex/contrib/lapdf/turtle.tex

(limited to 'macros/latex/contrib/lapdf/turtle.tex')

diff --git a/macros/latex/contrib/lapdf/turtle.tex b/macros/latex/contrib/lapdf/turtle.tex
new file mode 100644
index 0000000000..88c4720427
--- /dev/null
+++ b/macros/latex/contrib/lapdf/turtle.tex
@@ -0,0 +1,90 @@
+% ---------------------------------------------------------------------------
+% Draws turtle graphics in pdfTeX with Lapdf. The procedures are taken
+% from Abelson's introductory book for object logo on the Macintosh.
+% ---------------------------------------------------------------------------
+\input preamble.tex
+
+\newcount\i
+\newcount\pen
+\newdimen\a
+\newdimen\b
+\newdimen\t
+\newdimen\dir
+\newdimen\ax
+\newdimen\tx
+\newdimen\ty
+\newdimen\ux
+\newdimen\uy
+
+% ---------------------------------------------------------------------------
+% This is a simple Lapdf implementation of turtle graphics. The commands
+% are: Initturtle, Home, Penup, Pendown, Forward, Back, Right, Left.
+% ---------------------------------------------------------------------------
+\def\Home{\Moveto(0,0)}
+\def\Penup{\pen=0}
+\def\Pendown{\pen=1}
+
+\def\Initturtle{\Home \col=-1 \Dset(\dir,0) \Setwidth(0.02) \Pendown}
+
+\def\Forward(#1){\Dset(\ax,#1) \Rad(\Np\dir,\ty)
+ \Sin(\Np\ty,\tx) \Dmul(\tx,\ax) \Add(\ux,\tx)
+ \Cos(\Np\ty,\tx) \Dmul(\tx,\ax) \Add(\uy,\tx)
+ \ifnum\pen=0 \Moveto(\Np\ux,\Np\uy) \else \Lineto(\Np\ux,\Np\uy) \fi}
+
+\def\Back(#1){\Dset(\ax,#1) \Rad(\Np\dir,\ty)
+ \Sin(\Np\ty,\tx) \Dmul(\tx,\ax) \Sub(\ux,\tx)
+ \Cos(\Np\ty,\tx) \Dmul(\tx,\ax) \Add(\uy,\tx)
+ \ifnum\pen=0 \Moveto(\Np\ux,\Np\uy) \else \Lineto(\Np\ux,\Np\uy) \fi}
+
+\def\Right(#1){\Dset(\ax,#1) \Add(\dir,\ax) {\Dmod(\dir,360)}}
+\def\Left(#1){\Dset(\ax,#1) \Sub(\dir,\ax) {\Dmod(\dir,360)}}
+
+% ---------------------------------------------------------------------------
+% These are our own special drawing macros.
+% ---------------------------------------------------------------------------
+\def\Arcleft(#1,#2){\i=0 \Dset(\t,#1) \Dmul(\t,0.017453pt)
+ \Whilenum{\i<#2}{\Forward(\Np\t) \Left(1) \Add(\i,1)}}
+
+\def\Arcright(#1,#2){\i=0 \Dset(\t,#1) \Dmul(\t,0.017453pt)
+ \Whilenum{\i<#2}{\Forward(\Np\t) \Right(1) \Add(\i,1)}}
+
+\def\Fullcirc(#1){{\Arcright(#1,360)} \Stroke}
+
+\def\Square(#1){\i=0
+ \Whilenum{\i<4}{\Forward(#1) \Right(90) \Add(\i,1)} \Stroke \Home}
+
+\def\Rosette(#1,#2){\i=0 \Dset(\t,360) \Div(\t,#2)
+ \Whilenum{\i<#2}{\Nextcol(0,23) {\Square(#1)} \Right(\Np\t) \Add(\i,1)}}
+
+\def\Petal(#1){\Arcright(#1,60) \Right(120) \Arcright(#1,60)
+ \Right(120) \Stroke \Home}
+
+\def\Flower(#1){\i=0
+ \Whilenum{\i<6}{\Stepcol(0,23,4) {\Petal(#1)} \Right(60) \Add(\i,1)}}
+
+% ---------------------------------------------------------------------------
+\begin{document}
+\unitlength1.25cm
+
+\begin{center}
+{\Huge\bf{Turtle Graphics with \Lapdf}}
+\bigskip
+
+\begin{lapdf}(9,9)(-4.5,-4.5)
+ \Initturtle
+ \Rosette(3,24)
+ \Initturtle
+ \Penup
+ \Forward(4.243)
+ \Right(90)
+ \Pendown
+ \Dgray
+ \Fullcirc(4.243)
+\end{lapdf}
+
+\begin{lapdf}(9,9)(-4.5,-4.5)
+ \Initturtle
+ \Flower(5)
+\end{lapdf}
+\end{center}
+\end{document}
-- 
cgit v1.2.3

