diff options
author | katherine <ageha@airen-no-jikken.icu> | 2021-02-11 17:35:36 -0700 |
---|---|---|
committer | katherine <ageha@airen-no-jikken.icu> | 2021-02-11 17:35:36 -0700 |
commit | 2355472a9ed997a6676c32f0342834c7c4aef6b2 (patch) | |
tree | af7c4bcf3f35a899969732281ea903c14b0cfbee /03-wolfrand/src | |
parent | 3f073ddee13b08941467c98f4c46698eee7a1f43 (diff) | |
download | allegro-sketches-2355472a9ed997a6676c32f0342834c7c4aef6b2.tar.gz |
framerate and randomness for wolfrand
Diffstat (limited to '03-wolfrand/src')
-rw-r--r-- | 03-wolfrand/src/main.c | 22 |
1 files changed, 19 insertions, 3 deletions
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; } } |