ifsf=function(p,clr,cb){this.clr=clr;this.p=p;this._cb=cb;};co=function(x,y){this.X=x;this.Y=y;};var fs=new Array();fs.push(new ifsf(0.01,"#00f",function(x,y){x=0;y=0.16*y;return new co(x,y);}));fs.push(new ifsf(0.07,"#f00",function(x,y){nx=(0.2*x)-(0.26*y);ny=(0.23*x)+(0.22*y)+1.6;return new co(nx,ny);}));fs.push(new ifsf(0.07,"#0f0",function(x,y){nx=(-0.15*x)+(0.28*y);ny=(0.26*x)+(0.24*y)+0.44;return new co(nx,ny);}));fs.push(new ifsf(0.85,"#fff",function(x,y){nx=(0.85*x)+(0.04*y);ny=(-0.04*x)+(0.85*y)+1.6;return new co(nx,ny);}));dfs(fs,-2.2,0,2.7,10);function dfs(fs,tlx,tly,brx,bry){tpb=0;for(i in fs){tpb+=fs[i].p}var e=document.getElementById("c");var cx=e.getContext('2d');if(cx){var w=e.width;var h=e.height;cx.fillStyle="#000";cx.fillRect(0,0,w,h);var x=0;var y=0;cx.fillStyle="#bbb";for(var i=0;i<100000;i++){cx.fillRect(w-((x-tlx)*(w/(brx-tlx))),h-((y-tly)*(h/(bry-tly))),1,1);num=Math.random()*tpb;for(i2 in fs){num-=fs[i2].p;if(num<0){r=fs[i2]._cb(x,y);x=r.X;y=r.Y;cx.fillStyle=fs[i2].clr;break;}}}}}
function drawFern()
{
var funs = new Array();
funs.push(new ifsf(0.01, "rgb(0,0,255)", function(x, y) { x = 0; y = 0.16 * y; return new coord(x, y); }));
funs.push(new ifsf(0.07, "rgb(255,0,0)", function(x, y) { newx = (0.2 * x) - (0.26 * y); newy = (0.23 * x) + (0.22 * y) + 1.6; return new coord(newx, newy); }));
funs.push(new ifsf(0.07, "rgb(0,255,0)", function(x, y) { newx = (-0.15 * x) + (0.28 * y); newy = (0.26 * x) + (0.24 * y) + 0.44; return new coord(newx, newy); }));
funs.push(new ifsf(0.85, "rgb(255,255,255)", function(x, y) { newx = (0.85 * x) + (0.04 * y); newy = (-0.04 * x) + (0.85 * y) + 1.6; return new coord(newx, newy); }));
drawIFS(funs, -2.2, 0, 2.7, 10);
}
function drawIFS(funs, tlx, tly, brx, bry)
{
totalProb = 0;
for (i in funs)
{
totalProb += funs[i].prob
}
var elem = document.getElementById("imageEdit");
if (elem && elem.getContext)
{
var cxt = elem.getContext('2d');
if (cxt)
{
var w = elem.width;
var h = elem.height;
cxt.fillStyle = "rgb(0,0,0)";
cxt.fillRect(0,0,w,h);
var x = 0;
var y = 0;
cxt.fillStyle = "rgb(200,200,200)";
for(var i = 0; i < 100000; i++)
{
cxt.fillRect(w - ((x - tlx) * (w / (brx - tlx))),h - ((y - tly) * (h / (bry - tly))),1,1);
num = Math.random() * totalProb;
for (i2 in funs)
{
num -= funs[i2].prob;
if (num < 0)
{
ret = funs[i2]._cb(x, y);
x = ret.X;
y = ret.Y;
cxt.fillStyle = funs[i2].clr;
break;
}
}
}
}
}
}
ifsf = function(prob, clr, cb)
{
this.clr = clr;
this.prob = prob;
this._cb = cb;
}
coord = function(x, y)
{
this.X = x;
this.Y = y;
}