lidarnoget
Check out the formatting tips on the right for help formatting and making links.
Use the template below:
//-- draw an ASCII mandelbrot fractal in the console
//------------------------------
function contrast(color_value)
//------------------------------
{ return ((color_value * color_value) / 256);
}
function write_ascii(intensity)
{
local t = [" ",".",":","-",";","!","/",">",")","|","&","I","H","%","*","#"];
local i = (contrast(intensity)) / 20;
print(t[i]);
}
//--------------------------------------------------
//-- main
//--------------------------------------------------
print("Fractal test\n");
local bmp_size_x = 120;
local bmp_size_y = 60;
local origin_x = bmp_size_x / 2.0;
local origin_y = bmp_size_y / 2.0;
local cx=0.0, cy=0.0, scale=0.1;
local limit=4.0;
local i,j,
x=0.0,y=0.0,
ax=0.0,ay=0.0,a1=0.0,b1=0.0,a2=0.0,b2=0.0,lp=0;
for (j=0; j < bmp_size_y; j+=1)
{
for (i=0; i < bmp_size_x; i+=1)
{
x = (i - origin_x) * 0.5;
y = (j - origin_y) * 0.5;
ax=cx+x*scale;
ay=cy+y*scale;
a1=ax;
b1=ay;
lp=0;
do
{
lp=lp+1;
a2=a1*a1-b1*b1+ax;
b2=2*a1*b1+ay;
a1=a2;
b1=b2;
}
while ( (lp<=255) && ((a1*a1)+(b1*b1)<=limit) );
write_ascii(lp);
}
print("\n");
}
print("Done\n");