L-systems: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 31: Line 31:
var t = new JSXTurtleObj(brd);
var t = new JSXTurtleObj(brd);


function expander(level) {
function expander(level,axiom,rules) {
     this.source = (level>1) ? new expander(level-1) : (new function() {
    this.rules = rules;
     this.source = (level>1) ? new expander(level-1,axiom,rules) : (new function(axiom) {
         // Axiom:
         // Axiom:
         this.code = axiom;
         this.code = axiom;
Line 49: Line 50:
             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++];

Revision as of 18:37, 30 December 2008