L-systems: Difference between revisions

From JSXGraph Wiki
(New page: <html> <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/pro...)
 
No edit summary
 
(95 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) {
function expander(level,axiom,rules) {
     this.source = (level>1) ? new expander(level-1) : (new function() {
    this.axiom = axiom;
    this.rules = rules;
     this.source = (level>1) ? new expander(level-1,axiom,rules) : (new function() {
         // Axiom:
         // Axiom:
         this.code = axiom;
         this.code = axiom;
Line 38: 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 49: Line 65:
             var pattern = this.source.next();
             var pattern = this.source.next();
             if (!pattern) return null // Finished
             if (!pattern) return null // Finished
             this.code = rules[pattern];
             this.code = this.rules[pattern];
         }
         }
         return this.code[this.pos++];
         return this.code.charAt(this.pos++);
     }
     }
}
}


var generator = new expander(level);
function plotter(generator,symbols,len,angle,t,shrink) {
function plotter() {
     for (var c; c=generator.next(); c) {
     for (var c; c=generator.next(); c) {
         switch(symbols[c]) {
         switch(symbols[c]) {
Line 86: Line 101:
     }
     }
     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);
   plotter();
  var generator = new expander(level,axiom,rules);
   brd.unsuspendUpdate();
   plotter(generator,symbols,len,angle,t,shrink);
   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