| Uutiset | Koodikirjasto | Wiki | Keskustelut | FAQ | Info |
Javascript-mandelbrotglaze 20.02.04 16:35 Piirtää mandelbrotin fraktaalin ASCII:na selaimeen.
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Javascript Mandelbrot by glaze/biomassa</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
<!--
var x1=-2, x2=2, y1=-2, y2=2; //näytettävä alue
var width=100, height=45; //leveys ja korkeus
function mandelbrot()
{
var cr, ci, zr, zi, nzr, nzi, i, res;
var table = new Array(2); //merkit fraktaalin piirtämiseen
table[0] = 'o';
table[1] = '-';
document.write("<small><pre>");
for (y=0; y<height; y++, document.write("<br />"))
{
ci = y1+((y2-y1)*y)/height; //imaginaariosa
for (x=0; x<width; x++)
{
cr = x1+((x2-x1)*x)/width; //reaaliosa
zr = zi = res = 0;
for (i=0; i<30; i++) //iterointi
{
nzr = zr*zr - zi*zi;
nzi = zr*zi + zi*zr;
zr = nzr + cr;
zi = nzi + ci;
if ((zr*zr+zi*zi) <= 4.0) res++; //osuuko settiin?
}
if (res>0) document.write( table[res%2] );
else document.write(" ");
} //x ends
}
document.write("</pre></small>");
}
// -->
</script>
<style type="text/css">
<!--
body { background-color: black; }
pre { color: white; }
// -->
</style>
</head>
<body>
<script type="text/javascript">
mandelbrot();
</script>
</body>
</html>Linkku 17:37 24.2.04 Ihan hieno msdos64 20:39 7.3.04 Vähän vaikee hahmottaa... |
![]() Haku
|