L-systems: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 31: | Line 31: | ||
var t = new JSXTurtleObj(brd); | var t = new JSXTurtleObj(brd); | ||
function expander(level,axiom,rules) { | |||
this.source = (level>1) ? new expander(level-1) : (new function() { | this.rules = rules; | ||
this.axiom = axiom; | |||
this.source = (level>1) ? new expander(level-1,axiom,rules) : (new function() { | |||
// Axiom: | // Axiom: | ||
this.code = axiom; | this.code = this.axiom; | ||
this.pos = 0; | this.pos = 0; | ||
this.next = function() { | this.next = function() { | ||
Line 49: | Line 51: | ||
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[this.pos++]; | ||
} | } | ||
} | |||
function plotter(generator,symbols) { | |||
for (var c; c=generator.next(); c) { | for (var c; c=generator.next(); c) { | ||
switch(symbols[c]) { | switch(symbols[c]) { | ||
Line 84: | Line 87: | ||
} | } | ||
return null; | return null; | ||
} | |||
function run() { | function run() { | ||
Line 93: | Line 96: | ||
t.hideTurtle(); | t.hideTurtle(); | ||
eval(code); | eval(code); | ||
var generator = new expander(level); | var generator = new expander(level,axiom,rules); | ||
plotter(generator); | plotter(generator,symbols); | ||
brd.unsuspendUpdate(); | brd.unsuspendUpdate(); | ||
} | } |
Revision as of 18:41, 30 December 2008