Difference between revisions of "L-systems"

From JSXGraph Wiki
Jump to navigationJump to search
 
(13 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
For each system a maximum ''level'' is defined. If this value is increased, the complexity of the drawing rises and running time increases, too.
 
For each system a maximum ''level'' is defined. If this value is increased, the complexity of the drawing rises and running time increases, too.
  
 +
===Examples===
 
Most of the examples are from the book by Przemyslaw Prusinkiewicz and James Hanan: ''Lindenmayer Systems, Fractals, and Plants'', see the References.
 
Most of the examples are from the book by Przemyslaw Prusinkiewicz and James Hanan: ''Lindenmayer Systems, Fractals, and Plants'', see the References.
 
+
====First Example: Sierpinski curve====
===Sierpinski curve===
 
 
<html>
 
<html>
 
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
 
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
 
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<form><textarea id="inputtext0" rows=3 cols=35 wrap="off" style="width:600px;">
+
<form><textarea id="inputtext0" rows=15 cols=35 wrap="off" style="width:600px;">
 
var level = 6;
 
var level = 6;
 
var axiom = 'A';
 
var axiom = 'A';
Line 38: Line 37:
 
<input type="button" value="clear" onClick="clearturtle(0)">
 
<input type="button" value="clear" onClick="clearturtle(0)">
 
</form>
 
</form>
<div id="box0" class="jxgbox" style="width:600px; height:600px;"></div>
+
</html>
<script language="JavaScript">
+
<jsxgraph width="600" height="600" box="box0">
 
var t;
 
var t;
 
var turtle = [];
 
var turtle = [];
 
var brd = [];
 
var brd = [];
brd[0] = JXG.JSXGraph.initBoard('box0', {originX: 300, originY: 300, unitX: 1, unitY: 1});
+
brd[0] = JXG.JSXGraph.initBoard('box0', {boundingbox: [-300, 300, 300, -300]});
turtle[0] = brd[0].createElement('turtle');
+
turtle[0] = brd[0].create('turtle');
  
 
function expander(level,axiom,rules) {
 
function expander(level,axiom,rules) {
Line 107: Line 106:
 
function run(nr) {
 
function run(nr) {
 
   brd[nr].suspendUpdate();
 
   brd[nr].suspendUpdate();
   var code = $('inputtext'+nr).value;
+
   var code = document.getElementById('inputtext'+nr).value;
 
   if (code=='') { return; }
 
   if (code=='') { return; }
 
   t = turtle[nr];
 
   t = turtle[nr];
Line 121: Line 120:
 
   turtle[nr].cs();
 
   turtle[nr].cs();
 
}
 
}
</script>
+
</jsxgraph>
</html>
 
  
 +
====More examples====
 
* [[Quadratic snowflake variation]]
 
* [[Quadratic snowflake variation]]
 
* [[Dragon curve]]
 
* [[Dragon curve]]
Line 130: Line 129:
 
* [[Hexagonal Gosper curve]]
 
* [[Hexagonal Gosper curve]]
 
* [[Plant generation I]]
 
* [[Plant generation I]]
===Plant 1===
+
* [[Plant generation II]]
 
+
* [[Hexagonal kolam]]
<html>
+
* [[Mango kolam]]
<form><textarea id="inputtext6" rows=3 cols=35 wrap="off" style="width:600px;">
+
* [[Penrose tiling]]
var level = 3;
 
var axiom = 'F';
 
var rules = {
 
    'F' : 'F[+F]F[-F]F',
 
    '[' : '[',
 
    ']' : ']',
 
    '+' : '+',
 
    '-' : '-'
 
};
 
var symbols = { 'F':'F',
 
                '+':'+',
 
                '-':'-',
 
                '[':'[',
 
                ']':']'
 
              } ;
 
             
 
var angle = 25.7;
 
var len = 500/Math.pow(3,level);
 
t.setPos(0,-250);
 
var shrink = 1.0;
 
t.setProperty({strokeColor:'green',strokeWidth:2});
 
</textarea><br />
 
<input type="button" value="run" onClick="run(6)">
 
<input type="button" value="clear" onClick="clearturtle(6)">
 
</form>
 
<div id="box6" class="jxgbox" style="width:600px; height:600px;"></div>
 
<script language="JavaScript">
 
brd[6] = JXG.JSXGraph.initBoard('box6', {originX: 300, originY: 300, unitX: 1, unitY: 1});
 
turtle[6] = brd[6].createElement('turtle');
 
</script>
 
</html>
 
 
 
===Plant 2===
 
 
 
<html>
 
<form><textarea id="inputtext7" rows=3 cols=35 wrap="off" style="width:600px;">
 
var level = 4;
 
var axiom = 'X';
 
var rules = {
 
    'F' : 'FF',
 
    'X' : 'F-[[X]+X]+F[+FX]-X',
 
    '[' : '[',
 
    ']' : ']',
 
    '+' : '+',
 
    '-' : '-'
 
};
 
var symbols = { 'F':'F',
 
                'X':' ',
 
                '+':'+',
 
                '-':'-',
 
                '[':'[',
 
                ']':']'
 
              } ;
 
             
 
var angle = 22.5;
 
var len = 800/Math.pow(3,level);
 
t.setPos(0,-250);
 
t.setProperty({strokeColor:'green',strokeWidth:2});
 
</textarea><br />
 
<input type="button" value="run" onClick="run(7)">
 
<input type="button" value="clear" onClick="clearturtle(7)">
 
</form>
 
<div id="box7" class="jxgbox" style="width:600px; height:600px;"></div>
 
<script language="JavaScript">
 
brd[7] = JXG.JSXGraph.initBoard('box7', {originX: 300, originY: 300, unitX: 1, unitY: 1});
 
turtle[7] = brd[7].createElement('turtle');
 
</script>
 
</html>
 
 
 
===Hexagonal kolam===
 
 
 
<html>
 
<form><textarea id="inputtext8" rows=3 cols=35 wrap="off" style="width:600px;">
 
var level = 4;
 
var axiom = 'X';
 
var rules = {
 
    'F' : 'F',
 
    'X' : '[-F+F[Y]+F][+F-F[X]-F]',
 
    'Y' : '[-F+F[Y]+F][+F-F-F]',
 
    '[' : '[',
 
    ']' : ']',
 
    '+' : '+',
 
    '-' : '-'
 
};
 
var symbols = { 'F':'F',
 
                'X':' ',
 
                'Y':' ',
 
                '+':'+',
 
                '-':'-',
 
                '[':'[',
 
                ']':']'
 
              } ;
 
             
 
var angle = 60;
 
var len = 300/(level);
 
t.setPos(0,-250);
 
</textarea><br />
 
<input type="button" value="run" onClick="run(8)">
 
<input type="button" value="clear" onClick="clearturtle(8)">
 
</form>
 
<div id="box8" class="jxgbox" style="width:600px; height:600px;"></div>
 
<script language="JavaScript">
 
brd[8] = JXG.JSXGraph.initBoard('box8', {originX: 300, originY: 300, unitX: 1, unitY: 1});
 
turtle[8] = brd[8].createElement('turtle');
 
</script>
 
</html>
 
 
 
===Mango kolam===
 
 
 
<html>
 
<form><textarea id="inputtext9" rows=3 cols=35 wrap="off" style="width:600px;">
 
var level = 5;
 
var axiom = 'A---A';
 
var rules = {
 
    'F' : 'F',
 
    'f' : 'f',
 
    'A' : 'f-F+Z+F-fA',
 
    'Z' : 'F-FF-F--[--Z]F-FF-F--F-FF-F--',
 
    '[' : '[',
 
    ']' : ']',
 
    '+' : '+',
 
    '-' : '-'
 
};
 
var symbols = { 'F':'F',
 
                'f':'f',
 
                'A':' ',
 
                'Z':' ',
 
                '+':'+',
 
                '-':'-',
 
                '[':'[',
 
                ']':']'
 
              } ;
 
             
 
var angle = 60;
 
var len = 100/(level);
 
</textarea><br />
 
<input type="button" value="run" onClick="run(9)">
 
<input type="button" value="clear" onClick="clearturtle(9)">
 
</form>
 
<div id="box9" class="jxgbox" style="width:600px; height:600px;"></div>
 
<script language="JavaScript">
 
brd[9] = JXG.JSXGraph.initBoard('box9', {originX: 300, originY: 300, unitX: 1, unitY: 1});
 
turtle[9] = brd[9].createElement('turtle');
 
</script>
 
</html>
 
 
 
 
 
===Penrose tiling===
 
 
 
<html>
 
<form><textarea id="inputtext10" rows=3 cols=35 wrap="off" style="width:600px;">
 
var level = 2;
 
var axiom = '[7]++[7]++[7]++[7]++[7]';
 
var rules = {
 
    '6' : '81++91----71[-81----61]++',
 
    '7' : '+81--91[---61--71]+',
 
    '8' : '-61++71[+++81++91]-',
 
    '9' : '--81++++61[+91++++71]--71',
 
    '1' : '',
 
    '+' : '+',
 
    '-' : '-',
 
    '[' : '[',
 
    ']' : ']'
 
  };
 
var symbols = {
 
                '1':'F',
 
                '6':' ',
 
                '7':' ',
 
                '8':' ',
 
                '9':' ',
 
                '+':'+',
 
                '-':'-',
 
                '[':'[',
 
                ']':']'
 
              };
 
var angle = 36.0;
 
var len = 100/(level);
 
t.setProperty({fillcolor:'#abff00'});
 
</textarea><br />
 
<input type="button" value="run" onClick="run(10)">
 
<input type="button" value="clear" onClick="clearturtle(10)">
 
</form>
 
<div id="box10" class="jxgbox" style="width:600px; height:600px;"></div>
 
<script language="JavaScript">
 
brd[10] = JXG.JSXGraph.initBoard('box10', {originX: 300, originY: 300, unitX: 1, unitY: 1});
 
turtle[10] = brd[10].createElement('turtle');
 
</script>
 
</html>
 
  
 
===The underlying JavaScript code===
 
===The underlying JavaScript code===
Line 330: Line 141:
 
* [http://en.wikipedia.org/wiki/L-system http://en.wikipedia.org/wiki/L-system]
 
* [http://en.wikipedia.org/wiki/L-system http://en.wikipedia.org/wiki/L-system]
 
* [http://en.wikipedia.org/wiki/Space-filling_curve http://en.wikipedia.org/wiki/Space-filling_curve]
 
* [http://en.wikipedia.org/wiki/Space-filling_curve http://en.wikipedia.org/wiki/Space-filling_curve]
* [http://en.wikipedia.org/wiki/Penrose_tiling http://en.wikipedia.org/wiki/Penrose_tiling]
+
* [http://www.biologie.uni-hamburg.de/b-online/e28_3/lsys.html An Introduction to Lindenmayer Systems]
* [http://en.wikipedia.org/wiki/Kolam http://en.wikipedia.org/wiki/Kolam]
 
  
  

Latest revision as of 09:59, 8 June 2011

Online experiments with Lindenmayer Systems

A Lindenmayer System consists of

  • an initial string called axiom
  • a set of rewriting rules

This is an experimental page, where the Lindenmayer Systems can be changed online. The visualization is done by the JavaScript library JSXGraph. For each system a maximum level is defined. If this value is increased, the complexity of the drawing rises and running time increases, too.

Examples

Most of the examples are from the book by Przemyslaw Prusinkiewicz and James Hanan: Lindenmayer Systems, Fractals, and Plants, see the References.

First Example: Sierpinski curve


More examples

The underlying JavaScript code

The underlying JavaScript code for producing Lindenmayer systems

References