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