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 | function run() { | ||
brd.suspendUpdate(); | |||
this.source = (level>1) ? new expander(level-1 | var code = $('inputtext').value; | ||
if (code=='') { return; } | |||
t.cs(); | |||
t.hideTurtle(); | |||
eval(code); | |||
function expander(level) { | |||
this.source = (level>1) ? new expander(level-1) : (new function() { | |||
// Axiom: | // Axiom: | ||
this.code = axiom; | this.code = axiom; | ||
Line 50: | Line 56: | ||
var pattern = this.source.next(); | var pattern = this.source.next(); | ||
if (!pattern) return null // Finished | if (!pattern) return null // Finished | ||
this.code = | this.code = rules[pattern]; | ||
} | } | ||
return this.code[this.pos++]; | return this.code[this.pos++]; | ||
} | } | ||
} | } | ||
var generator = new expander(level); | |||
function plotter(generator | function plotter(generator) { | ||
for (var c; c=generator.next(); c) { | for (var c; c=generator.next(); c) { | ||
switch(symbols[c]) { | switch(symbols[c]) { | ||
Line 86: | Line 92: | ||
} | } | ||
return null; | return null; | ||
} | } | ||
plotter(generator); | |||
plotter(generator | |||
brd.unsuspendUpdate(); | brd.unsuspendUpdate(); | ||
} | } |
Revision as of 18:39, 30 December 2008