- Author:
- Roger Willian
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/293
- Shortlink:
- https://js1k.com/293
- Blog post:
- please update here!
- Bytes:
- 947
- Chars:
- 947
- Submission
var d=200,e=301,h,i,l,m,n,o,p,q,r,s;function v(a,b,c){var f,g,t,u,j,k;q=c;m=a-1.5/c;n=a+1.5/c;o=b+1/c;p=b-1/c;for(b=0;b<e/2;b++)for(a=0;a<e;a++){g=f=0;t=m+a*(n-m)/e;u=o+b*(p-o)/(e/2);j=f*f;k=g*g;for(c=0;j+k<=4&&c<d;c++){g=f*g*2;g+=u;f=j-k;f+=t;j=f*f;k=g*g}if(j+k<=4)r.fillStyle="rgb(0,0,0)";else{h=83885*c%255;i=84142*c%255;l=84399*c%255;r.fillStyle="rgb("+h+","+i+","+l+")"}r.fillRect(a*1,b*1,1,1)}}r=document.getElementById("c"); r.style.cssText="position:absolute;background:transparent;left:0px;top:0px;width:300px;height:150px;";r=r.getContext("2d");document.write("<div id='d' style='position:absolute;background:transparent;left:0px;top:0px;width:300px;height:150px;'></div>");s=document.getElementById("d");s.oncontextmenu=function(a){var b;b=a.pageX;a=a.pageY;xcen=b/e*(n-m)+m;ycen=a/(e/2)*(p-o)+o;zoom=q/2;v(xcen,ycen,zoom);return false};s.ondblclick=function(a){v(a.pageX/e*(n-m)+m,a.pageY/(e/2)*(p-o)+o,q*2);return false}; v(-0.5,0,1);
- Description
- Maldelbrot fractal viewer. Double click to zoom in, right click to zoom out.
- Base64 encoded
dmFyIGQ9MjAwLGU9MzAxLGgsaSxsLG0sbixvLHAscSxyLHM7ZnVuY3Rpb24gdihhLGIsYyl7dmFyIGYsZyx0LHUsaixrO3E9YzttPWEtMS41L2M7bj1hKzEuNS9jO289YisxL2M7cD1iLTEvYztmb3IoYj0wO2I8ZS8yO2IrKylmb3IoYT0wO2E8ZTthKyspe2c9Zj0wO3Q9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Ts=
- Original source
var MaxIters = 200;
var SIZE = 301;
var r,g,b,LEFT,RIGHT,TOP,BOTTOM,ZOOM,canvas,capa;
var sty="position:absolute;background:transparent;left:0px;top:0px;width:300px;height:150px;"
function mandel(xcen, ycen, zoom)
{
var x, y, count;
var zr, zi, cr, ci;
var rsquared, isquared;
ZOOM = zoom;
LEFT = xcen - 1.5/zoom;
RIGHT = xcen + 1.5/zoom;
TOP = ycen + 1.0/zoom;
BOTTOM = ycen -1.0/zoom;
for (y = 0; y < SIZE/2; y++)
{
for (x = 0; x < SIZE; x++)
{
zr = 0.0;
zi = 0.0;
cr = LEFT + x * (RIGHT - LEFT) / SIZE;
ci = TOP + y * (BOTTOM - TOP) / (SIZE/2);
rsquared = zr * zr;
isquared = zi * zi;
for (count = 0; rsquared + isquared <= 4 && count < MaxIters; count++)
{
zi = zr * zi * 2.0;
zi += ci;
zr = rsquared - isquared;
zr += cr;
rsquared = zr * zr;
isquared = zi * zi;
}
if (rsquared + isquared <= 4)
{
canvas.fillStyle="rgb(0,0,0)";
}
else
{
r = (0x147AD * count)%0xFF ;
g = (0x148AE * count)%0xFF ;
b = (0x149AF * count)%0xFF ;
canvas.fillStyle="rgb("+r+","+g+","+b+")";
}
canvas.fillRect(x*1, y*1, 1, 1);
}
}
}
function init()
{
canvas = document.getElementById("c");
canvas.style.cssText=sty;
canvas = canvas.getContext("2d");
document.write("<div id='d' style='"+sty+"'></div>");
capa = document.getElementById("d");
capa.oncontextmenu = zoomOut;
capa.ondblclick = zoomIn;
mandel(-0.5, 0.0, 1.0);
}
function zoomIn(e)
{
var x;
var y;
x = e.pageX;
y = e.pageY;
var xcen = (x/SIZE)*(RIGHT - LEFT) + LEFT;
var ycen = (y/(SIZE/2.0))*(BOTTOM-TOP) + TOP;
var zoom = ZOOM * 2.0;
mandel(xcen, ycen, zoom);
return false;
}
function zoomOut(e)
{
var x;
var y;
x = e.pageX;
y = e.pageY;
xcen = (x/SIZE)*(RIGHT - LEFT) + LEFT;
ycen = (y/(SIZE/2.0))*(BOTTOM-TOP) + TOP;
zoom = ZOOM / 2.0;
mandel(xcen, ycen, zoom);
return false;
}
init();
mandel(-0.5,0.0,1.0);