From 51ba9e5494cb848cd29fa174c0dcea4a5ac96eef Mon Sep 17 00:00:00 2001 From: katherine Date: Thu, 11 Feb 2021 00:41:56 -0700 Subject: wolfrand --- 01-rwalk/Makefile | 29 ++++++ 01-rwalk/screenshot.png | Bin 0 -> 1188 bytes 01-rwalk/src/main.c | 165 ++++++++++++++++++++++++++++++++++ 02-wolfautomata/Makefile | 29 ++++++ 02-wolfautomata/screenshot_01.png | Bin 0 -> 21611 bytes 02-wolfautomata/screenshot_02.png | Bin 0 -> 4047 bytes 02-wolfautomata/src/main.c | 162 ++++++++++++++++++++++++++++++++++ 03-wolfrand/Makefile | 29 ++++++ 03-wolfrand/screenshot.gif | Bin 0 -> 244161 bytes 03-wolfrand/src/main.c | 180 ++++++++++++++++++++++++++++++++++++++ README.md | 10 ++- rwalk/Makefile | 29 ------ rwalk/screenshot.png | Bin 1188 -> 0 bytes rwalk/src/main.c | 165 ---------------------------------- wolfautomata/Makefile | 29 ------ wolfautomata/screenshot_01.png | Bin 21611 -> 0 bytes wolfautomata/screenshot_02.png | Bin 4047 -> 0 bytes wolfautomata/src/main.c | 162 ---------------------------------- 18 files changed, 601 insertions(+), 388 deletions(-) create mode 100644 01-rwalk/Makefile create mode 100644 01-rwalk/screenshot.png create mode 100644 01-rwalk/src/main.c create mode 100644 02-wolfautomata/Makefile create mode 100644 02-wolfautomata/screenshot_01.png create mode 100644 02-wolfautomata/screenshot_02.png create mode 100644 02-wolfautomata/src/main.c create mode 100644 03-wolfrand/Makefile create mode 100644 03-wolfrand/screenshot.gif create mode 100644 03-wolfrand/src/main.c delete mode 100644 rwalk/Makefile delete mode 100644 rwalk/screenshot.png delete mode 100644 rwalk/src/main.c delete mode 100644 wolfautomata/Makefile delete mode 100644 wolfautomata/screenshot_01.png delete mode 100644 wolfautomata/screenshot_02.png delete mode 100644 wolfautomata/src/main.c diff --git a/01-rwalk/Makefile b/01-rwalk/Makefile new file mode 100644 index 0000000..da68641 --- /dev/null +++ b/01-rwalk/Makefile @@ -0,0 +1,29 @@ +CFLAGS+=-Wall -O2 $(shell pkg-config --cflags allegro-5 allegro_primitives-5 libsodium) +CFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --cflags allegro-5 allegro_primitives-5 libsodium) +LDFLAGS+=-Wall -O2 $(shell pkg-config --libs allegro-5 allegro_primitives-5 libsodium) +LDFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --libs allegro-5 allegro_primitives-5 libsodium) +SRCDIR=./src +OBJDIR=./build +SRC=$(wildcard $(SRCDIR)/*.c) +OBJ=$(patsubst $(SRCDIR)%.c,$(OBJDIR)%.o,$(SRC)) +BIN=rwalk + +all: $(OBJ) + $(CC) $(LDFLAGS) -o $(BIN) $^ + +$(OBJ): | $(OBJDIR) + +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(CC) $(CFLAGS) -c -o $@ $< + +$(OBJDIR): + mkdir -p $(OBJDIR) + +clean: + rm -rf $(OBJDIR) $(BIN) + +debug: CFLAGS=$(CFLAGSDEBUG) +debug: LDFLAGS=$(LDFLAGSDEBUG) +debug: all + +new: clean all diff --git a/01-rwalk/screenshot.png b/01-rwalk/screenshot.png new file mode 100644 index 0000000..a169b02 Binary files /dev/null and b/01-rwalk/screenshot.png differ diff --git a/01-rwalk/src/main.c b/01-rwalk/src/main.c new file mode 100644 index 0000000..28592e4 --- /dev/null +++ b/01-rwalk/src/main.c @@ -0,0 +1,165 @@ +#include +#include +#include + +#include +#include + +#include + +#define DO_INIT(check, desc) \ + if (!(check)) { \ + fprintf(stderr, "err: can't initialise %s\n", desc); \ + rval = 1; \ + goto done; \ + } + +int main(int argc, char **argv) +{ + int rval = 0; + unsigned goframes; + uint32_t randbytes; + + struct { + uint32_t middle; + uint32_t upper; + uint32_t lower; + } biases[4] = { + /* unbiased */ + { + .middle = 0x80000000, + .upper = 0xc0000000, + .lower = 0x40000000, + }, + /* 1/64 */ + { + .middle = 0x7c000000, + .upper = 0xbe000000, + .lower = 0x3e000000, + }, + /* 1/32 */ + { + .middle = 0x78000000, + .upper = 0xbc000000, + .lower = 0x3c000000, + }, + /* 1/16 */ + { + .middle = 0x70000000, + .upper = 0xb8000000, + .lower = 0x38000000, + } + }; + unsigned setting = 0; + + ALLEGRO_DISPLAY* d = NULL; + ALLEGRO_TIMER* t = NULL; + ALLEGRO_EVENT_QUEUE* eq = NULL; + ALLEGRO_EVENT e; + + float x = 320.0, y = 240.0; + + + DO_INIT(sodium_init() >= 0, "sodium"); + + DO_INIT(al_init(), "allegro"); + DO_INIT(al_init_primitives_addon(), "primitives"); + DO_INIT(al_install_keyboard(), "keyboard"); + + DO_INIT(t = al_create_timer(1.0 / 30.0), "timer"); + DO_INIT(eq = al_create_event_queue(), "event queue"); + + al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE); + DO_INIT(d = al_create_display(641, 481), "display"); + + al_register_event_source(eq, al_get_keyboard_event_source()); + al_register_event_source(eq, al_get_display_event_source(d)); + al_register_event_source(eq, al_get_timer_event_source(t)); + + al_clear_to_color(al_map_rgb(0, 0, 0)); + + + goframes = 0; + al_start_timer(t); + while(true) { + al_wait_for_event(eq, &e); + + switch (e.type) { + + case ALLEGRO_EVENT_DISPLAY_CLOSE: + goto done; + + case ALLEGRO_EVENT_KEY_DOWN: + switch(e.keyboard.keycode) { + + case ALLEGRO_KEY_1: + setting = 0; + puts("1"); + break; + + case ALLEGRO_KEY_2: + setting = 1; + puts("2"); + break; + + case ALLEGRO_KEY_3: + setting = 2; + puts("3"); + break; + + case ALLEGRO_KEY_4: + setting = 3; + puts("4"); + break; + + default: + break; + + } + + if (! (e.keyboard.keycode == ALLEGRO_KEY_ENTER) ) + continue; + + goframes = 1000; + case ALLEGRO_EVENT_TIMER: + if (goframes == 0) { + al_flip_display(); + break; + } + + al_draw_filled_rectangle(x, y, x + 1.0, y + 1.0, al_map_rgb(255, 255, 255)); + + randbytes = randombytes_random(); + + if (randbytes >= biases[setting].middle) { + if (randbytes >= biases[setting].upper) + x += 1; + else + y += 1; + } else { + if (randbytes >= biases[setting].lower) + x -= 1; + else + y -= 1; + } + + al_flip_display(); + + goframes--; + if (goframes == 0) + puts("next"); + } + } + + +done: + + if (d) + al_destroy_display(d); + if (t) + al_destroy_timer(t); + if (eq) + al_destroy_event_queue(eq); + + return rval; +} diff --git a/02-wolfautomata/Makefile b/02-wolfautomata/Makefile new file mode 100644 index 0000000..71038df --- /dev/null +++ b/02-wolfautomata/Makefile @@ -0,0 +1,29 @@ +CFLAGS+=-Wall -O2 $(shell pkg-config --cflags allegro-5 allegro_primitives-5 libsodium) +CFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --cflags allegro-5 allegro_primitives-5) +LDFLAGS+=-Wall -O2 $(shell pkg-config --libs allegro-5 allegro_primitives-5 libsodium) +LDFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --libs allegro-5 allegro_primitives-5) +SRCDIR=./src +OBJDIR=./build +SRC=$(wildcard $(SRCDIR)/*.c) +OBJ=$(patsubst $(SRCDIR)%.c,$(OBJDIR)%.o,$(SRC)) +BIN=wolfautomata + +all: $(OBJ) + $(CC) $(LDFLAGS) -o $(BIN) $^ + +$(OBJ): | $(OBJDIR) + +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(CC) $(CFLAGS) -c -o $@ $< + +$(OBJDIR): + mkdir -p $(OBJDIR) + +clean: + rm -rf $(OBJDIR) $(BIN) + +debug: CFLAGS=$(CFLAGSDEBUG) +debug: LDFLAGS=$(LDFLAGSDEBUG) +debug: all + +new: clean all diff --git a/02-wolfautomata/screenshot_01.png b/02-wolfautomata/screenshot_01.png new file mode 100644 index 0000000..8e8f059 Binary files /dev/null and b/02-wolfautomata/screenshot_01.png differ diff --git a/02-wolfautomata/screenshot_02.png b/02-wolfautomata/screenshot_02.png new file mode 100644 index 0000000..ad68d7e Binary files /dev/null and b/02-wolfautomata/screenshot_02.png differ diff --git a/02-wolfautomata/src/main.c b/02-wolfautomata/src/main.c new file mode 100644 index 0000000..d884280 --- /dev/null +++ b/02-wolfautomata/src/main.c @@ -0,0 +1,162 @@ +#include +#include +#include +#include + +#include +#include + +#define DISP_WIDTH 960 +#define DISP_HEIGHT 480 + +#define FPS 60.0 + +#define DO_INIT(check, desc) \ + if (!(check)) { \ + fprintf(stderr, "err: can't initialise %s\n", desc); \ + rval = 1; \ + goto done; \ + } + +static bool bit_get(uint8_t *bline, unsigned off) +{ + return (bline[off / 8] >> (off % 8)) & 0x01; +} + +static void bit_set(uint8_t *bline, unsigned off) +{ + bline[off / 8] = (bline[off / 8] | (0x01 << (off % 8)) ); +} + +int main(int argc, char **argv) +{ + int rval = 0; + unsigned goframes; + + uint8_t bits[DISP_HEIGHT][DISP_WIDTH / 8]; + + uint8_t automaton = 0; + unsigned x, y; + + ALLEGRO_DISPLAY* d = NULL; + ALLEGRO_TIMER* t = NULL; + ALLEGRO_EVENT_QUEUE* eq = NULL; + ALLEGRO_EVENT e; + + DO_INIT(al_init(), "allegro"); + DO_INIT(al_init_primitives_addon(), "primitives"); + DO_INIT(al_install_keyboard(), "keyboard"); + + DO_INIT(t = al_create_timer(1.0 / FPS), "timer"); + DO_INIT(eq = al_create_event_queue(), "event queue"); + + al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE); + DO_INIT(d = al_create_display(DISP_WIDTH, DISP_HEIGHT), "display"); + + al_register_event_source(eq, al_get_keyboard_event_source()); + al_register_event_source(eq, al_get_display_event_source(d)); + al_register_event_source(eq, al_get_timer_event_source(t)); + + al_start_timer(t); + goframes = 0; + +reset: + + al_clear_to_color(al_map_rgb(0, 0, 0)); + memset(bits, 0, DISP_HEIGHT * DISP_WIDTH / 8); + + /* seed bit */ + bit_set(bits[0], DISP_WIDTH / 2); + + for (y = 0; y < DISP_HEIGHT - 1; y++) { + for (x = 1; x < DISP_WIDTH - 2; x++) { + if ( + bit_get(&automaton, + bit_get(bits[y], x + 2) + + bit_get(bits[y], x + 1) * 2 + + bit_get(bits[y], x) * 4 + ) + ) { + bit_set(bits[y + 1], x + 1); + } + } + } + + while(true) { + al_wait_for_event(eq, &e); + + switch (e.type) { + + case ALLEGRO_EVENT_DISPLAY_CLOSE: + goto done; + + case ALLEGRO_EVENT_KEY_DOWN: + switch(e.keyboard.keycode) { + + case ALLEGRO_KEY_UP: + automaton += 10; + printf("%d\n", automaton); + break; + + case ALLEGRO_KEY_DOWN: + automaton -= 10; + printf("%d\n", automaton); + break; + + case ALLEGRO_KEY_LEFT: + automaton -= 1; + printf("%d\n", automaton); + break; + + case ALLEGRO_KEY_RIGHT: + automaton += 1; + printf("%d\n", automaton); + break; + + case ALLEGRO_KEY_ENTER: + goframes = DISP_HEIGHT; + goto reset; + + default: + continue; + + } + + case ALLEGRO_EVENT_TIMER: + if (goframes == 0) { + al_flip_display(); + break; + } + + /* draw line */ + for (x = 0; x < DISP_WIDTH; x++) { + if (bit_get(bits[DISP_HEIGHT - goframes], x)) { + al_draw_filled_rectangle( + (float)x, (float)(DISP_HEIGHT - goframes), + (float)(x + 1), (float)(DISP_HEIGHT - goframes + 1), + al_map_rgb(255, 255, 255) + ); + } + } + + al_flip_display(); + + goframes--; + + if (goframes == 0) + puts("next"); + } + } + + +done: + + if (d) + al_destroy_display(d); + if (t) + al_destroy_timer(t); + if (eq) + al_destroy_event_queue(eq); + + return rval; +} diff --git a/03-wolfrand/Makefile b/03-wolfrand/Makefile new file mode 100644 index 0000000..b96ec55 --- /dev/null +++ b/03-wolfrand/Makefile @@ -0,0 +1,29 @@ +CFLAGS+=-Wall -O2 $(shell pkg-config --cflags allegro-5 allegro_primitives-5 libsodium) +CFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --cflags allegro-5 allegro_primitives-5) +LDFLAGS+=-Wall -O2 $(shell pkg-config --libs allegro-5 allegro_primitives-5 libsodium) +LDFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --libs allegro-5 allegro_primitives-5) +SRCDIR=./src +OBJDIR=./build +SRC=$(wildcard $(SRCDIR)/*.c) +OBJ=$(patsubst $(SRCDIR)%.c,$(OBJDIR)%.o,$(SRC)) +BIN=wolfrand + +all: $(OBJ) + $(CC) $(LDFLAGS) -o $(BIN) $^ + +$(OBJ): | $(OBJDIR) + +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(CC) $(CFLAGS) -c -o $@ $< + +$(OBJDIR): + mkdir -p $(OBJDIR) + +clean: + rm -rf $(OBJDIR) $(BIN) + +debug: CFLAGS=$(CFLAGSDEBUG) +debug: LDFLAGS=$(LDFLAGSDEBUG) +debug: all + +new: clean all diff --git a/03-wolfrand/screenshot.gif b/03-wolfrand/screenshot.gif new file mode 100644 index 0000000..36a3b73 Binary files /dev/null and b/03-wolfrand/screenshot.gif differ diff --git a/03-wolfrand/src/main.c b/03-wolfrand/src/main.c new file mode 100644 index 0000000..5bf9578 --- /dev/null +++ b/03-wolfrand/src/main.c @@ -0,0 +1,180 @@ +#include +#include +#include +#include + +#include +#include + +#include + +#define DISP_WIDTH 640 +#define DISP_HEIGHT 480 + +#define FPS 3.0 + +#define DO_INIT(check, desc) \ + if (!(check)) { \ + fprintf(stderr, "err: can't initialise %s\n", desc); \ + rval = 1; \ + goto done; \ + } + +static bool bit_get(uint8_t *bline, unsigned off) +{ + return (bline[off / 8] >> (off % 8)) & 0x01; +} + +static void bit_set(uint8_t *bline, unsigned off) +{ + bline[off / 8] = (bline[off / 8] | (0x01 << (off % 8)) ); +} + +static void bit_toggle(uint8_t *bline, unsigned off) +{ + bline[off / 8] = (bline[off / 8] ^ (0x01 << (off % 8)) ); +} + +int main(int argc, char **argv) +{ + int rval = 0; + + uint8_t bits[DISP_HEIGHT][DISP_WIDTH / 8]; + + uint8_t automaton = 0; + unsigned x, y; + + bool pause = 0; + + ALLEGRO_DISPLAY* d = NULL; + ALLEGRO_TIMER* t = NULL; + ALLEGRO_EVENT_QUEUE* eq = NULL; + ALLEGRO_EVENT e; + + + DO_INIT(sodium_init() >= 0, "sodium"); + + DO_INIT(al_init(), "allegro"); + DO_INIT(al_init_primitives_addon(), "primitives"); + DO_INIT(al_install_keyboard(), "keyboard"); + + DO_INIT(t = al_create_timer(1.0 / FPS), "timer"); + DO_INIT(eq = al_create_event_queue(), "event queue"); + + al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE); + DO_INIT(d = al_create_display(DISP_WIDTH, DISP_HEIGHT), "display"); + + al_register_event_source(eq, al_get_keyboard_event_source()); + al_register_event_source(eq, al_get_display_event_source(d)); + al_register_event_source(eq, al_get_timer_event_source(t)); + + + al_start_timer(t); + + al_clear_to_color(al_map_rgb(0, 0, 0)); + + while(true) { + al_wait_for_event(eq, &e); + + switch (e.type) { + + case ALLEGRO_EVENT_DISPLAY_CLOSE: + goto done; + + case ALLEGRO_EVENT_KEY_DOWN: + switch(e.keyboard.keycode) { + + case ALLEGRO_KEY_UP: + automaton += 10; + printf("%d\n", automaton); + break; + + case ALLEGRO_KEY_DOWN: + automaton -= 10; + printf("%d\n", automaton); + break; + + case ALLEGRO_KEY_LEFT: + automaton -= 1; + printf("%d\n", automaton); + break; + + case ALLEGRO_KEY_RIGHT: + automaton += 1; + printf("%d\n", automaton); + break; + + case ALLEGRO_KEY_ENTER: + pause = !pause; + printf("%s\n", pause ? "pause" : "play"); + break; + + default: + break; + + } + + break; + + case ALLEGRO_EVENT_TIMER: + + if (pause) + break; + + /* seed bits */ + + memset(bits[1], 0, (DISP_HEIGHT - 1) * DISP_WIDTH / 8); + + for (x = 1; x < DISP_WIDTH - 1; x++) { + if (randombytes_random() < 0x80000000) + bit_toggle(bits[0], x); + } + + /* propagate */ + + for (y = 0; y < DISP_HEIGHT - 1; y++) { + for (x = 1; x < DISP_WIDTH - 2; x++) { + if ( + bit_get(&automaton, + bit_get(bits[y], x + 2) + + bit_get(bits[y], x + 1) * 2 + + bit_get(bits[y], x) * 4 + ) + ) { + bit_set(bits[y + 1], x + 1); + } + } + } + + /* draw frame */ + + al_clear_to_color(al_map_rgb(0, 0, 0)); + + for (y = 0; y < DISP_HEIGHT; y++) { + for (x = 0; x < DISP_WIDTH; x++) { + if (bit_get(bits[y], x)) { + al_draw_filled_rectangle( + (float)x, (float)y, + (float)(x + 1), (float)(y + 1), + al_map_rgb(255, 255, 255) + ); + } + } + } + + al_flip_display(); + } + } + + +done: + + if (d) + al_destroy_display(d); + if (t) + al_destroy_timer(t); + if (eq) + al_destroy_event_queue(eq); + + return rval; +} diff --git a/README.md b/README.md index 1e1c585..f79dc08 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ ### rwalk -![rwalk screenshot](https://git.airen-no-jikken.icu/ageha/allegro-sketches/raw/branch/master/rwalk/screenshot.png) +![rwalk screenshot](https://git.airen-no-jikken.icu/ageha/allegro-sketches/raw/branch/master/01-rwalk/screenshot.png) ### wolfautomata -![wolfautomata screenshot 1](https://git.airen-no-jikken.icu/ageha/allegro-sketches/raw/branch/master/wolfautomata/screenshot_01.png) -![wolfautomata screenshot 2](https://git.airen-no-jikken.icu/ageha/allegro-sketches/raw/branch/master/wolfautomata/screenshot_02.png) +![wolfautomata screenshot 1](https://git.airen-no-jikken.icu/ageha/allegro-sketches/raw/branch/master/02-wolfautomata/screenshot_01.png) +![wolfautomata screenshot 2](https://git.airen-no-jikken.icu/ageha/allegro-sketches/raw/branch/master/02-wolfautomata/screenshot_02.png) + +### wolfrand + +![wolfrand screenshot](https://git.airen-no-jikken.icu/ageha/allegro-sketches/raw/branch/master/03-wolfrand/screenshot.gif) diff --git a/rwalk/Makefile b/rwalk/Makefile deleted file mode 100644 index da68641..0000000 --- a/rwalk/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -CFLAGS+=-Wall -O2 $(shell pkg-config --cflags allegro-5 allegro_primitives-5 libsodium) -CFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --cflags allegro-5 allegro_primitives-5 libsodium) -LDFLAGS+=-Wall -O2 $(shell pkg-config --libs allegro-5 allegro_primitives-5 libsodium) -LDFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --libs allegro-5 allegro_primitives-5 libsodium) -SRCDIR=./src -OBJDIR=./build -SRC=$(wildcard $(SRCDIR)/*.c) -OBJ=$(patsubst $(SRCDIR)%.c,$(OBJDIR)%.o,$(SRC)) -BIN=rwalk - -all: $(OBJ) - $(CC) $(LDFLAGS) -o $(BIN) $^ - -$(OBJ): | $(OBJDIR) - -$(OBJDIR)/%.o: $(SRCDIR)/%.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJDIR): - mkdir -p $(OBJDIR) - -clean: - rm -rf $(OBJDIR) $(BIN) - -debug: CFLAGS=$(CFLAGSDEBUG) -debug: LDFLAGS=$(LDFLAGSDEBUG) -debug: all - -new: clean all diff --git a/rwalk/screenshot.png b/rwalk/screenshot.png deleted file mode 100644 index a169b02..0000000 Binary files a/rwalk/screenshot.png and /dev/null differ diff --git a/rwalk/src/main.c b/rwalk/src/main.c deleted file mode 100644 index 28592e4..0000000 --- a/rwalk/src/main.c +++ /dev/null @@ -1,165 +0,0 @@ -#include -#include -#include - -#include -#include - -#include - -#define DO_INIT(check, desc) \ - if (!(check)) { \ - fprintf(stderr, "err: can't initialise %s\n", desc); \ - rval = 1; \ - goto done; \ - } - -int main(int argc, char **argv) -{ - int rval = 0; - unsigned goframes; - uint32_t randbytes; - - struct { - uint32_t middle; - uint32_t upper; - uint32_t lower; - } biases[4] = { - /* unbiased */ - { - .middle = 0x80000000, - .upper = 0xc0000000, - .lower = 0x40000000, - }, - /* 1/64 */ - { - .middle = 0x7c000000, - .upper = 0xbe000000, - .lower = 0x3e000000, - }, - /* 1/32 */ - { - .middle = 0x78000000, - .upper = 0xbc000000, - .lower = 0x3c000000, - }, - /* 1/16 */ - { - .middle = 0x70000000, - .upper = 0xb8000000, - .lower = 0x38000000, - } - }; - unsigned setting = 0; - - ALLEGRO_DISPLAY* d = NULL; - ALLEGRO_TIMER* t = NULL; - ALLEGRO_EVENT_QUEUE* eq = NULL; - ALLEGRO_EVENT e; - - float x = 320.0, y = 240.0; - - - DO_INIT(sodium_init() >= 0, "sodium"); - - DO_INIT(al_init(), "allegro"); - DO_INIT(al_init_primitives_addon(), "primitives"); - DO_INIT(al_install_keyboard(), "keyboard"); - - DO_INIT(t = al_create_timer(1.0 / 30.0), "timer"); - DO_INIT(eq = al_create_event_queue(), "event queue"); - - al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE); - DO_INIT(d = al_create_display(641, 481), "display"); - - al_register_event_source(eq, al_get_keyboard_event_source()); - al_register_event_source(eq, al_get_display_event_source(d)); - al_register_event_source(eq, al_get_timer_event_source(t)); - - al_clear_to_color(al_map_rgb(0, 0, 0)); - - - goframes = 0; - al_start_timer(t); - while(true) { - al_wait_for_event(eq, &e); - - switch (e.type) { - - case ALLEGRO_EVENT_DISPLAY_CLOSE: - goto done; - - case ALLEGRO_EVENT_KEY_DOWN: - switch(e.keyboard.keycode) { - - case ALLEGRO_KEY_1: - setting = 0; - puts("1"); - break; - - case ALLEGRO_KEY_2: - setting = 1; - puts("2"); - break; - - case ALLEGRO_KEY_3: - setting = 2; - puts("3"); - break; - - case ALLEGRO_KEY_4: - setting = 3; - puts("4"); - break; - - default: - break; - - } - - if (! (e.keyboard.keycode == ALLEGRO_KEY_ENTER) ) - continue; - - goframes = 1000; - case ALLEGRO_EVENT_TIMER: - if (goframes == 0) { - al_flip_display(); - break; - } - - al_draw_filled_rectangle(x, y, x + 1.0, y + 1.0, al_map_rgb(255, 255, 255)); - - randbytes = randombytes_random(); - - if (randbytes >= biases[setting].middle) { - if (randbytes >= biases[setting].upper) - x += 1; - else - y += 1; - } else { - if (randbytes >= biases[setting].lower) - x -= 1; - else - y -= 1; - } - - al_flip_display(); - - goframes--; - if (goframes == 0) - puts("next"); - } - } - - -done: - - if (d) - al_destroy_display(d); - if (t) - al_destroy_timer(t); - if (eq) - al_destroy_event_queue(eq); - - return rval; -} diff --git a/wolfautomata/Makefile b/wolfautomata/Makefile deleted file mode 100644 index 71038df..0000000 --- a/wolfautomata/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -CFLAGS+=-Wall -O2 $(shell pkg-config --cflags allegro-5 allegro_primitives-5 libsodium) -CFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --cflags allegro-5 allegro_primitives-5) -LDFLAGS+=-Wall -O2 $(shell pkg-config --libs allegro-5 allegro_primitives-5 libsodium) -LDFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --libs allegro-5 allegro_primitives-5) -SRCDIR=./src -OBJDIR=./build -SRC=$(wildcard $(SRCDIR)/*.c) -OBJ=$(patsubst $(SRCDIR)%.c,$(OBJDIR)%.o,$(SRC)) -BIN=wolfautomata - -all: $(OBJ) - $(CC) $(LDFLAGS) -o $(BIN) $^ - -$(OBJ): | $(OBJDIR) - -$(OBJDIR)/%.o: $(SRCDIR)/%.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJDIR): - mkdir -p $(OBJDIR) - -clean: - rm -rf $(OBJDIR) $(BIN) - -debug: CFLAGS=$(CFLAGSDEBUG) -debug: LDFLAGS=$(LDFLAGSDEBUG) -debug: all - -new: clean all diff --git a/wolfautomata/screenshot_01.png b/wolfautomata/screenshot_01.png deleted file mode 100644 index 8e8f059..0000000 Binary files a/wolfautomata/screenshot_01.png and /dev/null differ diff --git a/wolfautomata/screenshot_02.png b/wolfautomata/screenshot_02.png deleted file mode 100644 index ad68d7e..0000000 Binary files a/wolfautomata/screenshot_02.png and /dev/null differ diff --git a/wolfautomata/src/main.c b/wolfautomata/src/main.c deleted file mode 100644 index d884280..0000000 --- a/wolfautomata/src/main.c +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -#define DISP_WIDTH 960 -#define DISP_HEIGHT 480 - -#define FPS 60.0 - -#define DO_INIT(check, desc) \ - if (!(check)) { \ - fprintf(stderr, "err: can't initialise %s\n", desc); \ - rval = 1; \ - goto done; \ - } - -static bool bit_get(uint8_t *bline, unsigned off) -{ - return (bline[off / 8] >> (off % 8)) & 0x01; -} - -static void bit_set(uint8_t *bline, unsigned off) -{ - bline[off / 8] = (bline[off / 8] | (0x01 << (off % 8)) ); -} - -int main(int argc, char **argv) -{ - int rval = 0; - unsigned goframes; - - uint8_t bits[DISP_HEIGHT][DISP_WIDTH / 8]; - - uint8_t automaton = 0; - unsigned x, y; - - ALLEGRO_DISPLAY* d = NULL; - ALLEGRO_TIMER* t = NULL; - ALLEGRO_EVENT_QUEUE* eq = NULL; - ALLEGRO_EVENT e; - - DO_INIT(al_init(), "allegro"); - DO_INIT(al_init_primitives_addon(), "primitives"); - DO_INIT(al_install_keyboard(), "keyboard"); - - DO_INIT(t = al_create_timer(1.0 / FPS), "timer"); - DO_INIT(eq = al_create_event_queue(), "event queue"); - - al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE); - DO_INIT(d = al_create_display(DISP_WIDTH, DISP_HEIGHT), "display"); - - al_register_event_source(eq, al_get_keyboard_event_source()); - al_register_event_source(eq, al_get_display_event_source(d)); - al_register_event_source(eq, al_get_timer_event_source(t)); - - al_start_timer(t); - goframes = 0; - -reset: - - al_clear_to_color(al_map_rgb(0, 0, 0)); - memset(bits, 0, DISP_HEIGHT * DISP_WIDTH / 8); - - /* seed bit */ - bit_set(bits[0], DISP_WIDTH / 2); - - for (y = 0; y < DISP_HEIGHT - 1; y++) { - for (x = 1; x < DISP_WIDTH - 2; x++) { - if ( - bit_get(&automaton, - bit_get(bits[y], x + 2) - + bit_get(bits[y], x + 1) * 2 - + bit_get(bits[y], x) * 4 - ) - ) { - bit_set(bits[y + 1], x + 1); - } - } - } - - while(true) { - al_wait_for_event(eq, &e); - - switch (e.type) { - - case ALLEGRO_EVENT_DISPLAY_CLOSE: - goto done; - - case ALLEGRO_EVENT_KEY_DOWN: - switch(e.keyboard.keycode) { - - case ALLEGRO_KEY_UP: - automaton += 10; - printf("%d\n", automaton); - break; - - case ALLEGRO_KEY_DOWN: - automaton -= 10; - printf("%d\n", automaton); - break; - - case ALLEGRO_KEY_LEFT: - automaton -= 1; - printf("%d\n", automaton); - break; - - case ALLEGRO_KEY_RIGHT: - automaton += 1; - printf("%d\n", automaton); - break; - - case ALLEGRO_KEY_ENTER: - goframes = DISP_HEIGHT; - goto reset; - - default: - continue; - - } - - case ALLEGRO_EVENT_TIMER: - if (goframes == 0) { - al_flip_display(); - break; - } - - /* draw line */ - for (x = 0; x < DISP_WIDTH; x++) { - if (bit_get(bits[DISP_HEIGHT - goframes], x)) { - al_draw_filled_rectangle( - (float)x, (float)(DISP_HEIGHT - goframes), - (float)(x + 1), (float)(DISP_HEIGHT - goframes + 1), - al_map_rgb(255, 255, 255) - ); - } - } - - al_flip_display(); - - goframes--; - - if (goframes == 0) - puts("next"); - } - } - - -done: - - if (d) - al_destroy_display(d); - if (t) - al_destroy_timer(t); - if (eq) - al_destroy_event_queue(eq); - - return rval; -} -- cgit v1.2.3