-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoise.c
59 lines (48 loc) · 1.61 KB
/
noise.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <MiniFB.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
static uint32_t g_width = 800;
static uint32_t g_height = 600;
static uint32_t *g_buffer = 0x0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void
resize(struct mfb_window *window, int width, int height) {
(void) window;
g_width = width;
g_height = height;
g_buffer = realloc(g_buffer, g_width * g_height * 4);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
main()
{
uint32_t i, noise, carry, seed = 0xbeef;
struct mfb_window *window = mfb_open_ex("Noise Test", g_width, g_height, WF_RESIZABLE);
if (!window)
return 0;
g_buffer = (uint32_t *) malloc(g_width * g_height * 4);
mfb_set_resize_callback(window, resize);
mfb_set_viewport(window, 50, 50, g_width - 50 - 50, g_height - 50 - 50);
resize(window, g_width - 100, g_height - 100); // to resize buffer
mfb_update_state state;
do {
for (i = 0; i < g_width * g_height; ++i) {
noise = seed;
noise >>= 3;
noise ^= seed;
carry = noise & 1;
noise >>= 1;
seed >>= 1;
seed |= (carry << 30);
noise &= 0xFF;
g_buffer[i] = MFB_RGB(noise, noise, noise);
}
state = mfb_update_ex(window, g_buffer, g_width, g_height);
if (state != STATE_OK) {
window = 0x0;
break;
}
} while(mfb_wait_sync(window));
return 0;
}