L-System Fractals

L-System Fractals preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

mathematics 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 702 times • Downloaded 98 times • Run 1 time
Download the 'L-System Fractals' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This program draws special types of pictures called fractals. A fractal is a shape that is self-similar --- that is, it looks the same no matter how closely you zoom in or out For instance, a tree can be thought of as a fractal since if you look at the tree as a whole, you see a stick, that is to say the trunk, with branches coming out of it. Then if you look at a smaller portion of it, say a branch, you see a similar thing, namely, a stick with branches coming out of it.

This model allows you to draw and look at one class of fractals, called L-system fractals. L-System fractals are made by following a set of rules over and over. The rules can be few, but a fascinating and complicated fractal can still form. By using different sets of rules, you can create a wide variety of different fractal designs.

HOW IT WORKS

In the beginning, there will be only one turtle for any fractal. Rules tell the turtle what to do. This turtle can do things such as draw a line, or turn to the right or left. This turtle can also split itself into two turtles. Each new turtle follows the same rules as the original turtle, and draws its own "branch" of the emerging fractal design.

HOW TO USE IT

Perhaps the best way to start with this program is by looking at examples of some L-system fractals. In the "Interface" tab, you will find a series of buttons: "Swirl", "Ball", etc. Each button sets up a different fractal. Some of these examples are famous fractals, such as Sierpinski's tree and Koch's snowflake. To view these examples, simply click on one of the example buttons and then press the GO ONCE button repeatedly.

You can also press GO and leave it pressed instead of pressing GO ONCE repeatedly. Watch the number of turtles though (in the COUNT TURTLES monitor). If it becomes very large the model may become very slow.

If you don't like the location of the fractal in the world you can change it by modifying the value of the following sliders:

  • INIT-X sets the initial x coordinate of the first turtle. It changes the horizontal starting location of the original turtle.
  • INIT-Y sets the initial y coordinate of the first turtle. It changes the vertical starting location of the original turtle.

If you don't like the color scheme of the fractal you can change it by modifying the value of the following sliders:

  • INIT-COLOR controls the initial color of the first turtle.
  • The value of COLOR-INC is added to the turtles color anytime a new turtle hatches.

The example buttons and the SETUP button choose the rules for a fractal. Each of the example buttons sets up the world to draw the fractal of the same name. The SETUP button sets up the world for drawing the rules found in the applyRules procedure in the Code tab.

THINGS TO NOTICE

Notice the self-similarity of the fractals at each iteration. What if one were to perform an infinite number of iterations? Would looking at any piece up close look any different than looking at the whole? Also notice how the number of turtles in each of the example is multiplied by some number at each iteration. Does this make sense? Try to figure out the number of turtles at some arbitrary step n for one or more of the examples.

THINGS TO TRY

Now that you have played around with settings for the examples provided, why not try making your own fractals. You can do this by changing the commands in the apply-rules procedure in the Code tab. The comments in that procedure list the commands you can use.

EXTENDING THE MODEL

Try adding switches such as increment-by-random-length or decrement-by-random-degree that could impose a random factor to the movement of the turtles. Then add to the forward and turning functions, for example, a random value to the number of steps and degrees. This would increase the realism in a fractal.

Pick up a book on fractals or search on the internet to find fractals that are interesting and try to create them using the rules of L-system fractals. You may find some resources below.

Try extending the set of rules so that there are more than the basic ones included in this model. Then use these rules to make new fractals.

Try starting with more than just one turtle, in a different location or heading, and see how that can affect the fractals that you have made. Does it ruin them or does it make them more interesting and complex?

NETLOGO FEATURES

The hatch command is used to make an exact duplicate of an existing turtle.

The run command is used to run the current rule set.

RELATED MODELS

all of the other models in the Fractals section of the Models Library (under Mathematics)

CREDITS AND REFERENCES

You may find more information on L-System fractals in the following locations:

This site offers a nice history and explanation of L-system fractals as well as quit a few classic examples of L-systems.
http://spanky.triumf.ca/www/fractint/LSYS/tutor.html

This site offers an introduction to fractals, including L-system fractals as well as others.
http://www.cs.wpi.edu/~matt/courses/cs563/talks/cbyrd/pres1.html

The Fractal Geometry of Nature by Benoit Mandelbrot

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

COPYRIGHT AND LICENSE

Copyright 2001 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

Comments and Questions

Traffic Simulation (Question)

how to prevent dying of turtles moving along the patch with an degree of 300. I dont know how to manipulate diagonal movement of turtles in netlogo. Can someone Please Help me. how to work with it..

Posted about 12 years ago

Click to Run Model

globals [rule-set]
turtles-own [len]

to setup
  clear-all
  crt 1 [
    set color init-color
    setxy init-x init-y
    set heading 0
    set len 128
    pen-down
  ]
  set rule-set "apply-rules"
  reset-ticks
end 

to go
  ask turtles [ run rule-set ]
  tick
end 

; write your own rules here.  use these commands:
;    "rt " turns the turtle right by number degrees
;    "lt " turns the turtle left by number degrees
;    "fd " moves the turtle forward number steps and draws a line
;    "skip " moves the turtle without drawing
;    "spawn" causes the turtle to duplicate itself

to apply-rules
;enter your rules here
  fd 3 rt 15 spawn fd 3 lt 30 fd 3
;end of your rules
end 

;;;
;;; helper procedures
;;;

;hatch a new turtle; change color of old turtle

to spawn
  hatch 1
  set color color + color-inc
end 

;move forward by steps but do not draw

to skip [steps]
  pen-up fd steps pen-down
end 


;-----------------------------
;        example buttons
;-----------------------------

to setup-swirl
  set color-inc 9
  set init-color 9
  set init-x 0
  set init-y 0
  setup
  set rule-set "swirl"
end 

to swirl
  fd 3 rt 10 spawn skip 3 lt 60 fd 5
end 

to setup-ball
  set color-inc 9
  set init-color 9
  set init-x 0
  set init-y 0
  setup
  set rule-set "ball"
end 

to ball
  fd 2 rt 45 spawn skip 3 lt 45 fd 3 lt 45
end 

to setup-tree1
  set color-inc 9
  set init-color 9
  set init-x 0
  set init-y -50
  setup
  set rule-set "tree1"
end 

to tree1
  fd 4 rt 15 fd 8 spawn rt 180 skip 8 rt 180 lt 15 fd 4 lt 15 spawn fd 8 die
end 

to setup-tree2
  set color-inc 9
  set init-color 9
  set init-x 0
  set init-y -50
  setup
  set rule-set "tree2"
end 

to tree2
  fd 10 rt 30 fd 5 spawn skip -5 lt 60 fd 5 spawn skip -5 rt 30 die
end 

to setup-sierpinski
  set color-inc 3
  set init-color 9
  set init-x 0
  set init-y -25
  setup
  ask turtles [ set len 110 ]
  set rule-set "sierpinski"
end 

to sierpinski
  set len len / 2
  repeat 3 [ fd len spawn rt 180 skip len rt 300 ]
  die
end 

to setup-figure8
  set color-inc 9
  set init-color 9
  set init-x 0
  set init-y 0
  setup
  ask turtles [ set len 100 ]
  set rule-set "figure8"
end 

to figure8
  set len len / 2
  repeat 4 [ fd len spawn rt 180 skip len lt 90 ]
  die
end 

to setup-koch
  set color-inc 5
  set init-color 9
  set init-x -47
  set init-y -82
  setup
  ask turtles [ set len 160 ]
  set rule-set "koch"
end 

to koch
  set len len / 3
  ifelse ticks = 0
  [
    repeat 3  ; we do these rules three times so that we can get the snowflake shape
    [ spawn fd len lt 60 spawn fd len rt 120 spawn fd len lt 60 spawn fd len rt 120 ]
  ]
  ; notice these are the same rules as above, except that we only do them once
  [ spawn fd len lt 60 spawn fd len rt 120 spawn fd len lt 60 spawn fd len rt 120 ]
  die
end 


; Copyright 2001 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago L-System Fractals Download this version

Attached files

File Type Description Last updated
L-System Fractals.png preview Preview for 'L-System Fractals' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.