Browse Source

framerate and randomness for wolfrand

master
katherine 3 months ago
parent
commit
2355472a9e
  1. 22
      03-wolfrand/src/main.c

22
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;
}
}

Loading…
Cancel
Save