summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/echo.c2
-rwxr-xr-xexamples/julia_set.c32
2 files changed, 24 insertions, 10 deletions
diff --git a/examples/echo.c b/examples/echo.c
index 671d609..7790c6a 100755
--- a/examples/echo.c
+++ b/examples/echo.c
@@ -57,7 +57,7 @@ i32 main(i32 argc, c8 **argv) {
switch (mode) {
case MODE_RECV: {
- printf("Recieving UDP messages on port %d\n\n", PORT);
+ printf("Receiving UDP messages on port %d\n\n", PORT);
for (;;) {
i64 n = p_recv(
diff --git a/examples/julia_set.c b/examples/julia_set.c
index 9d12bb8..747c339 100755
--- a/examples/julia_set.c
+++ b/examples/julia_set.c
@@ -45,13 +45,28 @@ i32 main(i32 argc, c8 **argv) {
f64 view_y = 0.;
f64 view_s = 1.;
- f64 cx = -.8;
- f64 cy = .1;
+ f64 cx = -.771;
+ f64 cy = .1005;
f64 radius = 2.;
i64 limit = 1024;
+ i64 time = p_time();
+
while (!platform.done) {
- p_wait_events();
+ i32 num_events = p_handle_events();
+
+ i64 time_elapsed = p_time() - time;
+ time += time_elapsed;
+
+ b8 left = platform.key_down[KEY_LEFT];
+ b8 right = platform.key_down[KEY_RIGHT];
+ b8 up = platform.key_down[KEY_UP];
+ b8 down = platform.key_down[KEY_DOWN];
+
+ if (!left && !right && !up && !down && num_events == 0) {
+ p_sleep_for(1);
+ continue;
+ }
if (platform.key_pressed['\n'])
p = (p == 1 ? 4 : 1);
@@ -62,13 +77,12 @@ i32 main(i32 argc, c8 **argv) {
view_s = 1.;
}
- f64 d = platform.key_down[MOD_CTRL] ? .0005 : .01;
-
- if (platform.key_pressed['q']) cx -= d;
- if (platform.key_pressed['w']) cx += d;
- if (platform.key_pressed['a']) cy -= d;
- if (platform.key_pressed['s']) cy += d;
+ f64 d = (platform.key_down[MOD_CTRL] ? .00005 : .001) * view_s * time_elapsed;
+ if (left) { cx -= d; cy -= d; }
+ if (right) { cx += d; cy += d; }
+ if (up) { cx += d; cy -= d; }
+ if (down) { cx -= d; cy += d; }
if (platform.key_down[BUTTON_LEFT]) {
view_x += platform.cursor_dx * view_s;