Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
84 lines (74 sloc) 1.63 KB
<HTML>
<HEAD>
<TITLE>
Mandelbrot Set
</TITLE>
<SCRIPT>
var cvs;
var c;
function Color(r,g,b){
this.r = r;
this.g = g;
this.b = b;
}
function ImaginaryNumber(a,b){
this.x = a;
this.i = b;
this.getSquare = function(){
return new ImaginaryNumber(this.x * this.x - this.i * this.i, 2 * this.x * this.i)
}
}
function main(){
cvs = document.getElementById("cvns");
c = cvs.getContext("2d");
var screen = c.createImageData(cvs.width,cvs.height);
var pixelColor = new Color(0, 0, 0);
var x;
var y;
var value;
for(var i = 0; i < cvs.width * cvs.height; i++){
pixelColor = new Color(0, 0, 0);
x = (i % cvs.width) / (cvs.height);
y = Math.floor(i / cvs.width) / cvs.height;
x = 3.5 * (x - .5);
y = 3.5 * (y - .5);
var n = new ImaginaryNumber(x, y);
var j = 0;
while(j < 128 && n.x < 4){
n = n.getSquare();
// n.x += x;
// n.i += y;
n.x -= .8;
n.i += .156;
// n.x += -.45;
// n.i += .6666;
// n.x += .2;
// n.i += -.575;
// n.x += .375;
// n.i -= .3;
// n.x += .33333;
// n.i += .035;
// n.x -= 1.19;
// n.i += .3;
j++;
}
value = j * j / 12;
pixelColor.r += value / 3;
pixelColor.g += value / 2;
pixelColor.b += value;
screen.data[4*i] = pixelColor.r;
screen.data[4*i+1] = pixelColor.g;
screen.data[4*i+2] = pixelColor.b;
screen.data[4*i+3] = 256;
}
c.putImageData(screen, 0, 0);
document.getElementById("print_to_me").innerHTML = SEED;
}
</SCRIPT>
</HEAD>
<BODY onload="main();" bgcolor="#303030" onkeydown="Step();">
<CANVAS ID="cvns" WIDTH="512" HEIGHT="512" STYLE="border-style:solid; border-width:1px;">
</CANVAS>
<DIV ID="print_to_me"></DIV>
</BODY>
</HTML>