Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The balls, they touch!

Name: Anonymous 2008-01-10 5:02

        string text;
        string pixel;

        int n;

        double tarx;
        double tary;
        double tarz;
        double rayx;
        double rayy;
        double rayz;
        double lightness;
               
        double resx;
        double resy;
        double posx;
        double posy;
        double posz;
        double spherex;
        double spherey;
        double spherez;
        double sphereradius;
        double sphereradius2;
        double lightx;
        double lighty;
        double lightz;
        double ocx;
        double ocy;
        double ocz;

        double yiplus1;
        double yi;
        double delta;
        double t;
        double intersectionx;
        double intersectiony;
        double intersectionz;

        double normalx;
        double normaly;
        double normalz;
       
        double tolightx;
        double tolighty;
        double tolightz;
       
        double a;
        double b;
        double c;
        double d;
        double x;
        double y;
        double z;

        /* 1.koule */
        double sphere1x;
        double sphere1y;
        double sphere1z;
        double sphere1speedx;
        double sphere1speedy;
        double sphere1speedz;
        double sphere1radius;

        /* 2.koule */
        double sphere2x;
        double sphere2y;
        double sphere2z;
        double sphere2speedx;
        double sphere2speedy;
        double sphere2speedz;
        double sphere2radius;

        /* 3.koule */
        double sphere3x;
        double sphere3y;
        double sphere3z;
        double sphere3speedx;
        double sphere3speedy;
        double sphere3speedz;
        double sphere3radius;

        string buff;
        string key;

{
    text = $"ifj-raytracer, vykresli 3 koule\n"$;
    write $text$;
   
    resx = $70.0$;
    resy = $60.0$;
   
    posx = $0.0$;
    posy = $0.0$;
    posz = $0.0-20.0$;
   
    spherex = $0.0$;
    spherey = $0.0$;
    spherez = $0.0$;
    sphereradius = $4.0$;
   
    lightx = $0.0-5.0$;
    lighty = $5.0$;
    lightz = $0.0-11.0$;
   
    /* inicializace 1.koule*/
    sphere1x = $0.0-5.0$;
    sphere1y = $0.0-3.0$;
    sphere1z = $6.0$;
    sphere1speedx = $0.5$;
    sphere1speedy = $0.2$;
    sphere1speedz = $0.0-0.3$;
    sphere1radius = $3.0$;

    /* inicializace 2.koule */
    sphere2x = $0.0-1.0$;
    sphere2y = $1.0$;
    sphere2z = $10.0$;
    sphere2speedx = $0.0-0.3$;
    sphere2speedy = $0.4$;
    sphere2speedz = $0.3$;
    sphere2radius = $5.0$;

    /* inicializace 3.koule */
    sphere3x = $5.0$;
    sphere3y = $0.0-3.0$;
    sphere3z = $20.0$;
    sphere3speedx = $0.1$;
    sphere3speedy = $0.0-0.2$;
    sphere3speedz = $0.3$;
    sphere3radius = $8.0$;

    key = $""$;
    while $key != "q"$
    {
        text = $"+"$;
        buff = $text$;
        text = $"-"$;
        x = $0.0$;
   
        while $x < resx$
        {
            buff = $buff + text$;
            x = $x + 1$;
        }
       
        text = $"+\n"$;
        buff = $buff + text$;
       
        y = $3.0$;
        while $y < resy$
        {
            text = $"|"$;
            buff = $buff + text$;
       
            x = $0.0$;
            while $x < resx$
            {
                tarx = $(1.0 - (x * 2.0) / resx) * 7.0$;
                tary = $(1.0 - (y * 2.0) / resy) * 5.0$;
                tarz = $0.0$;
       
                rayx = $tarx - posx$;
                rayy = $tary - posy$;
                rayz = $tarz - posz$;
       
                n = $0$;
                z = $9999.0$;
                pixel = $" "$;
       
                while $n < 3$
                {
                    if $n == 0$
                    {
                        spherex = $sphere1x$;
                        spherey = $sphere1y$;
                        spherez = $sphere1z$;
                        sphereradius = $sphere1radius$;
                    }
                    else
                    if $n == 1$
                    {
                        spherex = $sphere2x$;
                        spherey = $sphere2y$;
                        spherez = $sphere2z$;
                        sphereradius = $sphere2radius$;
                    }
                    else
                    {
                        spherex = $sphere3x$;
                        spherey = $sphere3y$;
                        spherez = $sphere3z$;
                        sphereradius = $sphere3radius$;
                    }
                   
                    sphereradius2 = $sphereradius * sphereradius$;
       
                    ocx = $posx - spherex$;
                    ocy = $posy - spherey$;
                    ocz = $posz - spherez$;
       
                    a = $rayx * rayx + rayy * rayy + rayz * rayz$;
                    b = $2.0 * (rayx * ocx + rayy * ocy + rayz * ocz)$;
                    c = $ocx * ocx + ocy * ocy + ocz * ocz - sphereradius2$;
                    d = $b * b - 4.0 * a * c$;
       
                    if $d > 0.0$
                    {
                        yi = $d$;
                       
                        /* vypocet odmocniny */
                        delta = $1.0$;
                        while $delta > 1.0e-4$
                        {
                            yiplus1 = $0.5 * (d / yi + yi)$;
                            delta = $yiplus1 - yi$;
                            if $delta < 0.0$ delta = $0.0 - delta$; else {}
                            yi = $yiplus1$;
                        }
       
                        d = $yi$;
                        t = $(0.0 - b - d) / (2.0 * a)$;
       
                        if $((t > 0.0) + (t <= z)) == 2$
                        {
                            z = $t$;
       
                            intersectionx = $rayx * t + posx$;
                            intersectiony = $rayy * t + posy$;
                            intersectionz = $rayz * t + posz$;
       
                            normalx = $(intersectionx - spherex) / sphereradius$;
                            normaly = $(intersectiony - spherey) / sphereradius$;
                            normalz = $(intersectionz - spherez) / sphereradius$;
       
                            tolightx = $lightx - intersectionx$;
                            tolighty = $lighty - intersectiony$;
                            tolightz = $lightz - intersectionz$;
       
                            d = $tolightx * tolightx + tolighty * tolighty + tolightz * tolightz$;
       
                            yi = $d$;
                       
                            /* vypocet odmocniny */
                            delta = $1$;
                            while $delta > 1.0e-4$
                            {
                                yiplus1 = $0.5 * (d / yi + yi)$;
                                delta = $yiplus1 - yi$;
                                if $delta < 0.0$ delta = $0.0 - delta$; else {}
                                yi = $yiplus1$;
                            }
       
                            d = $yi$;
       
                            lightness = $(normalx * tolightx + normaly * tolighty +
                                                     normalz * tolightz) / d$;
       
                            if $lightness > 0.9$
                                 pixel = $"#"$;
                            else
                            if $lightness > 0.7$
                                 pixel = $"*"$;
                            else
                            if $lightness > 0.5$
                                 pixel = $"+"$;
                            else
                            if $lightness > 0.3$
                                 pixel = $"-"$;
                            else
                            if $lightness > 0.1$
                                 pixel = $"."$;
                            else
                            {
                                pixel = $" "$;
                            }
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                    }
                    n = $n + 1$;
                }

                buff = $buff + pixel$;
       
                x = $x + 1.0$;
            }
       
            text = $"|\n"$;
            buff = $buff + text$;
       
            y = $y + 1.0$;
        }

        /* -- 1.KOULE --
           odrazy od sten */
        if $(sphere1x + sphere1speedx /*- sphere1radius*/ < 0.0-12.0)$
            sphere1speedx = $0.0 - sphere1speedx$;
        else
        {
            if $(sphere1x + sphere1speedx /*+ sphere1radius*/ > 12.0)$
                sphere1speedx = $0.0 - sphere1speedx$;
            else {}
        }
        if $(sphere1y + sphere1speedy /*- sphere1radius*/ < 0.0-12.0)$
            sphere1speedy = $0.0 - sphere1speedy$;
        else
        {
            if $(sphere1y + sphere1speedy /*+ sphere1radius*/ > 12.0)$
                sphere1speedy = $0.0 - sphere1speedy$;
            else {}
        }
        if $(sphere1z + sphere1speedz /*- sphere1radius*/ < 0.0)$
            sphere1speedz = $0.0 - sphere1speedz$;
        else
        {
            if $(sphere1z + sphere1speedz /*+ sphere1radius*/ > 30.0)$
                sphere1speedz = $0.0 - sphere1speedz$;
            else {}
        }
        /* posun */
        sphere1x = $sphere1x + sphere1speedx$;
        sphere1y = $sphere1y + sphere1speedy$;
        sphere1z = $sphere1z + sphere1speedz$;

        /* -- 2.KOULE --
           odrazy od sten */
        if $(sphere2x + sphere2speedx /*- sphere2radius*/ < 0.0-12.0)$
            sphere2speedx = $0.0 - sphere2speedx$;
        else
        {
            if $(sphere2x + sphere2speedx /*+ sphere2radius*/ > 12.0)$
                sphere2speedx = $0.0 - sphere2speedx$;
            else {}
        }
        if $(sphere2y + sphere2speedy /*- sphere2radius*/ < 0.0-12.0)$
            sphere2speedy = $0.0 - sphere2speedy$;
        else
        {
            if $(sphere2y + sphere2speedy /*+ sphere2radius*/ > 12.0)$
                sphere2speedy = $0.0 - sphere2speedy$;
            else {}
        }
        if $(sphere2z + sphere2speedz /*- sphere2radius*/ < 0.0)$
            sphere2speedz = $0.0 - sphere2speedz$;
        else
        {
            if $(sphere2z + sphere2speedz /*+ sphere2radius*/ > 30.0)$
                sphere2speedz = $0.0 - sphere2speedz$;
            else {}
        }
        /* posun */
        sphere2x = $sphere2x + sphere2speedx$;
        sphere2y = $sphere2y + sphere2speedy$;
        sphere2z = $sphere2z + sphere2speedz$;

        /* -- 3.KOULE --
           odrazy od sten */
        if $(sphere3x + sphere3speedx /*- sphere3radius*/ < 0.0-12.0)$
            sphere3speedx = $0.0 - sphere3speedx$;
        else
        {
            if $(sphere3x + sphere3speedx /*+ sphere3radius*/ > 12.0)$
                sphere3speedx = $0.0 - sphere3speedx$;
            else {}
        }
        if $(sphere3y + sphere3speedy /*- sphere3radius*/ < 0.0-12.0)$
            sphere3speedy = $0.0 - sphere3speedy$;
        else
        {
            if $(sphere3y + sphere3speedy /*+ sphere3radius*/ > 12.0)$
                sphere3speedy = $0.0 - sphere3speedy$;
            else {}
        }
        if $(sphere3z + sphere3speedz /*- sphere3radius*/ < 0.0)$
            sphere3speedz = $0.0 - sphere3speedz$;
        else
        {
            if $(sphere3z + sphere3speedz /*+ sphere3radius*/ > 30.0)$
                sphere3speedz = $0.0 - sphere3speedz$;
            else {}
        }
        /* posun */
        sphere3x = $sphere3x + sphere3speedx$;
        sphere3y = $sphere3y + sphere3speedy$;
        sphere3z = $sphere3z + sphere3speedz$;
       
        text = $"+"$;
        buff = $buff + text$;
        text = $"-"$;
        x = $0.0$;
        while $x < resx$
        {
            buff = $buff + text$;
            x = $x + 1.0$;
        }
        text = $"+\n"$;
        buff = $buff + text$;
        write $buff$;

        /*read key;    // kvuli zpomaleni animace, je nutne drzet enter pro animovani */
    }
}

Name: Anonymous 2008-01-10 6:43

What language is this?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List