Show Changes Show Changes
Edit Edit
Print Print
Recent Changes Recent Changes
Subscriptions Subscriptions
Lost and Found Lost and Found
Find References Find References
Rename Rename
Administration Page Administration Page
Topic Locks Topic Locks

Search

History

2/22/2017 3:56:07 AM
-92.222.238.172
6/21/2008 3:42:07 AM
84.236.50.38
5/22/2008 6:57:43 AM
-130.85.136.169
3/14/2008 8:31:49 PM
jonn1-66.231.51.171
3/14/2008 8:31:29 PM
jonn1-67.160.186.48
List all versions List all versions

RSS feed for the SquirrelWiki namespace

Mandelbrot_ Ansi
.

lidarnoget

Check out the formatting tips on the right for help formatting and making links.

Use the template below: http://www.partnerhoroskop-kostenlos.eu/

Summary
    //-- 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");
Not logged in. Log in

squirrel's community wiki

This is FlexWiki, an open source wiki engine.

Change Style

Recent Topics