# Gallery

This section of the book is a collection of Nell program examples that serve as a handy reference and quick start for creating a drawing you need to make now. To really understand a language you should read a lot of code examples to fully grasp its capabilities. All the program files can be found on the book's website.

#### Program: (koch.nll)

```; Creates a Koch curve whose generation is specified by
; the command line recursion level.
a = pi/3;
l = 0.025;
T1 : L(l) S(T1,1) L(l) T(a) L(l) S(T1,1) L(l) T(-2*a) L(l) S(T1,1)
L(l) T(a) L(l) S(T1,1) L(l);
```

#### Command line

`nell koch.nll T1 3 | nellsvg 6 2 in 0.02 1 > koch.svg`

#### Program: (hilbert.nll)

```; Creates a Hilbert curve whose generation is specified by
; the command line recursion level.
b = pi/2;
s = 0.2;
A : T(b) S(B,1) L(s) T(-b) S(A,1) L(s) S(A,1) T(-b) L(s) S(B,1) T(b);
B : T(-b) S(A,1) L(s) T(b) S(B,1) L(s) S(B,1) T(b) L(s) S(A,1) T(-b);
START : ;
```

#### Command line

`nell hilbert.nll START 5 | nellsvg 6.2 6.2 in 0.02 1 > hilbert.svg`

#### Program: (peano.nll)

```; Creates a Peano curve.
a = pi/4;
l = .0625;
T1 : S(T1,1) L(l) S(TP,1) S(T1,1) L(l) S(TN,1) S(T1,1) L(l) S(TN,1)
S(T1,1) L(l) S(TN,1) S(T1,1) L(l) S(TP,1) S(T1,1) L(l) S(TP,1)
S(T1,1) L(l) S(TP,1) S(T1,1) L(l) S(TN,1) S(T1,1);
TP : T(a) L(4*l) T(a);
TN : T(-a) L(4*l) T(-a);
START : P(0,12.0) ;
```

#### Command line

`nell peano.nll START 4 | nellsvg 25 24 cm 0.05 1 > peano.svg`

#### Program: (sierpinski.nll)

```; A Sierpinski triangle.
a = 2*pi/3;
l = 4;
T1 : A(l,l/2) S(T1,1) A(l,2*l) L(l) T(a) A(l,l/2) S(T1,1) A(l,2*l)
L(l) T(a) A(l,l/2) S(T1,1) A(l,2*l) L(l) T(a);
PIC : P(-l/2+2,-l/2+2) S(T1,1);
```

#### Command line

`nell sierpinski.nll PIC 6 | nellsvg 4 3.5 in 0.005 1 > sierpinski.svg`

#### Program: (cairo.nll)

```; Produces a tiling with irregular pentagons called a Cairo tiling.
n = 6;
l = 0.25;
a = pi/3;
b = pi/2;
d = sqrt(3)-1;
T1 : L(l*d) T(a) L(l) T(b) L(l) T(a) L(l) T(b) L(l) T(a);
T2 : L(l*d) T(-a) L(l) T(-b) L(l) T(-a) L(l) T(-b) L(l) T(-a);
T3 : L(l) T(b) L(l) T(a) L(l*d) T(a) L(l) T(b) L(l) T(a);
T4 : S(T1,1) S(T2,1) T(2*a) S(T3,1) T(-2*a) M(l*d) T(-a) S(T3,1) T(a);
T5 : S(T4,1) T(a) M(2*l) T(-a) S(T4,1);
T6 : [S(T5,1)] M(2*sqrt(3)*l);
T7 : [S(T6,n)] T(b) M(2*sqrt(3)*l) T(-b);
PIC : P(0.35,0.35) S(T7,n);
```

#### Command line

`nell cairo.nll PIC 10 | nellsvg 5.75 5.5 in 0.02 1 > cairo.svg`

#### Program: (tatami.nll)

```; Creates a tatami mat.
a = -pi/2;
l = 5;
n = 6;
i = 0;
T1 : L(2*l) T(a) L(l) T(a) L(2*l) T(a) L(l) T(a) M(2*l);
T2 : S(T1,i) M(l) T(a) S(T1,i) M(l) T(a) S(T1,i) M(l) T(a) S(T1,i)
M(l) T(a);
T3 : T(-pi/4) M(-l*sqrt(2)) T(pi/4) A(i,i+1) S(T2,1);
PIC : P(35,35) T(-pi/4) M(-l/sqrt(2)) T(pi/4) S(T3,n);
```

#### Command line

`nell tatami.nll PIC 5 | nellsvg 70 70 mm 0.2 1 > tatami.svg`

#### Program: (trellis1.nll)

```; Creates a trellis pattern.
l = 0;
lc1 = 0.7;
ac1 = 0.9;
lc2 = -0.7;
ac2 = -0.9;
y = 0.85;
h = sqrt(11)/10;
T1 : M(0.5) [T(pi/2) M(h) T(-pi/2) B(l,lc1,ac1,lc2,ac2)]
[T(-pi/2) M(h) T(pi/2) B(l,lc1,-ac1,lc2,-ac2)] M(0.5);
T2 : S(T1,1) C(0.4) C(0.6) E(0.4,0.1) E(0.1,0.4);
T3 : P(-0.75,y) S(T2,8) S(T1,1) A(y,y+1.5);
START : S(T3,6);
```

#### Command line

`nell trellis1.nll START 3 | nellsvg 7.5 9.25 in 0.02 1 > trellis1.svg`

#### Program: (spiral.nll)

```d = 0.025;
a = pi/8;
T1 : L(d) T(a);
ARM : S(T1,8) A(d,d+0.025);
START : P(2.55,2.55) <S(ARM,40)>;
```

#### Command line

`nell spiral.nll START 3 | nellsvg 5.1 5.1 in 0.02 1 > spiral.svg`

```; Draws a lady bug.
MOUTH : M(-0.4) R(0.3,0.1,0,-pi);
EYE : T(pi/2) M(0.2) C(0.05);
ANTENNA : T(pi/2) M(0.5) [Q(0.5,0.5,-pi/12) C(0.03)] T(-pi/2) M(0.1)
T(pi/2) [Q(0.5,0.5,-pi/12) C(0.03)];
HEAD : R(0.7,0.5,0,pi) R(0.7,0.3,0,-pi) [S(MOUTH,1) S(EYE,1)]
S(ANTENNA,1);
BODY : R(1.2,1,0,pi) R(1.2,0.35,0,-pi) R(1.2,0.7,0,pi);
FLEG : M(-1.2) T(-2*pi/3) Q(1,1,pi/3); front leg
MLEG : T(-pi/2) M(0.35) T(-pi/8) Q(0.6,0.62,pi/8); middle leg
BLEG : M(1.2) T(-pi/3) Q(1,1,-pi/3); back leg
FSPOTS : P(1.95,2.2) C(0.15) P(2.5,1.9) C(0.15) P(3.6,2.0) C(0.15)
P(3.0,2.5) C(0.15); foreground spots
BSPOTS : P(1.8,2.4) T(2*pi/5) R(0.08,0.08,pi,7*pi/8) P(2.5,2.85)
C(0.08) P(3.6,2.7) C(0.08) P(3.0,2.83)
C(0.1); background spots
START : P(1,2) [S(HEAD,1)] M(1.9) S(BODY,1) [S(FSPOTS,1)]
[S(BSPOTS,1)] [S(FLEG,1)] [S(MLEG,1)] [S(BLEG,1)];
```

#### Command line

`nell ladybug.nll START 3 | nellsvg 6 5 in 0.02 1 > ladybug.svg`

#### Program: (tess03.nll)

```; Creates a triangle tesselation.
a = 2*pi/3;
d = sqrt(2*(1-cos(a)));
T1 : L(d) T(5*a/4) L(1) T(a/2) L(1) T(a) L(1) T(a/2) L(1) T(3*a/4);
T2 : L(d) T(a) L(d);
PIC : P(1,0.65) S(T1,3) T(-a/4) M(1) T(a/4) S(T2,3);
```

#### Command line

`nell tess03.nll PIC 5 | nellsvg 3.7 3.25 cm 0.01 1 > tess03.svg`

#### Program: (tess05.nll)

```; Creates a pentagon tesselation.
a = 2*pi/5;
d1 = sqrt(2*(1-cos(a)));
d2 = sqrt(2*(1-cos(2*a)));
T1 : L(d1) T(7*a/4) L(1) T(3*a/2) L(1) T(a) L(1) T(3*a/2) L(1) T(a/4);
T2 : L(d2) T(9*a/4) L(1) T(a/2) L(1) T(2*a) L(1) T(a/2) L(1) T(3*a/4);
T3 : L(d1) T(a) L(d1);
PIC : P(1.4,1.3) S(T1,5) T(-3*a/4) M(1) T(5*a/4) S(T2,5) T(-a/4) M(1)
T(a/4) S(T3,5);
```

#### Command line

`nell tess05.nll PIC 5 | nellsvg 4 3.9 cm 0.01 1 > tess05.svg`

#### Program: (tess06.nll)

```; Creates a hexagon tesselation.
a = pi/3;
d1 = sqrt(2*(1-cos(a)));
d2 = sqrt(2*(1-cos(2*a)));
d3 = 2/sqrt(3);
T1 : L(d1) T(2*a) L(1) T(2*a) L(1) T(a) L(1) T(2*a) L(1);
T2 : L(d2) T(5*a/2) L(1) T(a) L(1) T(2*a) L(1) T(a) L(1) T(a/2);
T3 : L(d3) T(a) L(d3);
PIC : P(1.6,1.5) S(T1,6) T(-a) M(1) T(3*a/2) S(T2,6) T(-a/2) M(1)
T(a/2) S(T3,6);
```

#### Command line

`nell tess06.nll PIC 5 | nellsvg 4.2 4.7 cm 0.01 1 > tess06.svg`

#### Program: (tess08.nll)

```; Creates an octagon tesselation.
a = pi/4;
d1 = sqrt(2*(1-cos(a)));
d2 = sqrt(2*(1-cos(2*a)));
d3 = sqrt(2*(1-cos(3*a)));
T1 : L(d1) T(5*a/2) L(1) T(3*a) L(1) T(a) L(1) T(3*a) L(1) T(-a/2);
T2 : L(d2) T(3*a) L(1) T(2*a) L(1) T(2*a) L(1) T(2*a) L(1);
T3 : L(d3) T(7*a/2) L(1) T(a) L(1) T(3*a) L(1) T(a) L(1) T(a/2);
PIC : P(2.3,1.8) S(T1,8) T(-3*a/2) M(1) T(2*a) S(T2,8) T(-a) M(1)
T(3*a/2) S(T3,8);
```

#### Command line

`nell tess08.nll PIC 5 | nellsvg 5.4 5.4 cm 0.01 1 > tess08.svg`

#### Program: (tess10.nll)

```; Creates a decagon tesselation.
a = pi/5;
d1 = sqrt(2*(1-cos(a)));
d2 = sqrt(2*(1-cos(2*a)));
d3 = sqrt(2*(1-cos(3*a)));
d4 = sqrt(2*(1-cos(4*a)));
T1 : L(d1) T(3*a) L(1) T(4*a) L(1) T(a) L(1) T(4*a) L(1) T(-a);
T2 : L(d2) T(7*a/2) L(1) T(3*a) L(1) T(2*a) L(1) T(3*a) L(1) T(-a/2);
T3 : L(d3) T(4*a) L(1) T(2*a) L(1) T(3*a) L(1) T(2*a) L(1);
T4 : L(d4) T(9*a/2) L(1) T(a) L(1) T(4*a) L(1) T(a) L(1) T(a/2);
PIC : P(3,2.3) S(T1,10) T(-2*a) M(1) T(5*a/2) S(T2,10) T(-3*a/2) M(1)
T(2*a) S(T3,10) T(-a) M(1) T(3*a/2) S(T4,10);
```

#### Command line

`nell tess10.nll PIC 5 | nellsvg 6.6 6.5 cm 0.01 1 > tess10.svg`

#### Program: (tess16.nll)

```; Creates a 16-gon tesselation.
a = pi/8;
d1 = sqrt(2*(1-cos(a)));
d2 = sqrt(2*(1-cos(2*a)));
d3 = sqrt(2*(1-cos(3*a)));
d4 = sqrt(2*(1-cos(4*a)));
d5 = sqrt(2*(1-cos(5*a)));
d6 = sqrt(2*(1-cos(6*a)));
d7 = sqrt(2*(1-cos(7*a)));
T1 : L(d1) T(9*a/2) L(1) T(7*a) L(1) T(a) L(1) T(7*a) L(1) T(-5*a/2);
T2 : L(d2) T(5*a) L(1) T(6*a) L(1) T(2*a) L(1) T(6*a) L(1) T(-2*a);
T3 : L(d3) T(11*a/2) L(1) T(5*a) L(1) T(3*a) L(1) T(5*a) L(1) T(-3*a/2);
T4 : L(d4) T(6*a) L(1) T(4*a) L(1) T(4*a) L(1) T(4*a) L(1) T(-a);
T5 : L(d5) T(13*a/2) L(1) T(3*a) L(1) T(5*a) L(1) T(3*a) L(1) T(-a/2);
T6 : L(d6) T(7*a) L(1) T(2*a) L(1) T(6*a) L(1) T(2*a) L(1) T(0);
T7 : L(d7) T(15*a/2) L(1) T(a) L(1) T(7*a) L(1) T(a) L(1) T(a/2);
PIC : P(5.05,4.25) S(T1,16) T(-7*a/2) M(1) T(4*a) S(T2,16) T(-3*a)
M(1) T(7*a/2) S(T3,16) T(-5*a/2) M(1) T(3*a) S(T4,16) T(-2*a)
M(1) T(5*a/2) S(T5,16) T(-3*a/2) M(1) T(2*a) S(T6,16) T(-a)
M(1) T(3*a/2) S(T7,16);
```

#### Command line

`nell tess16.nll PIC 5 | nellsvg 10.5 10.5 cm 0.01 1 > tess16.svg`

#### Program: (tile005.nll)

```; Creates a tiling using octagons
a = pi/4;
d = 1;
d1 = 1 + sqrt(2);
d2 = 2 + sqrt(2);
T1 : L(1) T(a);
T2 :  T(a) M(d*d1) T(-a)  T(-a) M(d*d1)
T(a);
T3 : [S(T2,4)] T(2*a) M(d*d2) T(-2*a);
START : M(1) S(T3,4);
```

#### Command line

`nell tile005.nll START 10 | nellsvg 15 15 cm 0.05 1 > tile005.svg`

#### Program: (tile006.nll)

```; Creates a square in center alternating with squares and pentagons.
l = 10;
a = 2*pi/4;
b = 2*pi/5;
T1 : L(l) T(b) L(l) T(b) S(T2,1) L(l) T(b) S(T2,1) L(l) T(b) L(l) T(b);
T2 : L(l) T(-a) L(l) T(-a) S(T1,1) L(l) T(-a) L(l) T(-a);
PIC : P(100,100) T(a/2) M(-l/sqrt(2)) T(-a/2) S(T2,1) M(l) T(a)
S(T2,1) M(l) T(a) S(T2,1) M(l) T(a) S(T2,1) M(l) T(a)
P(100,100) C(8.7*l-2.5) C(8.7*l);
```

#### Command line

`nell tile006.nll PIC 7 | nellsvg 200 200 mm 0.5 1 > tile006.svg`

#### Program: (tile007.nll)

```; Creates pentagon in center alternating with rectangles and pentagons.
l = 5;
a = 2*pi/5;
b = 2*pi/5;
T1 : L(l) T(b) L(l) T(b) S(T2,1) L(l) T(b) S(T2,1) L(l) T(b) L(l) T(b);
T2 : L(l) T(-pi/2) L(2*l) T(-pi/2) S(T1,1) L(l) T(-pi/2) L(2*l)
T(-pi/2);
PIC : P(66,66) T(3*pi/10) M(-l/(2*cos(3*pi/10))) T(-3*pi/10) S(T2,1)
M(l) T(a) S(T2,1) M(l) T(a) S(T2,1) M(l) T(a) S(T2,1) M(l) T(a)
S(T2,1) M(l) T(a) P(66,66) C(13*l-2.5) C(13*l);
```

#### Command line

`nell tile007.nll PIC 7 | nellsvg 132 132 mm 0.5 1 > tile007.svg`

#### Program: (tile008.nll)

```; Creates hexagon in center alternating with rectangles and hexagons.
l = 5;
a = pi/3;
T1 : L(l) T(a) S(T2,1) L(l) T(a) S(T2,1) L(l) T(a) S(T2,1) L(l) T(a)
S(T2,1) L(l) T(a) L(l) T(a);
T2 : L(l) T(-pi/2) L(2*l) T(-pi/2) S(T1,1) L(l) T(-pi/2) L(2*l)
T(-pi/2);
PIC : P(55,62) T(a) M(-l) T(-a) S(T2,1) M(l) T(a) S(T2,1) M(l) T(a)
S(T2,1) M(l) T(a) S(T2,1) M(l) T(a) S(T2,1) M(l) T(a) S(T2,1)
M(l) T(a);
```

#### Command line

`nell tile008.nll PIC 6 | nellsvg 110 124 mm 0.5 1 > tile008.svg`

#### Program: (tile009.nll)

```; Creates a pattern with equilateral triangles.
l1 = 10;
l2 = 5;
a = 2*pi/3;
n = 2;
T1 : L(l1) T(a) L(l1) T(a) L(l1) T(a) M(l1+l2) S(T1,1);
T2 : [S(T1,1)] T(pi/3) M(l1+l2) T(-pi/3);
T3 : [S(T2,n)] T(pi/6);
PIC : P(38,38) S(T3,12) C(25) C(37); C(50);
```

#### Command line

`nell tile009.nll PIC 4 | nellsvg 76 76 mm 0.5 1 > tile009.svg`

#### Program: (tile011.nll)

```; Creates a pattern with hexagons.
l1 = 10;
l2 = 10;
a = pi/3;
n = 2;
T1 : L(l1) T(a) L(l1) T(a) L(l1) T(a) L(l1) T(a) L(l1) T(a) L(l1)
T(3*a/2) M(l1*sqrt(3)+l2) T(-a/2) S(T1,1);
T2 : [S(T1,1)] T(pi/2) M(l1*sqrt(3)+l2) T(-pi/2);
T3: [S(T2,n)] T(pi/6);
PIC: P(72,72) S(T3,12) C(70.0);
```

#### Command line

`nell tile011.nll PIC 4 | nellsvg 144 144 mm 0.5 1 > tile011.svg`

#### Program: (tile012.nll)

```; Creates a tiling using dodecagons.
; d = tile spacing
; d < 1 tiles overlap
; d = 1 exact tiling
; d > 1 tiles space apart
; d = 0.5 produces an interesting tiling
a = pi/6;
d = sqrt(3)-1;
d0 = 2+sqrt(3);
d1 = sqrt(3)*d0;
n = 6;
ah = pi/3;
dh = 0.5;
h1 = sqrt(2*(1-cos(ah)))/2;
h2 = sqrt(2*(1-cos(2*ah)))/2;
H1 : L(h1) T(2*ah) L(dh) T(2*ah) L(dh) T(ah) L(dh) T(2*ah) L(dh);
H2 : L(h2) T(5*ah/2) L(dh) T(ah) L(dh) T(2*ah) L(dh) T(ah) L(dh) T(ah/2);
HP : T(ah/2) S(H1,6) T(-ah) M(dh) T(3*ah/2) S(H2,6);
T0 : L(1) T(a);
T1 : S(T0,12) [T(pi/3) M(1) T(pi/6) M(dh) T(-pi/2) S(HP,1)];
T2 : S(T1,1) T(2*a) M(d*d0) T(-2*a) S(T1,1);
T3 : [S(T2,1)] M(d*d0);
T4 : [S(T3,n)] T(pi/2) M(d*d1) T(-pi/2);
PIC : S(T4,n/2);
```

#### Command line

`nell tile012.nll PIC 10 | nellsvg 16 16 cm 0.02 1 > tile012.svg`

```; Creates the circle of major triads.
a = pi/6;
l = 1;
T0 : C(l/4) M(l/2);
T1 : [ M(1/4) S(T0,3)] T(a);
PIC : P(2.3,2.3) C(3*l/4) C(5*l/4) C(7*l/4) C(9*l/4) S(T1,12);
```

#### Command line

`nell triadcirc.nll PIC 6 | nellsvg 4.6 4.6 in 0.01 1 > triadcirc.svg`

#### Program: (horns.nll)

```; horns.pen creates a pair of spiral horns composed of squares and
; triangles. The length of the horns depends on the value of n.
n = 30; n determines length of horns.
A = 5;
B = 12;
C = 13;
a = A;
b = B;
c = C;
s = b/c;
t1 = pi-angle(a,b,c);
t2 = pi-angle(b,c,a);
t3 = pi-angle(c,a,b);
t4 = -pi/2;
t5 = -2*pi/3;
L1 : L(c) T(t4) L(c) T(t4) L(c) T(t4) L(c) T(t4); left square
L2 : L(c) T(t3) L(a) T(t1) L(b) T(t2);            left triangle
L3 : S(L1,1) S(L2,1) A(a,s*a) A(b,s*b) A(c,s*c) T(3*pi/2-t2) M(c)
T(-pi/2);
R1 : L(c) T(t4) L(c) T(t4) L(c) T(t4) L(c) T(t4); right square
R2 : L(c) T(t2) L(b) T(t1) L(a) T(t3);            right triangle
R3 : S(R1,1) S(R2,1) A(a,s*a) A(b,s*b) A(c,s*c) T(pi-t3) M((a+b)/s)
T(-pi/2);
T1 : L(2*c) T(t5) L(2*c) T(t5) L(2*c) T(t5);
PIC : P(70,36) M(-c) [S(L3,n)] A(a,A) A(b,B) A(c,C) M(c) [S(R3,n)]
A(a,A) A(b,B) A(c,C) P(70-c,36-c) S(T1,1);
```

#### Command line

`nell horns.nll PIC 10 | nellsvg 140 70 mm 0.2 1 > horns.svg`

#### Program: (network.nll)

```; Creates a network of resistors.
a = pi/3;
b = 2*a;
l1 = 0.25;
l2 = l1/2;
V : T(-b) L(l1) T(b) L(l1);
R : L(l1) T(a) L(l2) S(V,2) T(-b) L(l1) T(b) L(l2) T(-a) L(l1);
SRC :  L(l1+l2) M(l1) C(l1) M(l1) L(l1+l2);
T : S(R,1) [T(-pi/2) S(R,1)];
START : P(l1,1.375) [S(T,3)] P(l1,.125) [S(R,3)] T(pi/2) S(SRC,1);
```

#### Command line

`nell network.nll START 3 | nellsvg 4.125 1.5 in 0.02 1 > network.svg`

#### Program: (prism.nll)

```; This shows the dispersion of light through an isosceles prism.
n0 = 1; air index of refraction
n1 = 1.6; prism index of refraction
phi = pi/3; apex angle
psi = (pi-phi)/2; base interior angle
a = (pi+phi)/2; base exterior angle
s = 2; length of the two equal sides
sb = 2*s*sin(phi/2); length of base
h = 1; ray entrance height above base max=s*sin(psi)
x = h/cos(phi/2);
t0 = pi/4; ray entrance angle, horizontal=phi/2
t1 = asin(n0*sin(t0)/n1);
t2 = phi-t1;
t3 = asin(n1*sin(t2)/n0);
l0 = (s-x)*sin(phi)/cos(t2);
PRISM : ;
CALC : A(n1,n1-0.1) A(t1,asin(n0*sin(t0)/n1)) A(t2,phi-t1)
A(t3,asin(n1*sin(t2)/n0)) A(l0,(s-x)*sin(phi)/cos(t2));
RAY : [T(t1-pi/2) L(l0) T(t2-t3) L(2)] S(CALC,1);
START : M(0.5) S(PRISM,1) T(psi) M(x) [T(pi/2+t0) L(1)] S(RAY,4);
```

#### Command line

`nell prism.nll START 3 | nellsvg 4 2 in 0.02 1 > prism.svg`

#### Program: (ball.nll)

```; This shows parallel rays of light being focused by a ball lens
n0 = 1; air index of refraction
n1 = 1.5; lens index of refraction
h = 0.9;
t0 = asin(h);
t1 = asin(n0*h/n1);
T1 : ;
T2 : A(h,h-0.1) A(t0,asin(h)) A(t1,asin(n0*h/n1)) [S(T1,1)];
T3 : A(h,h+0.1) A(t0,asin(h)) A(t1,asin(n0*h/n1)) [S(T1,1)];
START : P(0.25,1) [L(1.5) [T(pi/2) L(1)] C(1) [T(-pi/2) L(1)] L(1.5)]
S(T2,8) A(h,-0.9) S(T3,8);
```

#### Command line

`nell ball.nll START 3 | nellsvg 4 2 in 0.02 1 > ball.svg`

#### Program: (squarelat.nll)

```; Creates a nr x nc square lattice.
; nr = number of rows
; nc = number of columns
; d = lattice spacing
; r = node circle radius
nc = 6;
nr = 6;
d = 1.5;
r = 0.5;
a = pi/2;
T1 : C(r) M(r) L(d-2*r) M(r);
T2 : [S(T1,nc-1) C(r)] T(a) M(d) T(-a);
T3 : M(r) L(d-2*r) M(r);
T4 : [T(a) S(T3,nr-1)] M(d);
PIC : P(0.55,0.55) [S(T2,nr)] S(T4,nc-1) T(a) S(T3,nr-1);
```

#### Command line

`nell squarelat.nll PIC 6 | nellsvg 8.6 8.6 cm 0.03 1 > squarelat.svg`

#### Program: (squarepat0.nll)

```; Creates a simple square tiling.
; d = tile spacing
; d < 1 tiles overlap
; d = 1 exact tiling
; d > 1 tiles space apart
a = pi/2;
d = 1.1;
T1 : L(1) T(a) L(1) T(a) L(1) T(a) L(1) T(a) M(d);
T2 : [S(T1,8)] T(a) M(d) T(-a);
PIC : P(0.15,0.15) S(T2,8);
```

#### Command line

`nell squarepat0.nll PIC 6 | nellsvg 9 9 cm 0.03 1 > squarepat0.svg`

#### Program: (squarepat1.nll)

```; A square pattern of hexagons, circles and squares.
; d1, d2 = tile spacing
a = pi/2;
b = pi/3;
d1 = 1.5;
d2 = (1+sqrt(3))/2;
n = 4;
A : L(1) T(a) L(1) T(a) L(1) T(a) L(1) T(a);
B : L(1) T(b) L(1) T(b) L(1) T(b) L(1) T(b) L(1) T(b) L(1) T(b);
T2 : C(0.5) T(a/2) M(1/sqrt(2)) T(3*a/2) S(A,1);
T3 : M(1) T(2*b) S(B,1);
T4 : [S(T2,1)] M(d1) [S(T3,1)] M(d1);
T5 : [S(T3,1)] M(d1) [S(T2,1)] M(d1);
T6 : [S(T4,n)] T(a) M(d2) T(-a) [S(T5,n)] T(a) M(d2) T(-a);
PIC : P(1,1) S(T6,n);
```

#### Command line

`nell squarepat1.nll PIC 6 | nellsvg 12.5 11.5 cm 0.03 1 > squarepat1.svg`

#### Program: (squarepat2.nll)

```; Creates a square pattern of overlapping hexagons.
; d1, d2 = tile spacing
a = pi/2;
b = pi/3;
d1 = 1.5;
d2 = sqrt(3);
n = 4;
A : L(1) T(a) L(1) T(a) L(1) T(a) L(1) T(a);
B : L(1) T(b) L(1) T(b) L(1) T(b) L(1) T(b) L(1) T(b) L(1) T(b);
T2 : M(1) T(2*b) S(B,1);
T3 : M(1) T(2*b) S(B,1);
T4 : [S(T2,1)] M(d1) [S(T3,1)] M(d1);
T5 : [S(T3,1)] M(d1) [S(T2,1)] M(d1);
T6 : [S(T4,n)] T(a) M(d2) T(-a) [S(T5,n)] T(a) M(d2) T(-a);
PIC : P(1,1) S(T6,n);
```

#### Command line

`nell squarepat2.nll PIC 6 | nellsvg 12.5 14.1 cm 0.03 1 > squarepat2.svg`

#### Program: (pent0.nll)

```; Pentagonal star and pentagram inside pentagon.
a = 2*pi/5;
l = 5;
T1 : A(l,l/2) S(T1,1) A(l,2*l) L(l) T(a) A(l,l/2) S(T1,1) A(l,2*l)
L(l) T(a) A(l,l/2) S(T1,1) A(l,2*l) L(l) T(a) A(l,l/2) S(T1,1)
A(l,2*l) L(l) T(a) A(l,l/2) S(T1,1) A(l,2*l) L(l) T(a);
PIC : P(-l/2+4.5,-l/2+3.0) S(T1,1);
```

#### Command line

`nell pent0.nll PIC 2 | nellsvg 9 8.5 cm 0.05 1 > pent0.svg`

#### Program: (pent1.nll)

```; Produces a pattern with 31 pentagons.
a = 2*pi/5;
l = 0.5;
T0 : L(l) T(-a) L(l) T(-a) L(l) T(-a) L(l) T(-a) L(l) T(-a);
T1 : S(T2,1) L(l) T(a) S(T2,1) L(l) T(a) S(T2,1) L(l) T(a) S(T2,1)
L(l) T(a) S(T2,1) L(l) T(a);
T2 : L(l) T(-a) L(l) T(-a) S(T3,1) L(l) T(-a) S(T3,1) L(l) T(-a) L(l)
T(-a);
T3 : L(l) T(a) L(l) T(a) S(T0,1) L(l) T(a) S(T0,1) L(l) T(a) L(l)
T(a);
START : P(2.15,2.05) S(T1,1);
```

#### Command line

`nell pent1.nll START 4 | nellsvg 4.8 4.6 in 0.02 1 > pent1.svg`

#### Program: (pent2.nll)

```; Produces a pentagon pattern.
; Size of pattern is controlled by changing the maximum recursion
; level parameter in command line.
a = 2*pi/5;
l = 0.25;
T1 : P(3.7,3.5) S(T2,1) L(l) T(a) S(T2,1) L(l) T(a) S(T2,1) L(l) T(a)
S(T2,1) L(l) T(a) S(T2,1) L(l) T(a);
T2 : L(l) T(-a) L(l) T(-a) S(T3,1) L(l) T(-a) S(T4,1) L(l) T(-a) L(l)
T(-a);
T3 : L(l) T(a) L(l) T(a) L(l) T(-a) L(l) T(-a) S(T3,1) L(l) T(-a)
S(T4,1) L(l) T(-a) L(l) T(-a) L(l) T(a) L(l) T(-a) L(l) T(-a)
L(l) T(-a) S(T4,1) L(l) T(-a) L(l) T(-a) L(l) T(a) L(l) T(a);
T4 : L(l) T(a) L(l) T(a) L(l) T(a) L(l) T(-a) L(l) T(-a) L(l) T(-a)
S(T4,1) L(l) T(-a) L(l) T(-a) L(l) T(a) L(l) T(a);
```

#### Command line

`nell pent2.nll T1 6 | nellsvg 7.65 7.25 in 0.02 1 > pent2.svg`

#### Program: (pent3.nll)

```; Creates a pentagon wreath.
a = 2*pi/5;
r = 1;
s = 0.25;
d = s*(1+sqrt(5))/2;
T0 : ;
T1 :  M(s) T(a);
T2 : S(T0,1) S(T1,5);
T3 : S(T2,1) T(a/2) M(2*d+s);
START : P(2.65,0.4) S(T3,10);
```

#### Command line

`nell pent3.nll START 4 | nellsvg 4.3 4.1 in 0.02 1 > pent3.svg`

#### Program: (manda01.nll)

```; A mandala of triangles.
l1 = 8;
l2 = 13;
l3 = 13;
scale = 0.75;
n2 = 5;
a1 = angle(l3,l1,l2);
a2 = angle(l1,l2,l3);
a3 = angle(l2,l3,l1);
dm = l1*sin(a2/2)/(cos(a1/2)*sin(a2/2)+sin(a1/2)*cos(a2/2));
a = 2*pi/n2;
T1 : L(l1) T(pi-a2) L(l2) T(pi-a3) L(l3) T(pi-a1);
PIC1 : S(T1,1) T(a);
PIC3 : [T(a1/2) M(dm) T(-a1/2) S(PIC1,n2)] T(a);
PIC4 : A(l1,scale*l1) A(l2,scale*l2) A(l3,scale*l3) S(PIC3,n2);
PIC5 : P(14,14) S(PIC1,n2) C(l3)  S(PIC4,1);
```

#### Command line

`nell manda01.nll PIC5 3 | nellsvg 28 28 mm 0.2 1 > manda01.svg`

#### Program: (manda03.nll)

```; A template for creating mandalas with rectangles.
L1 = 13; L1,L2 = sides of rectangle.
L2 = 8; Note: Scaling the same rectangle can make different mandalas.
d = 2;  d = spacing between concentric rectangles
n1 = 1; n1 = number of concentric rectangles
n2 = 10; n2 = number of copies going around the circle
; For scripting, everything below here remains unchanged.
l1 = L1;
l2 = L2;
ai = pi/2;
dm = d*sqrt(2);
a = 2*pi/n2;
T1 : L(l1) T(ai) L(l2) T(ai) L(l1) T(ai) L(l2) T(ai);
PIC2 : S(T1,1) T(ai/2) M(dm) T(-ai/2) A(l1,l1-2*d) A(l2,l2-2*d);
PIC3 : [S(PIC2,n1)] T(a) A(l1,L1) A(l2,L2);
PIC4 : P(20,20) [S(PIC3,n2)] C(sqrt(2)*l1);
```

#### Command line

`nell manda03.nll PIC4 10 | nellsvg 40 40 mm 0.2 1 > manda03.svg`

#### Program: (manda05.nll)

```; Creates a mandala of equilateral triangles.
a = pi/3;
d = 1.0;
len = 5;
dlen = d/(1.5*tan(a/2));
dm = d/(2*sin(a/2));
T1 : ;
PIC2 : S(T1,1)  A(len,len-dlen) T(a/2) M(dm) T(-a/2);
PIC3 : [S(PIC2,4)] T(a) A(len,5);
PIC4 : P(5,5) [S(PIC3,6)] C(5);
```

#### Command line

`nell manda05.nll PIC4 10 | nellsvg 11 11 cm 0.05 1 > manda05.svg`

#### Program: (manda07.nll)

```; A mandala of triangles with the largest inscribed circle
; inside each triangle.
L1 = 10;
L2 = 10;
L3 = 10;
d = 2;
n1 = 2;
n2 = 5;
l1 = L1;
l2 = L2;
l3 = L3;
a1 = angle(l3,l1,l2);
a2 = angle(l1,l2,l3);
a3 = angle(l2,l3,l1);
d1 = d/tan(a1/2);
d2 = d/tan(a2/2);
d3 = d/tan(a3/2);
dm = d/sin(a1/2);
cm = sin(a2/2)/(cos(a1/2)*sin(a2/2)+sin(a1/2)*cos(a2/2));
a = 2*pi/n2;
tri : L(l1) T(pi-a2) L(l2) T(pi-a3) L(l3) T(pi-a1);
circ : T(a1/2) M(l1*cm) C(sqrt((-l1+l2+l3)*(l1-l2+l3)*(l1+l2-l3)/
(l1+l2+l3))/2) T(-a1/2);
PIC2 : S(tri,1) [S(circ,1)] T(a1/2) M(dm) T(-a1/2) A(l1,l1-d1-d2)
A(l2,l2-d2-d3) A(l3,l3-d1-d3);
PIC3 : [S(PIC2,n1)] T(a) A(l1,L1) A(l2,L2) A(l3,L3);
PIC4 : P(11,11) [S(PIC3,n2)] C(L3);
```

#### Command line

`nell manda07.nll PIC4 3 | nellsvg 22 22 mm 0.2 1 > manda07.svg`

#### Program: (manda09.nll)

```; A template for creating mandalas with triangles.
L1 = 10; L1,L2,L3 = sides of triangles.
L2 = 10; Note: Scaling the same triangle can make different mandalas.
L3 = 10;
d = 2;  d = spacing between concentric triangles
n1 = 1; n1 = number of concentric triangles
n2 = 6; n2 = number of copies going around the circle
l1 = L1;
l2 = L2;
l3 = L3;
a1 = pi/3;
d1 = d/tan(a1/2);
dm = d/sin(a1/2);
a = 2*pi/n2;
T1 : L(l1) T(pi-a1) S(S1,1) L(l2) T(pi-a1) L(l3) T(pi-a1);
S1 : L(l2) T(-pi/2) L(l2) T(-pi/2) S(T1,1) L(l2) T(-pi/2) L(l2)
T(-pi/2);
PIC2 : S(T1,1) T(a1/2) M(dm) T(-a1/2) A(l1,l1-2*d1) A(l2,l2-2*d1)
A(l3,l3-2*d1);
PIC3 : [S(PIC2,n1)] T(a) A(l1,L1) A(l2,L2) A(l3,L3);
PIC4 : P(40,40) [S(PIC3,n2)];
```

#### Command line

`nell manda09.nll PIC4 9 | nellsvg 80 80 mm 0.2 1 > manda09.svg`

#### Program: (manda11.nll)

```; A template for creating mandalas with triangles.
L1 = 10; L1,L2,L3 = sides of triangles.
L2 = 10; Note: Scaling the same triangle can make different mandalas.
L3 = 10;
d = 2; d = spacing between concentric triangles
n1 = 1; n1 = number of concentric triangles
n2 = 1; n2 = number of copies going around the circle
l1 = L1;
l2 = L2;
l3 = L3;
a1 = pi/3;
d1 = d/tan(a1/2);
dm = d/sin(a1/2);
a = 2*pi/n2;
T1 : L(l1) T(pi-a1) S(S1,1) L(l2) T(pi-a1) S(S1,1) L(l3) T(pi-a1)
S(S1,1);
S1 : L(l2) T(-pi/2) L(l2) T(-pi/2) S(T1,1) L(l2) T(-pi/2) L(l2)
T(-pi/2);
PIC2 : S(T1,1) T(a1/2) M(dm) T(-a1/2) A(l1,l1-2*d1) A(l2,l2-2*d1)
A(l3,l3-2*d1);
PIC3 : [S(PIC2,n1)] T(a) A(l1,L1) A(l2,L2) A(l3,L3);
PIC4 : P(62,65) [S(PIC3,n2)] T(a1/2) M(l1/(2*cos(a1/2))) T(-a1/2)
C(60.0) C(65.0);
```

#### Command line

`nell manda11.nll PIC4 11 | nellsvg 135 135 mm 0.2 1 > manda11.svg`

#### Program: (manda13.nll)

```; Has intertwined production rules (T1 and T2), and produces
; a mandala of triangles, where the most important parameter is the
; maximum substitution level, given on the command line, with a
; higher number making longer mandala arms.
n2 = 10;
a = 2*pi/n2;
l1 = 8;
l2 = 13;
l3 = 13;
k1 = 5;
k2 = 8;
k3 = 8;
a1 = angle(l3,l1,l2);
a2 = angle(l1,l2,l3);
a3 = angle(l2,l3,l1);
b1 = angle(k3,k1,k2);
b2 = angle(k1,k2,k3);
b3 = angle(k2,k3,k1);
T1 : L(l1) T(pi-a2) S(T2,1) L(l2) T(pi-a3) L(l3) T(pi-a1);
T2 : L(k1) T(b2-pi) S(T1,1) L(k2) T(b3-pi) L(k3) T(b1-pi);
PIC1 : [S(T1,1)] T(a);
PIC2 : P(32,32) S(PIC1,n2);
```

#### Command line

`nell manda13.nll PIC2 7 | nellsvg 65 65 mm 0.2 1 > manda13.svg`

#### Program: (manda15.nll)

```; Creates a mandala with pentagonal symmetry.
a = 2*pi/5;
b1 = pi - angle(3, 10, 12);
b2 = pi - angle(10, 12, 3);
b3 = pi - angle(12, 3, 10);
c1 = pi - angle(3, 8, 10);
c2 = pi - angle(8, 10, 3);
c3 = pi - angle(10, 3, 8);
d1 = pi - angle(3, 6, 8);
d2 = pi - angle(6, 8, 3);
d3 = pi - angle(8, 3, 6);
e1 = pi - angle(3, 4, 6);
e2 = pi - angle(4, 6, 3);
e3 = pi - angle(6, 3, 4);
f1 = pi - angle(3, 2, 4);
f2 = pi - angle(2, 4, 3);
f3 = pi - angle(4, 3, 2);
stem = 3.9; stem defines the distance btw the lobes of the mandala
r = 0.5; r is a scale factor
R1 : T(-b3) L(r*3) T(-b1) [S(R2,1)] L(r*10);
R2 : T(pi-c3) L(r*3) T(-c1) [S(R3,1)] L(r*8);
R3 : T(pi-d3) L(r*3) T(-d1) [S(R4,1)] L(r*6);
R4 : T(pi-e3) L(r*3) T(-e1) [S(R5,1)] L(r*4);
R5 : T(pi-f3) L(r*3) T(-f1) L(r*2);
L1 : T(b3) L(r*3) T(b1) [S(L2,1)] L(r*10);
L2 : T(c3-pi) L(r*3) T(c1) [S(L3,1)] L(r*8);
L3 : T(d3-pi) L(r*3) T(d1) [S(L4,1)] L(r*6);
L4 : T(e3-pi) L(r*3) T(e1) [S(L5,1)] L(r*4);
L5 : T(f3-pi) L(r*3) T(f1) L(r*2);
LEAF: L(r*12) [S(R1,1)] [S(L1,1)];
ALL: P(8,6.5) T(a/4) [L(r*stem) S(LEAF,1)] T(a) [L(r*stem) S(LEAF,1)]
T(a) [L(r*stem) S(LEAF,1)] T(a) [L(r*stem) S(LEAF,1)] T(a)
[L(r*stem) S(LEAF,1)];
```

#### Command line

`nell manda15.nll ALL 10 | nellsvg 16 14.5 cm 0.05 1 > manda15.svg`

#### Program: (manda17.nll)

```; Creates a mandala of square symmetry.
a = 2*pi/5;
b1 = pi - angle(3, 10, 12);
b2 = pi - angle(10, 12, 3);
b3 = pi - angle(12, 3, 10);
c1 = pi - angle(3, 8, 10);
c2 = pi - angle(8, 10, 3);
c3 = pi - angle(10, 3, 8);
d1 = pi - angle(3, 6, 8);
d2 = pi - angle(6, 8, 3);
d3 = pi - angle(8, 3, 6);
e1 = pi - angle(3, 4, 6);
e2 = pi - angle(4, 6, 3);
e3 = pi - angle(6, 3, 4);
f1 = pi - angle(3, 2, 4);
f2 = pi - angle(2, 4, 3);
f3 = pi - angle(4, 3, 2);
stem = 3.9; stem defines the distance btw the lobes of the mandala
r = 0.25; scale factor
R1 : T(-b3) L(r*3) T(-b1) [S(R2,1)] L(r*10);
R2 : T(pi-c3) L(r*3) T(-c1) [S(R3,1)] L(r*8);
R3 : T(pi-d3) L(r*3) T(-d1) [S(R4,1)] L(r*6);
R4 : T(pi-e3) L(r*3) T(-e1) [S(R5,1)] L(r*4);
R5 : T(pi-f3) L(r*3) T(-f1) L(r*2);
L1 : T(b3) L(r*3) T(b1) [S(L2,1)] L(r*10);
L2 : T(c3-pi) L(r*3) T(c1) [S(L3,1)] L(r*8);
L3 : T(d3-pi) L(r*3) T(d1) [S(L4,1)] L(r*6);
L4 : T(e3-pi) L(r*3) T(e1) [S(L5,1)] L(r*4);
L5 : T(f3-pi) L(r*3) T(f1) L(r*2);
CORNERBL : P(1,1) [L(r*12) S(R1,1)] [T(pi/2) L(r*12) S(L1,1)];
CORNERBR : P(10,1) [T(pi) L(r*12) S(L1,1)] [T(pi/2) L(r*12) S(R1,1)];
CORNERTL : P(1,10) [T(-pi/2) L(r*12) S(R1,1)] [T(0) L(r*12) S(L1,1)];
CORNERTR : P(10,10) [T(pi) L(r*12) S(R1,1)] [T(-pi/2) L(r*12)
S(L1,1)];
SQUARE : S(CORNERBL,1) S(CORNERBR,1) S(CORNERTL,1) S(CORNERTR,1);
CENTRAL : T(pi/2) [S(R1,1)] [S(L1,1)];
CIRCLES : P(5.5,5.5) C(r*1) C(r*19) P(r*9+5.5,5.5) C(r*2)
P(r*-9+5.5,5.5) C(r*2) P(5.5,r*9+5.5) C(r*2) P(5.5,r*-9+5.5)
C(r*2) P(5.5,r*16+5.5) C(r*3) P(5.5,r*-16+5.5) C(r*3)
P(r*16+5.5,5.5) C(r*3) P(r*-16+5.5,5.5) C(r*3);
TOTAL : P(5.5,5.5) [S(SQUARE,1)] [T(pi/4) S(CENTRAL,4)] S(CIRCLES,1);
```

#### Command line

`nell manda17.nll TOTAL 10 | nellsvg 11 11 cm 0.05 1 > manda17.svg`

#### Program: (manda19.nll)

```; A template for creating mandalas with triangles.
L1 = 10; L1,L2,L3 = sides of triangles.
L2 = 10; Note: Scaling the same triangle can make different mandalas.
L3 = 10;
d = 2.5; d = spacing between concentric triangles
n1 = 4; n1 = number of concentric triangles
n2 = 6; n2 = number of copies going around the circle
l1 = L1;
l2 = L2;
l3 = L3;
a1 = angle(l3,l1,l2);
a2 = angle(l1,l2,l3);
a3 = angle(l2,l3,l1);
d1 = d/tan(a1/2);
d2 = d/tan(a2/2);
d3 = d/tan(a3/2);
dm = d/sin(a1/2);
a = 2*pi/n2;
T1 : L(l1) T(pi-a2) L(l2) T(pi-a3) L(l3) T(pi-a1);
PIC2 : S(T1,1) T(a1/2) M(dm) T(-a1/2) A(l1,l1-d1-d2) A(l2,l2-d2-d3)
A(l3,l3-d1-d3);
PIC3 : [S(PIC2,n1)] T(a) A(l1,L1) A(l2,L2) A(l3,L3);
PIC4 : P(15,15) [S(PIC3,n2)] C(L3) C(1.5*L3);
```

#### Command line

`nell manda19.nll PIC4 10 | nellsvg 30 30 mm 0.1 1 > manda19.svg`

#### Program: (lonestar.nll)

```; Produces a star-like figure using paralelograms.
; d = tile spacing
; d < 1 tiles overlap
; d = 1 exact tiling
; d > 1 tiles space apart
a = pi/4;
l = 0.4;
d = 1.25*l;
n = 4;
T1 : L(l) T(a) L(l) T(3*a) L(l) T(a) L(l) T(3*a) M(d);
T2 : [S(T1,n)] T(a) M(d) T(-a);
T3 : [S(T2,n)] T(a);
T4 : P(3.25,3.25) S(T3,8);
```

#### Command line

`nell lonestar.nll T4 10 | nellsvg 6.5 6.5 in 0.02 1 > lonestar.svg`

#### Program: (cross.nll)

```; Creates a cross with an octagon at center.
s = 1; "s" makes tips longer with increase.
r = s; "r" makes junction side wider with increase.
a = 2*pi/5; "a" makes tips more pointy with increase.
t1 = 3*s; "t1" makes 3 arms longer with increase.
; b1 is angle of side near junction.
b1 = acos((s/t1)*cos(a/2)-r/(2*t1));
c1 = pi-a/2-b1; "c1" is angle of side near point
t2 = 5*s; t2,b2,c2 are long arm versions of t1,b1,c1
b2 = acos((s/t2)*cos(a/2)-r/(2*t2));
c2 = pi-a/2-b2;
; T1 is the 3 short arms, T2 is longer arm.
T1 : L(r) T(-b1) L(t1) T(-c1) L(s) T(-a) L(s) T(-c1) L(t1) T(-b1);
T2 : L(r) T(-b2) L(t2) T(-c2) L(s) T(-a) L(s) T(-c2) L(t2) T(-b2);
T3 : L(s) T(pi/4); T3 is a side of octagon
T4 : S(T3,8); T4 is octagon at junction
; T5 makes longer arm, T6 makes shorter arms.
T5 : M((s-r)/2) S(T2,1) M((s+r)/2) T(pi/4) M(s) T(pi/4);
T6 : M((s-r)/2) S(T1,1) M((s+r)/2) T(pi/4) M(s) T(pi/4);
PIC : P(4.5,5.8) S(T4,1) S(T5,1) S(T6,3);
```

#### Command line

`nell cross.nll PIC 6 | nellsvg 10 12 cm 0.05 1 > cross.svg`