Fern (fractal): Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) (New page: <html> <link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" /> <script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/pro...) |
A WASSERMANN (talk | contribs) No edit summary |
||
(18 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<html> | Do 100 iterations: | ||
< | <html><form><input type='button' value="OK" onClick="ifs();"></form></html> | ||
< | <jsxgraph width="600" height="400" box="box"> | ||
< | board = JXG.JSXGraph.initBoard('box', {boundingbox: [-49, 71.8, 70, -5.2]}); | ||
< | var p = board.create('point', [0,0], {style:10,labelcolor:'#FFFFFF00'}); | ||
board = JXG.JSXGraph.initBoard('box', { | |||
var p = board. | |||
function ifs() { | function ifs() { | ||
board.suspendUpdate(); | board.suspendUpdate(); | ||
Line 14: | Line 11: | ||
var prob = Math.random(); | var prob = Math.random(); | ||
if(prob < 0.85) { | if(prob < 0.85) { | ||
p = board. | 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 | else if(prob >= 0.85) if (prob < 0.92) { | ||
p = board. | 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 | else if(prob >= 0.92) if (prob < 0.99) { | ||
p = board. | 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 { | else { | ||
p = board. | p = board.create('point', [0*x+0*y+0,0*x+0.16*y+0], | ||
{size:1, face:'o', withLabel:false}); | |||
} | } | ||
} | } | ||
board.unsuspendUpdate(); | board.unsuspendUpdate(); | ||
} | } | ||
</ | </jsxgraph> | ||
=== References === | |||
* [http://en.wikipedia.org/wiki/Iterated_function_system http://en.wikipedia.org/wiki/Iterated_function_system] | |||
=== The underlying JavaScript code === | |||
<source lang="javascript"> | <source lang="javascript"> | ||
board = JXG.JSXGraph.initBoard('box', { | board = JXG.JSXGraph.initBoard('box', {boundingbox: [-49, 71.8, 70, -5.2]}); | ||
var p = board. | var p = board.create('point', [0,0], {style:10,labelcolor:'#FFFFFF00'}); | ||
function ifs() { | function ifs() { | ||
board.suspendUpdate(); | board.suspendUpdate(); | ||
Line 41: | Line 46: | ||
var prob = Math.random(); | var prob = Math.random(); | ||
if(prob < 0.85) { | if(prob < 0.85) { | ||
p = board. | 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 | else if(prob >= 0.85) if (prob < 0.92) { | ||
p = board. | 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 | else if(prob >= 0.92) if (prob < 0.99) { | ||
p = board. | 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 { | else { | ||
p = board. | p = board.create('point', [0*x+0*y+0,0*x+0.16*y+0], | ||
{size:1, face:'o', withLabel:false}); | |||
} | } | ||
} | } | ||
Line 59: | Line 68: | ||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Fractals]] |
Latest revision as of 11:21, 13 October 2015
Do 100 iterations:
References
The underlying JavaScript code
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-49, 71.8, 70, -5.2]});
var p = board.create('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();
}