/* gcc lorenz-alleg.c `allegro-config --libs` */

#include <allegro.h>

#define WIDTH   600
#define HEIGHT  600

typedef struct { double x, y, z; } Point;

int main(void)
{
    Point p[2];
    double h = 0.01, a = 10.0, b = 28.0, c = 8.0 / 3.0;

    allegro_init();
    install_timer();
    install_keyboard();
    
    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, WIDTH, HEIGHT, 0, 0) != 0)
        return 1;

    p[0].x = 1.0;

    while (!keypressed()) {
        int zc;

        p[1].x = p[0].x + h * a * (p[0].y - p[0].x);
        p[1].y = p[0].y + h * (p[0].x * (b - p[0].z) - p[0].y);
        p[1].z = p[0].z + h * (p[0].x * p[0].y - c * p[0].z);

        zc = (p[1].z + p[0].z) * 255 / 110;

        line(screen, p[0].x * 10 + WIDTH / 2,
                     p[0].y * 10 + HEIGHT / 2,
                     p[1].x * 10 + WIDTH / 2,
                     p[1].y * 10 + HEIGHT / 2, makecol(zc, zc, zc));
        p[0] = p[1];
        rest(1);
    }

    return 0;
} END_OF_MAIN()