Dragon curve (triangles)

Dragon curve (triangles)

Source code

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
lsystem DragonCurveTriangles {
 
set symbols axiom = L;
set iterations = 8;
// normalize line length (result image will have always same size)
interpret R as lsystem Triangle(1, 2 ^ -(currentIteration / 2) * 256);
interpret L as lsystem Triangle(-1, 2 ^ -(currentIteration / 2) * 256);
interpret + as TurnLeft(90);
interpret - as TurnLeft(-90);
 
rewrite L to L + R +;
rewrite R to - L - R;
 
}
 
abstract lsystem Triangle(orientation = 1, length = 10) extends Polygons {
 
let sideLen = length * sqrt(2);
 
set symbols axiom = <(#0, 0) . + f(sideLen) . - f(sideLen) + . >;
 
interpret f as MoveForward;
interpret + as TurnLeft(45 * orientation);
interpret - as TurnLeft(-90 * orientation);
}
 
process all with SvgRenderer;