2019-12-12 22:08:35 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-12-12 23:46:24 +00:00
|
|
|
#include "termbox.h"
|
|
|
|
#include "bool.h"
|
|
|
|
#include "outp.h"
|
|
|
|
#include "type.h"
|
2019-12-12 22:08:35 +00:00
|
|
|
|
2019-12-12 23:46:24 +00:00
|
|
|
#define STEPS 13
|
2019-12-12 22:08:35 +00:00
|
|
|
|
2019-12-12 23:46:24 +00:00
|
|
|
void init ( struct term_buf buf );
|
2019-12-12 22:08:35 +00:00
|
|
|
void dofire ( void );
|
|
|
|
void draw ( void );
|
|
|
|
|
|
|
|
int
|
|
|
|
main ( void )
|
|
|
|
{
|
2019-12-12 23:46:24 +00:00
|
|
|
// initialize termbox
|
|
|
|
tb_init();
|
|
|
|
tb_select_output_mode(TB_OUTPUT_NORMAL);
|
|
|
|
tb_clear();
|
2019-12-12 22:08:35 +00:00
|
|
|
|
2019-12-12 23:46:24 +00:00
|
|
|
struct term_buf buf;
|
|
|
|
draw_init(&buf);
|
2019-12-12 22:08:35 +00:00
|
|
|
|
2019-12-12 23:46:24 +00:00
|
|
|
// initialize drawing
|
|
|
|
|
2019-12-12 22:08:35 +00:00
|
|
|
|
2019-12-12 23:46:24 +00:00
|
|
|
draw();
|
2019-12-12 22:08:35 +00:00
|
|
|
dofire();
|
2019-12-12 23:46:24 +00:00
|
|
|
|
|
|
|
// cleanup termbox
|
|
|
|
tb_shutdown();
|
|
|
|
|
2019-12-12 22:08:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-12 23:46:24 +00:00
|
|
|
void
|
|
|
|
init ( struct term_buf buf )
|
|
|
|
{
|
|
|
|
buf->init_width = buf->width;
|
|
|
|
buf->init_height = buf->height;
|
|
|
|
|
|
|
|
usize len = buf->width * buf->height;
|
|
|
|
buf->tmp_buf = malloc(len);
|
|
|
|
len -= buf->width;
|
|
|
|
|
|
|
|
if (buf->tmp_buf == NULL)
|
|
|
|
PRINT("fire: error: unable to malloc() memory for buffer\n");
|
|
|
|
|
|
|
|
memset(buf->tmp_buf, 0, len);
|
|
|
|
memset(buf->tmp_buf + len, STEPS - 1, buf->width);
|
|
|
|
}
|
|
|
|
|
2019-12-12 22:08:35 +00:00
|
|
|
void
|
|
|
|
dofire ( void )
|
|
|
|
{
|
|
|
|
for (usize x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
for (usize y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
usize src = y * width + x;
|
2019-12-12 23:46:24 +00:00
|
|
|
usize random = 0;//(rand() % 7) & 3;
|
2019-12-12 22:08:35 +00:00
|
|
|
usize dest = src - random + 1;
|
|
|
|
usize color;
|
|
|
|
|
|
|
|
if (width > dest ) dest = 0;
|
|
|
|
else dest -= width;
|
|
|
|
|
2019-12-12 23:46:24 +00:00
|
|
|
color = pixels[src];
|
|
|
|
|
|
|
|
if (color == 0 || color == (usize) NULL)
|
|
|
|
pixels[(src - width) % ((width * height) - 1)] = palette[0];
|
|
|
|
else
|
|
|
|
pixels[(dest - width) % ((width * height) - 1)] = pixels[src] - (random & 1);
|
2019-12-12 22:08:35 +00:00
|
|
|
draw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
draw ( void )
|
|
|
|
{
|
|
|
|
// clear screen
|
|
|
|
PRINT("%c[2J", esc);
|
|
|
|
|
|
|
|
// draw pixels onto screen
|
2019-12-12 23:46:24 +00:00
|
|
|
for (usize y = 0; y < height; y++)
|
2019-12-12 22:08:35 +00:00
|
|
|
{
|
2019-12-12 23:46:24 +00:00
|
|
|
for (usize x = 0; x < width; x++)
|
2019-12-12 22:08:35 +00:00
|
|
|
{
|
|
|
|
usize color = pixels[y * width + x];
|
2019-12-12 23:46:24 +00:00
|
|
|
if (color == (usize) NULL) continue;
|
|
|
|
|
|
|
|
// extract RGB value from color
|
2019-12-12 22:08:35 +00:00
|
|
|
u8 blue = color % 256;
|
|
|
|
u8 green = ((color - blue) / 256) % 256;
|
|
|
|
u8 red = ((color - blue) / (int)pow((double)256, (double)2))-(green / 256);
|
|
|
|
|
|
|
|
PRINT("%c[48;2;%i;%i;%im %c[0m", esc, red, blue, green, esc);
|
|
|
|
}
|
|
|
|
PRINT("\n");
|
|
|
|
}
|
|
|
|
}
|