Fern (fractal): Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 12: Line 12:
                 if(prob < 0.85) {
                 if(prob < 0.85) {
                     p = board.create('point', [0.85*x+0.04*y+0,-0.04*x+0.85*y+10.6],  
                     p = board.create('point', [0.85*x+0.04*y+0,-0.04*x+0.85*y+10.6],  
                                 {size:1, face='o', withLabel:false});
                                 {size:1, face:'o', withLabel:false});
                 }
                 }
                 else if(prob >= 0.85) if (prob < 0.92) {
                 else if(prob >= 0.85) if (prob < 0.92) {
                     p = board.create('point', [0.2*x-0.26*y+0,0.23*x+0.22*y+10.6],  
                     p = board.create('point', [0.2*x-0.26*y+0,0.23*x+0.22*y+10.6],  
                                 {size:1, face='o', withLabel:false});
                                 {size:1, face:'o', withLabel:false});
                 }
                 }
                 else if(prob >= 0.92) if (prob < 0.99) {
                 else if(prob >= 0.92) if (prob < 0.99) {
                     p = board.create('point', [-0.15*x+0.28*y+0,0.26*x+0.24*y+4.4],  
                     p = board.create('point', [-0.15*x+0.28*y+0,0.26*x+0.24*y+4.4],  
                                 {size:1, face='o', withLabel:false});
                                 {size:1, face:'o', withLabel:false});
                 }
                 }
                 else {
                 else {
                     p = board.create('point', [0*x+0*y+0,0*x+0.16*y+0],  
                     p = board.create('point', [0*x+0*y+0,0*x+0.16*y+0],  
                                 {size:1, face='o', withLabel:false});
                                 {size:1, face:'o', withLabel:false});
                 }
                 }
             }
             }
Line 47: Line 47:
                 if(prob < 0.85) {
                 if(prob < 0.85) {
                     p = board.create('point', [0.85*x+0.04*y+0,-0.04*x+0.85*y+10.6],  
                     p = board.create('point', [0.85*x+0.04*y+0,-0.04*x+0.85*y+10.6],  
                                 {size:1, face='o', withLabel:false});
                                 {size:1, face:'o', withLabel:false});
                 }
                 }
                 else if(prob >= 0.85) if (prob < 0.92) {
                 else if(prob >= 0.85) if (prob < 0.92) {
                     p = board.create('point', [0.2*x-0.26*y+0,0.23*x+0.22*y+10.6],  
                     p = board.create('point', [0.2*x-0.26*y+0,0.23*x+0.22*y+10.6],  
                                 {size:1, face='o', withLabel:false});
                                 {size:1, face:'o', withLabel:false});
                 }
                 }
                 else if(prob >= 0.92) if (prob < 0.99) {
                 else if(prob >= 0.92) if (prob < 0.99) {
                     p = board.create('point', [-0.15*x+0.28*y+0,0.26*x+0.24*y+4.4],  
                     p = board.create('point', [-0.15*x+0.28*y+0,0.26*x+0.24*y+4.4],  
                                 {size:1, face='o', withLabel:false});
                                 {size:1, face:'o', withLabel:false});
                 }
                 }
                 else {
                 else {
                     p = board.create('point', [0*x+0*y+0,0*x+0.16*y+0],  
                     p = board.create('point', [0*x+0*y+0,0*x+0.16*y+0],  
                                 {size:1, face='o', withLabel:false});
                                 {size:1, face:'o', withLabel:false});
                 }
                 }
             }
             }

Revision as of 09:35, 25 March 2011

Do 100 iterations:

References

The underlying JavaScript code

        board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 370, unitX: 5, unitY: 5});
        var p = board.createElement('point', [0,0], {style:10,labelcolor:'#FFFFFF00'});
        function ifs() {
            board.suspendUpdate();
            for(var i=1; i<= 100; i++) {
                var x = p.coords.usrCoords[1];
                var y = p.coords.usrCoords[2];
                var prob = Math.random();
                if(prob < 0.85) {
                    p = board.create('point', [0.85*x+0.04*y+0,-0.04*x+0.85*y+10.6], 
                                {size:1, face:'o', withLabel:false});
                }
                else if(prob >= 0.85) if (prob < 0.92) {
                    p = board.create('point', [0.2*x-0.26*y+0,0.23*x+0.22*y+10.6], 
                                {size:1, face:'o', withLabel:false});
                }
                else if(prob >= 0.92) if (prob < 0.99) {
                    p = board.create('point', [-0.15*x+0.28*y+0,0.26*x+0.24*y+4.4], 
                                {size:1, face:'o', withLabel:false});
                }
                else {
                    p = board.create('point', [0*x+0*y+0,0*x+0.16*y+0], 
                                {size:1, face:'o', withLabel:false});
                }
            }
            board.unsuspendUpdate();
        }