From 2355472a9ed997a6676c32f0342834c7c4aef6b2 Mon Sep 17 00:00:00 2001 From: katherine Date: Thu, 11 Feb 2021 17:35:36 -0700 Subject: framerate and randomness for wolfrand --- 03-wolfrand/src/main.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to '03-wolfrand/src') diff --git a/03-wolfrand/src/main.c b/03-wolfrand/src/main.c index 5d90690..b23cf81 100644 --- a/03-wolfrand/src/main.c +++ b/03-wolfrand/src/main.c @@ -11,7 +11,7 @@ #define DISP_WIDTH 640 #define DISP_HEIGHT 480 -#define FPS 15.0 +#define FPS 20.0 #define DO_INIT(check, desc) \ if (!(check)) { \ @@ -41,7 +41,8 @@ int main(int argc, char **argv) uint8_t bits[DISP_HEIGHT][DISP_WIDTH / 8]; - uint8_t automaton = 0; + uint8_t automaton = 0, randomness = 4, framerate = 2; + unsigned goframes = 1; unsigned x, y; bool pause = 0; @@ -87,6 +88,14 @@ int main(int argc, char **argv) case ALLEGRO_EVENT_KEY_DOWN: switch(e.keyboard.keycode) { + case ALLEGRO_KEY_1: + randomness = (randomness == 64 ? 4 : randomness * 2); + break; + + case ALLEGRO_KEY_2: + framerate = (framerate == 1 ? 8 : framerate / 2); + break; + case ALLEGRO_KEY_UP: automaton += 10; printf("%d\n", automaton); @@ -124,12 +133,17 @@ int main(int argc, char **argv) if (pause) break; + if (goframes > 1) { + goframes--; + break; + } + /* seed bits */ memset(bits[1], 0, (DISP_HEIGHT - 1) * DISP_WIDTH / 8); for (x = 1; x < DISP_WIDTH - 1; x++) { - if (randombytes_random() < 0x10000000) + if (! (randombytes_random() % randomness) ) bit_toggle(bits[0], x); } @@ -169,6 +183,8 @@ int main(int argc, char **argv) al_set_target_backbuffer(d); al_draw_bitmap(b, 0, 0, 0); al_flip_display(); + + goframes = framerate; } } -- cgit v1.2.3