News:

Welcome to RetroCoders Community

Main Menu

Have a Donut in C3 - donut.c3

Started by ron77, Dec 24, 2024, 07:41 AM

Previous topic - Next topic

ron77

donut.c3:

module example;

import std::math;
import std::io;
import std::thread;
import libc;

fn void main()
{
    float a1 = 0;
    float b1 = 0;
    float i;
    float j;
    int k;
    float[1760] z;
    char[1760] b;
    
    io::printf("\x1b[2J");
    
    while (true)
    {
        // Initialize arrays
        for (k = 0; k < 1760; k++)
        {
            b[k] = ' ';
            z[k] = 0;
        }
        
        for (j = 0; j < 6.28; j += 0.07)
        {
            for (i = 0; i < 6.28; i += 0.02)
            {
                float c = math::sin(i);
                float d = math::cos(j);
                float e = math::sin(a1);
                float f = math::sin(j);
                float g = math::cos(a1);
                float h = d + 2;
                float d2 = 1 / (c * h * e + f * g + 5);
                float l = math::cos(i);
                float m = math::cos(b1);
                float n = math::sin(b1);
                float t = c * h * g - f * e;
                
                int x = 40 + (int)(30 * d2 * (l * h * m - t * n));
                int y = 12 + (int)(15 * d2 * (l * h * n + t * m));
                int o = x + 80 * y;
                
                int n2 = (int)(8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n));
                
                if (y > 0 && y < 22 && x > 0 && x < 80 && d2 > z[o])
                {
                    z[o] = d2;
                    b[o] = n2 > 0 ? ".,-~:;=!*#$@"[n2] : ".,-~:;=!*#$@"[0];
                }
            }
        }
        
        io::printf("\x1b[H");
        for (k = 0; k < 1761; k++)
        {
            libc::putchar(k % 80 ? b[k] : 10);
        }
        
        a1 += 0.04;
        b1 += 0.02;
        thread::sleep_ms(30); // Replace usleep with thread::sleep_ms
    }
}