Code Trip
  • Blog
  • Archive
  • Projects
  • Portfolio
  • CV

Year 3, Semester 2 - Procedural Methods: Catalogue of 30 L-systems drawable with turtle graphics

21/8/2015

0 Comments

 
January 2015 - May 2015
Download the full procedural methods project here.
For an overview of what this is see my previous post.

Gallery

Defining L-systems for turtles

The turtle I created for this project understands 7 kinds of commands:
COMMAND_DRAW

COMMAND_MOVE

COMMAND_TURN_LEFT
COMMAND_TURN_RIGHT
COMMAND_PUSH

COMMAND_POP

COMMAND_NOTHING
Move forward in the direction currently facing while drawing to the texture.
Move forward in the direction currently facing, without drawing.
Turn left (anticlockwise) by an angle in degrees.
Turn right (clockwise) by an angle in degrees.
Remember the current orientation and position and push them onto a stack.
Revert to the last remembered position and orientation and remove it from the stack.
Do nothing (useful for symbols which should not be interpreted by the turtle but which are used to control the evolution of the curve).
As such, all 30 of these L-systems can be described by a sequence of these commands. A typical description of an L-system looks something like this:

Rules: F → F-F++F-F
Constants: + -
Meanings: F → draw 80%, + → turn right 60°, - → turn left 60°
Axiom: F++F++F
Initial heading: 0
Initial position: x = 0.1, y = 0.75
Scaling factor: 1/3 (exact)

Rules are the set of characters and their productions that comprise the L-system itself. When iterating over the L-system, each character in the current string will be replaced by its production according to these rules (in this example 'F' is replaced with
"F-F++F-F"). Note that every character used in an L-system must define a rule and a meaning. In this example the '+' rule has production "+" and the '-' rule has production "-", i.e. they are constants in the system and are described as such for brevity. Iterating over them in the system simply replaces them with themselves. Note that the → and , characters are never part of the L-system definitions, they are simply part of the layout of this information.

The meaning of a character is the command the turtle should perform when it encounters that character in its command string. Move and draw commands are given in terms of the percentage of the canvas to cover so that they are independent of canvas size. The turn left and right commands are given in degrees for ease of understanding.

The axiom is the starting point of the command string (the 0th iteration of the L-system). The initial heading describes what direction the turtle should be facing at the start of the first drawing (in degrees), where 0 is right and 90 is down. The initial position is the point on the canvas the turtle should begin the first drawing, given as percentages across (0 is the left edge, 1 the right) and up (0 is bottom edge, 1 is top) the canvas.

Finally the scaling factor describes how to scale the move and draw commands in order to fit the drawing on the same size canvas, as each iteration would otherwise result in ever-larger images. The scale s at the nth iteration is based on the scaling factor f such that s = f^n . An example of how this works is given in my previous post in the section "A problem of scale". The scaling factor also includes some combination of the following notes:
  • exact: The L-system will cover the exact same amount of canvas at any iteration.
  • diminishing expansion: The L-system expands with each iteration to fill a certain area, then covers exactly that area with each further iteration.
  • rotates: The L-system rotates with each iteration, usually about the initial position.
  • rough: The scaling factor is incorrect and the L-system will eventually shrink to nothing or expand over the boundaries of the canvas.
Above is a video showing several iterations and animations of the turtle at work for each of the L-systems. The video description includes time-stamped links to each one.

01 - Koch Snowflake

Picture
Rules: F → F-F++F-F
Constants: + -
Meanings: F → draw 80%,
+ → turn right 60°, - → turn left 60°
Axiom: F++F++F
Initial heading: 0
Initial position: x = 0.1, y = 0.75
Scaling factor: 1/3 (exact)

02 - Koch Antisnowflake

Picture
Rules: F → F+F--F+F
Constants: + -
Meanings: F → draw 80%,
+ → turn left 60°, - → turn right 60°
Axiom: F++F++F
Initial heading: 0
Initial position: x = 0.1, y = 0.15
Scaling factor: 1/3 (exact)

03 - Quadratic Koch A

Picture
Rules: F → F+F-F-FF+F+F-F
Constants: + -
Meanings: F → draw 50%,
+ → turn left 90°, - → turn right 90°
Axiom: F-F-F-F
Initial heading: 0
Initial position: x = 0.25, y = 0.75
Scaling factor: 0.25 (exact)

04 - Quadratic Koch B

Picture
Rules: F → FF-F-F-F-F-F+F
Constants: + -
Meanings: F → draw 35%,
+ → turn left 90°, - → turn right 90°
Axiom: F-F-F-F
Initial heading: 0
Initial position: x = 0.6, y = 0.7
Scaling factor: 1/3 (diminishing expansion, rotates)

05 - Vicsek Fractal (Outline)

Picture
Rules: F → F+F-F-F+F
Constants: + -
Meanings: F → draw 80%,
+ → turn left 90°, - → turn right 90°
Axiom: F+F+F+F
Initial heading: 0
Initial position: x = 0.1, y = 0.1
Scaling factor: 1/3 (exact)

06 - Sierpiński Arrowhead

Picture
Rules: A → A+B+A-B-A-B-A+B+A,
B → B-A-B+A+B+A+B-A-B
Constants: + -
Meanings: A → draw 80%, B → draw 80%, + → turn left 60°, - → turn right 60°
Axiom: A
Initial heading: 0
Initial position: x = 0.1, y = 0.1
Scaling factor: 0.25 (exact)
The Sierpiński Arrowhead can be done with the simpler rules A → B-A-B and B → A+B+A, but that system flips with each iteration. Here we're essentially doing 2 iterations of the simple system with each iteration of the more complex one, so that the position is constant.

07 - Sierpiński Triangle

Picture
Rules: X → ++FXF--FXF--FXF++, F → FF
Constants: + -
Meanings: X → do nothing, F → draw 40%, + → turn left 60°, - → turn right 60°
Axiom: FXF++FF++FF
Initial heading: 0
Initial position: x = 0.1, y = 0.1
Scaling factor: 0.5 (exact)

08 - Sierpiński Curve

Picture
Rules: X → XF-F+F-XF+F+XF-F+F-X
Constants: F + -
Meanings: X → do nothing, F → draw 20%, + → turn left 90°, - → turn right 90°
Axiom: F+XF+F+XF
Initial heading: 0
Initial position: x = 0.5, y = 0.1
Scaling factor: 0.5 (diminishing expansion)

09 - Sierpiński Carpet

Picture
Rules: F → F+F-F-FF-F-F-MF, M → MMM
Constants: + -
Meanings: F → draw 80%, M → move 80%, + → turn left 90°, - → turn right 90°
Axiom: F
Initial heading: 0
Initial position: x = 0.1, y = 0.5
Scaling factor: 1/3 (exact)

10 - Dragon Curve

Picture
Rules: X → X-YF-, Y → +FX+Y
Constants: F + -
Meanings: X → do nothing,
Y → do nothing, F → draw 30%,
+ → turn left 90°, - → turn right 90°
Axiom: FX
Initial heading: 0
Initial position: x = 0.5, y = 0.5
Scaling factor: 0.715 (rough, rotates)

11 - Terdragon

Picture
Rules: F → F-F+F
Constants: + -
Meanings: F → draw 40%,
+ → turn left 120°, - → turn right 120°
Axiom: F
Initial heading: 0
Initial position: x = 0.5, y = 0.5
Scaling factor: 0.58 (rough, rotates)

12 - Lévy C Curve

Picture
Rules: F → -F++F-
Constants: + -
Meanings: F →  draw 46%,
+ → turn left 45°, - → turn right 45°
Axiom: F
Initial heading: 0
Initial position: x = 0.25, y = 0.6
Scaling factor: (√2)/2 (exact)

13 - Hilbert Curve

Picture
Rules: X → +YF-XFX-FY+,
Y → -XF+YFY+FX-
Constants: F + -
Meanings: X → do nothing,
Y → do nothing, F → draw 80%,
+ → turn left 90°, - → turn right 90°
Axiom: X
Initial heading: 90
Initial position: x = 0.1, y = 0.9
Scaling factor: 0.5 (diminishing expansion)

Note that the 0th iteration is blank.

14 - Hilbert II Curve

Picture
Rules: X → XFYFX+F+YFXFY-F-XFYFX,
Y → YFXFY-F-XFYFX+F+YFXFY
Constants: F + -
Meanings: X → do nothing,
Y → do nothing, F → draw 80%,
+ → turn left 90°, - → turn right 90°
Axiom: X
Initial heading: 90
Initial position: x = 0.1, y = 0.9
Scaling factor: 1/3 (diminishing expansion)

Note that the 0th iteration is blank.

15 - Square Space-Filling Tree

Picture
Rules: F → FF[+F][F][-F]
Constants: + - [ ]
Meanings: F → draw 25%,
+ → turn left 90°, - → turn right 90°,
[ → push, ] → pop
Axiom: [F]-[F]-[F]-[F]
Initial heading: 270
Initial position: x = 0.5, y = 0.5
Scaling factor: 0.5 (exact)

I worked this one out myself, it could possibly be improved.

16 - Triangle Space-Filling Tree

Picture
Rules:
F → G[M|X][|M|X]G[+X+F][F][-X-F],
G → GG, M → MM, X → [F]
Constants: + - | [ ]
Meanings: F → draw 25%, G → draw 25%, M → move 25%, X → do nothing,
+ → turn left 60°, - → turn right 60°,
| → turn 180°, [ → push, ] → pop
Axiom: [F]-X-[F]-X-[F]-X
Initial heading: 270
Initial position: x = 0.5, y = 0.4
Scaling factor: 0.5 (exact)
I worked this one out myself and I'm certain it could be vastly simplified. I chose to have a special command for turning 180° rather than using +++ or --- to reduce the size of the string this system generates.

17 - Gosper Curve

Picture
Rules: A → A-B--B+A++AA+B-,
B → +A-BB--B-A++A+B
Constants: + -
Meanings: A → draw 80%, B → draw 80%, + → turn left 60°, - → turn right 60°
Axiom: A
Initial heading: 270
Initial position: x = 0.2, y = 0.45
Scaling factor: 1/3 (diminishing shrink, rotates)

18 - Quadratic Gosper

Picture
Rules: X → XFX-YF-YF+FX+FX-YF-YFFX+YF+FXFXYF-FX+YF+FXFX+YF-FXYF-YF-FX+FX+YFYF-,
Y → +FXFX-YF-YF+FX+FXYF+FX-YFYF-FX-YF+FXYFYF-FX-YFFX+FX+YF-YF-FX+FX+YFY
Constants: F + -
Meanings: X → do nothing,
Y → do nothing, F → draw 80%,
+ → turn left 90°, - → turn right 90°
Axiom: -YF
Initial heading: 0
Initial position: x = 0.1, y = 0.9
Scaling factor: 1/5 (exact)

19 - Pentagonal

Picture
Rules: F → F++F++F|F-F++F
Constants: + - |
Meanings: F → draw 50%,
+ → turn left 36°, - → turn right 36°,
| → turn 180°
Axiom: F++F++F++F++F
Initial heading: 0
Initial position: x = 0.25, y = 0.1
Scaling factor: 2/(3 + √5) (exact)

I chose to have a special command for turning 180° rather than using +++++ or
----- to reduce the size of the string this system generates.

20 - Penrose Tiling

Picture
Rules:
M → OA++PA----NA[-OA----MA]++,
N → +OA--PA[---MA--NA]+,
O → -MA++NA[+++OA++PA]-,
P → --OA++++MA[+PA++++NA]--NA,
A → nothing
Constants: + - [ ]
Meanings: M → do nothing,
N → do nothing, O → do nothing,
P → do nothing, A → draw 50%,
+ → turn left 36°, - → turn right 36°,
[ → push, ] → pop
Axiom: [N]++[N]++[N]++[N]++[N]
Initial heading: 0
Initial position: x = 0.5, y = 0.5
Scaling factor: 0.6 (exact)

Note that the 0th iteration is blank.

21 - Lace

Picture
Rules: W → +++X--F--ZFX+,
X → ---W++F++YFW-,
Y → +ZFX--F--Z+++,
Z → -YFW++F++Y---
Constants: F + -
Meanings: W → do nothing,
X → do nothing, Y → do nothing,
Z → do nothing, F → draw 50%,
+ → turn left 30°, - → turn right 30°
Axiom: W
Initial heading: 0
Initial position: x = 0.1, y = 0.3
Scaling factor: 0.55 (pretty much exact)

Note that the 0th iteration is blank.

22 - Crystal

Picture
Rules: F → F[+F]F[-F]F
Constants: + - [ ]
Meanings: F → draw 80%,
+ → turn left 90°, - → turn right 90°,
[ → push, ] → pop
Axiom: F
Initial heading: 0
Initial position: x = 0.1, y = 0.5
Scaling factor: 1/3 (exact)

23 - Islands and Lakes

Picture
Rules: F → F+M-FF+F+FF+FM+FF-M+FF-F-FF-FM-FFF, M → MMMMMM
Constants: + -
Meanings: F → draw 50%, M → move 50%, + → turn left 90°, - → turn right 90°
Axiom: F+F+F+F
Initial heading: 0
Initial position: x = 0.25, y = 0.25
Scaling factor: 1/6 (exact)

24 - Cube Effects

Picture
Rules: F → BB[++F][F][--F],
B → B[++D][--D]B, D → F, X → F
Constants: + - [ ]
Meanings: F → draw 50%, B → draw 25%, D → draw 25%, X → do nothing,
+ → turn left 60°, - → turn right 60°,
[ → push, ] → pop
Axiom: [F]-X-[F]-X-[F]-X
Initial heading: 270
Initial position: x = 0.5, y = 0.4
Scaling factor: 0.5 (exact)
I accidentally discovered this when trying to work out the ruleset for L-system 16 - Triangle Space-Filling Tree and really liked the isometric cube effects it creates, so I decided to keep it. It could potentially be simplified or further developed.

25 - Cesàro Curve

Picture
Rules: F → F+F--F+F
Constants: + -
Meanings: F → draw 80%,
+ → turn left 85°, - → turn right 85°
Axiom: F
Initial heading: 0
Initial position: x = 0.1, y = 0.3
Scaling factor: 1/(2 + (sin(10°)/sin(85°))) (exact)

26 - Tree

Picture
Rules: F → G[+F]-F
Constants: G + - [ ]
Meanings: F → draw 50%, G → draw 50%,
+ → turn left 24°, - → turn right 24°,
[ → push, ] → pop
Axiom: F
Initial heading: 270
Initial position: x = 0.5, y = 0.1
Scaling factor: 0.75 (rough)

27 - Plant A

Picture
Rules: F → F[+F]F[-F][F]
Constants: + - [ ]
Meanings: F → draw 40%,
+ → turn left 20°, - → turn right 20°,
[ → push, ] → pop
Axiom: F
Initial heading: 270
Initial position: x = 0.5, y = 0.1
Scaling factor: 0.5 (exact, diminishing expansion)

28 - Plant B

Picture
Rules: F → FF-[-F+F+F]+[+F-F-F]
Constants: + - [ ]
Meanings: F → draw 25%,
+ → turn left 25°, - → turn right 25°,
[ → push, ] → pop
Axiom: F
Initial heading: 270
Initial position: x = 0.4, y = 0.1
Scaling factor: 0.5 (exact, diminishing expansion)

29 - Plant C

Picture
Rules: X → F[+X][-X]FX, F → FF
Constants: + - [ ]
Meanings: X → do nothing, F → draw 40%, + → turn left 25°, - → turn right 25°,
[ → push, ] → pop
Axiom: X
Initial heading: 270
Initial position: x = 0.5, y = 0.1
Scaling factor: 0.5 (exact, diminishing expansion)

Note that the 0th iteration is blank.

30 - Plant D

Picture
Rules: X → F+[[X]-X]-F[-FX]+X, F → FF
Constants: + - [ ]
Meanings: X → do nothing, F → draw 35%, + → turn left 25°, - → turn right 25°,
[ → push, ] → pop
Axiom: X
Initial heading: 270
Initial position: x = 0.5, y = 0.1
Scaling factor: 0.5 (exact, diminishing expansion)

Note that the 0th iteration is blank.
0 Comments



Leave a Reply.

    Author

    Connor Halford. Studied Computer Games Technology at Abertay, now a Games Programmer at MediaTonic.
    ​

    Useful Sites

    hilite.me converts source code into formatted, embeddable HTML without the need for CSS or Javascript.

    tablesgenerator.com performs a similar task as hilite.me but for tabular data.

    Archives
    All posts

    June 2017
    December 2016
    September 2016
    August 2016
    June 2016
    May 2016
    April 2016
    February 2016
    January 2016
    October 2015
    September 2015
    August 2015
    July 2015
    May 2015
    March 2015
    February 2015
    January 2015
    December 2014
    September 2014
    August 2014
    July 2014
    March 2014
    February 2014
    August 2013
    June 2013
    December 2012

    Categories

    All
    Advice
    AI
    Algorithms
    AMPS
    Audio
    Boost
    Box2D
    Coursework
    DirectX
    Flash
    Game Boy Advance
    Game Jam
    Graphics Programming
    Honours Project
    Maths
    Nonograms
    Oh God Why
    OpenGL
    PICO-8
    Pixel Art
    PlayStation 4
    PlayStation Vita
    Procedural Generation
    SFML
    Shaders
    Spirit Shift
    Twine
    Unity
    XAudio2
    Year 1
    Year 2
    Year 3
    Year 4

    RSS Feed

Powered by
✕