L-systems: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(76 intermediate revisions by 2 users not shown)
Line 1: Line 1:
===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 [http://jsxgraph.org 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====
<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>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxturtle.js"></script>
<form><textarea id="inputtext0" rows=15 cols=35 wrap="off" style="width:600px;">
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">
var level = 6;
var level = 6;
var axiom = 'A';
var axiom = 'A';
var rules = {
var rules = {
     'A':'B-A-B',  
     'A':'B-A-B',
     'B':'A+B+A',
     'B':'A+B+A',
     '+' : '+',
     '+' : '+',
Line 15: Line 24:
var symbols = { 'A':'F',  
var symbols = { 'A':'F',  
                 'B':'F',  
                 'B':'F',  
                 '+':'+',
                 '+':'+',  
                 '-':'-',
                 '-':'-',  
                 '[':'[',
                 '[':'[',  
                 ']':']'
                 ']':']'
               } ;
               };  
var angle = 60;
var angle = 60;  
var len = 500/Math.pow(2,level);
var len = 500/Math.pow(2,level);
t.setPos(-250*Math.pow(-1,level),-250);
t.rt(90*Math.pow(-1,level));  
</textarea><br />
</textarea><br />
<input type="button" value="run" onClick="run()">
<input type="button" value="run" onClick="run(0)">
<input type="button" value="clear" onClick="clearturtle()">
<input type="button" value="clear" onClick="clearturtle(0)">
</form>
</form>
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
</html>
<script language="JavaScript">
<jsxgraph width="600" height="600" box="box0">
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var t;
var t = new JSXTurtleObj(brd);
var turtle = [];
var brd = [];
brd[0] = JXG.JSXGraph.initBoard('box0', {boundingbox: [-300, 300, 300, -300]});
turtle[0] = brd[0].create('turtle');


function expander(level,axiom,rules) {
function expander(level,axiom,rules) {
Line 40: Line 54:
         this.next = function() {
         this.next = function() {
             if (this.pos>=this.code.length) return null;
             if (this.pos>=this.code.length) return null;
             return this.code[this.pos++];
             return this.code.charAt(this.pos++);
         }
         }
     });
     });
Line 53: Line 67:
             this.code = this.rules[pattern];
             this.code = this.rules[pattern];
         }
         }
         return this.code[this.pos++];
         return this.code.charAt(this.pos++);
     }
     }
}
}


function plotter(generator,symbols,len) {
function plotter(generator,symbols,len,angle,t,shrink) {
     for (var c; c=generator.next(); c) {
     for (var c; c=generator.next(); c) {
         switch(symbols[c]) {
         switch(symbols[c]) {
Line 88: Line 102:
     return null;
     return null;
   }
   }
 
var shrink = 1.0;
function run() {
   brd.suspendUpdate();
function run(nr) {
   var code = $('inputtext').value;
   brd[nr].suspendUpdate();
   var code = document.getElementById('inputtext'+nr).value;
   if (code=='') { return; }
   if (code=='') { return; }
  t = turtle[nr];
   t.cs();
   t.cs();
   t.hideTurtle();
   t.hideTurtle();
   eval(code);
   eval(code);
   var generator = new expander(level,axiom,rules);
   var generator = new expander(level,axiom,rules);
   plotter(generator,symbols);
   plotter(generator,symbols,len,angle,t,shrink);
   brd.unsuspendUpdate();
   brd[nr].unsuspendUpdate();
}
}


function clearturtle() {
function clearturtle(nr) {
   t.cs();
   turtle[nr].cs();
}
}
run();
</jsxgraph>
</script>
 
</html>
====More examples====
* [[Quadratic snowflake variation]]
* [[Dragon curve]]
* [[Islands and lakes]]
* [[Peano curve]]
* [[Hexagonal Gosper curve]]
* [[Plant generation I]]
* [[Plant generation II]]
* [[Hexagonal kolam]]
* [[Mango kolam]]
* [[Penrose tiling]]
 
===The underlying JavaScript code===
The underlying [[JavaScript code for producing Lindenmayer systems]]
 
===References===
* Przemyslaw Prusinkiewicz, James Hanan: Lindenmayer Systems, Fractals, and Plants (Lecture Notes in Biomathematics). Springer-Verlag 1989, ISBN 0-387-97092-4
* [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://www.biologie.uni-hamburg.de/b-online/e28_3/lsys.html An Introduction to Lindenmayer Systems]
 


[[Category:Examples]]
[[Category:Examples]]
[[Category:Fractals]]
[[Category:Turtle Graphics]]
[[Category:Turtle Graphics]]
[[Category:Lindenmayer systems]]

Latest revision as of 07: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