From 425fe47298bd29ce0cf7d117df0ee86a05f89ea2 Mon Sep 17 00:00:00 2001 From: Ekin Igdir Date: Mon, 18 Nov 2024 22:16:26 +0100 Subject: [PATCH 1/5] timestepping on pause --- src/randomart.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/randomart.c b/src/randomart.c index cf9755b..ecb5c73 100644 --- a/src/randomart.c +++ b/src/randomart.c @@ -1124,6 +1124,7 @@ int main(int argc, char **argv) .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, }; float time = 0.0f; + float max_render_length = (2*PI)*2; bool pause = false; while (!WindowShouldClose()) { @@ -1150,6 +1151,13 @@ int main(int argc, char **argv) if (IsKeyPressed(KEY_SPACE)) { pause = !pause; } + if ( pause && IsKeyPressed(KEY_Q)) { + time -= 0.5*dt; + } + if (pause && IsKeyPressed(KEY_E)) { + time += 0.5*dt; + } + } else { if (time < max_render_length) { BeginTextureMode(screen); From b0e6e52a64d48c12cfb117378db5ecceeb5d2855 Mon Sep 17 00:00:00 2001 From: Ekin Igdir Date: Mon, 18 Nov 2024 22:18:46 +0100 Subject: [PATCH 2/5] camera movements --- src/randomart.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/randomart.c b/src/randomart.c index ecb5c73..81af538 100644 --- a/src/randomart.c +++ b/src/randomart.c @@ -1124,9 +1124,12 @@ int main(int argc, char **argv) .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, }; float time = 0.0f; - + float max_render_length = (2*PI)*2; bool pause = false; + float x_coord = 0; + float y_coord = 0; + while (!WindowShouldClose()) { float w = GetScreenWidth(); float h = GetScreenHeight(); @@ -1137,7 +1140,7 @@ int main(int argc, char **argv) BeginShaderMode(shader); DrawTexturePro( default_texture, - (Rectangle){0, 0, 1, 1}, + (Rectangle){x_coord, y_coord, x_coord+1, y_coord+1}, (Rectangle){0, 0, w, h}, (Vector2){0}, 0, WHITE); EndShaderMode(); @@ -1157,6 +1160,19 @@ int main(int argc, char **argv) if (pause && IsKeyPressed(KEY_E)) { time += 0.5*dt; } + if (IsKeyPressed(KEY_W)) { + y_coord += 0.01; + } + if (IsKeyPressed(KEY_S)) { + y_coord -= 0.01; + } + + if (IsKeyPressed(KEY_A)) { + x_coord += 0.01; + } + if (IsKeyPressed(KEY_D)) { + x_coord -= 0.01; + } } else { if (time < max_render_length) { From d41f9f3c27612147c59fa9f181e2cc10155b1275 Mon Sep 17 00:00:00 2001 From: Ekin Igdir Date: Mon, 18 Nov 2024 22:23:03 +0100 Subject: [PATCH 3/5] camera zoom --- src/randomart.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/randomart.c b/src/randomart.c index 81af538..8060b65 100644 --- a/src/randomart.c +++ b/src/randomart.c @@ -775,13 +775,15 @@ bool compile_node_func_into_fragment_shader(String_Builder *sb, Node *f) sb_append_cstr(sb, "in vec2 fragTexCoord;\n"); sb_append_cstr(sb, "out vec4 finalColor;\n"); sb_append_cstr(sb, "uniform float time;\n"); + sb_append_cstr(sb, "uniform float x_offset;\n"); + sb_append_cstr(sb, "uniform float y_offset;\n"); sb_append_cstr(sb, "vec4 map_color(vec3 rgb) {\n"); sb_append_cstr(sb, " return vec4((rgb + 1)/2.0, 1.0);\n"); sb_append_cstr(sb, "}\n"); sb_append_cstr(sb, "void main()\n"); sb_append_cstr(sb, "{\n"); - sb_append_cstr(sb, " float x = fragTexCoord.x*2.0 - 1.0;\n"); - sb_append_cstr(sb, " float y = fragTexCoord.y*2.0 - 1.0;\n"); + sb_append_cstr(sb, " float x = fragTexCoord.x*2.0 - x_offset;\n"); + sb_append_cstr(sb, " float y = fragTexCoord.y*2.0 - y_offset;\n"); sb_append_cstr(sb, " float t = sin(time);\n"); sb_append_cstr(sb, " finalColor = map_color("); if (!compile_node_into_fragment_expression(sb, f, 0)) return false; @@ -1114,6 +1116,9 @@ int main(int argc, char **argv) RenderTexture2D screen = LoadRenderTexture(width, height); Shader shader = LoadShaderFromMemory(NULL, sb.items); int time_loc = GetShaderLocation(shader, "time"); + int x_offset_loc = GetShaderLocation(shader, "x_offset"); + int y_offset_loc = GetShaderLocation(shader, "y_offset"); + SetTargetFPS(fps); SetExitKey(KEY_NULL); Texture default_texture = { @@ -1129,6 +1134,8 @@ int main(int argc, char **argv) bool pause = false; float x_coord = 0; float y_coord = 0; + float x_zoom = 1; + float y_zoom = 1; while (!WindowShouldClose()) { float w = GetScreenWidth(); @@ -1137,10 +1144,12 @@ int main(int argc, char **argv) BeginDrawing(); if (ffmpeg == NULL) { SetShaderValue(shader, time_loc, &time, SHADER_UNIFORM_FLOAT); + SetShaderValue(shader, x_offset_loc, &x_zoom, SHADER_UNIFORM_FLOAT); + SetShaderValue(shader, y_offset_loc, &y_zoom, SHADER_UNIFORM_FLOAT); BeginShaderMode(shader); DrawTexturePro( default_texture, - (Rectangle){x_coord, y_coord, x_coord+1, y_coord+1}, + (Rectangle){x_coord, y_coord, x_coord+x_zoom, y_coord+y_zoom}, (Rectangle){0, 0, w, h}, (Vector2){0}, 0, WHITE); EndShaderMode(); @@ -1160,6 +1169,7 @@ int main(int argc, char **argv) if (pause && IsKeyPressed(KEY_E)) { time += 0.5*dt; } + if (IsKeyPressed(KEY_W)) { y_coord += 0.01; } @@ -1174,6 +1184,28 @@ int main(int argc, char **argv) x_coord -= 0.01; } + if (IsKeyPressed(KEY_I)) { + y_zoom /= 1.2; + } + if (IsKeyPressed(KEY_K)) { + y_zoom *= 1.2; + } + + if (IsKeyPressed(KEY_J)) { + x_zoom /= 1.2; + } + if (IsKeyPressed(KEY_L)) { + x_zoom *= 1.2; + } + + if (IsKeyPressed(KEY_U)) { + x_zoom /= 1.2; + y_zoom /= 1.2; + } + if (IsKeyPressed(KEY_H)) { + x_zoom *= 1.2; + y_zoom *= 1.2; + } } else { if (time < max_render_length) { BeginTextureMode(screen); From 09387adf384a17150bc655ee1cd8b34f467f13df Mon Sep 17 00:00:00 2001 From: Ekin Igdir Date: Mon, 18 Nov 2024 23:27:16 +0100 Subject: [PATCH 4/5] Added amplitude and frequency change, Added info, remapped some keys --- src/randomart.c | 106 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 15 deletions(-) diff --git a/src/randomart.c b/src/randomart.c index 8060b65..227a313 100644 --- a/src/randomart.c +++ b/src/randomart.c @@ -775,6 +775,10 @@ bool compile_node_func_into_fragment_shader(String_Builder *sb, Node *f) sb_append_cstr(sb, "in vec2 fragTexCoord;\n"); sb_append_cstr(sb, "out vec4 finalColor;\n"); sb_append_cstr(sb, "uniform float time;\n"); + + sb_append_cstr(sb, "uniform float amp;\n"); + sb_append_cstr(sb, "uniform float freq;\n"); + sb_append_cstr(sb, "uniform float x_offset;\n"); sb_append_cstr(sb, "uniform float y_offset;\n"); sb_append_cstr(sb, "vec4 map_color(vec3 rgb) {\n"); @@ -784,7 +788,7 @@ bool compile_node_func_into_fragment_shader(String_Builder *sb, Node *f) sb_append_cstr(sb, "{\n"); sb_append_cstr(sb, " float x = fragTexCoord.x*2.0 - x_offset;\n"); sb_append_cstr(sb, " float y = fragTexCoord.y*2.0 - y_offset;\n"); - sb_append_cstr(sb, " float t = sin(time);\n"); + sb_append_cstr(sb, " float t = amp*sin(freq*time);\n"); sb_append_cstr(sb, " finalColor = map_color("); if (!compile_node_into_fragment_expression(sb, f, 0)) return false; sb_append_cstr(sb, ");\n"); @@ -1118,6 +1122,8 @@ int main(int argc, char **argv) int time_loc = GetShaderLocation(shader, "time"); int x_offset_loc = GetShaderLocation(shader, "x_offset"); int y_offset_loc = GetShaderLocation(shader, "y_offset"); + int amp_loc = GetShaderLocation(shader, "amp"); + int freq_loc = GetShaderLocation(shader, "freq"); SetTargetFPS(fps); SetExitKey(KEY_NULL); @@ -1136,7 +1142,20 @@ int main(int argc, char **argv) float y_coord = 0; float x_zoom = 1; float y_zoom = 1; - + float amp = 1; + float freq = 1; + + printf("==============================================================================================\n" + "\tUse arrow keys to MOVE around\n" + "\tUse keys to ZOOM around\n" + "\tUse keys to ZOOM uniformly\n" + "\tUse keys to adjust AMPLITUDE (t variable)\n" + "\tUse keys to adjust FREQUENCY (t variable)\n" + "\tUse key to set everything to default\n" + "\tUse key to PAUSE\n" + "\tUse key to adjust the TIME (only works in pause)\n" + "\tUse key to get INFORMATION\n" + "==============================================================================================\n"); while (!WindowShouldClose()) { float w = GetScreenWidth(); float h = GetScreenHeight(); @@ -1146,6 +1165,9 @@ int main(int argc, char **argv) SetShaderValue(shader, time_loc, &time, SHADER_UNIFORM_FLOAT); SetShaderValue(shader, x_offset_loc, &x_zoom, SHADER_UNIFORM_FLOAT); SetShaderValue(shader, y_offset_loc, &y_zoom, SHADER_UNIFORM_FLOAT); + SetShaderValue(shader, amp_loc, &, SHADER_UNIFORM_FLOAT); + SetShaderValue(shader, freq_loc, &freq, SHADER_UNIFORM_FLOAT); + BeginShaderMode(shader); DrawTexturePro( default_texture, @@ -1154,6 +1176,12 @@ int main(int argc, char **argv) (Vector2){0}, 0, WHITE); EndShaderMode(); if (!pause) time += dt; + if ( pause && IsKeyPressed(KEY_Q)) { + time -= 0.5 * dt; + } + if (pause && IsKeyPressed(KEY_E)) { + time += 0.5 * dt; + } if (IsKeyPressed(KEY_R)) { ffmpeg = ffmpeg_start_rendering(width, height, fps); @@ -1163,42 +1191,90 @@ int main(int argc, char **argv) if (IsKeyPressed(KEY_SPACE)) { pause = !pause; } - if ( pause && IsKeyPressed(KEY_Q)) { - time -= 0.5*dt; + if (IsKeyPressed(KEY_O)) { + x_zoom = 1; + y_zoom = 1; + x_coord = 0; + y_coord = 0; + amp = 1; + freq = 1; } - if (pause && IsKeyPressed(KEY_E)) { - time += 0.5*dt; + if (IsKeyPressed(KEY_EQUAL) || GetCharPressed() == '?') { + printf("==============================================================================================\n" + + printf("pause : %s\n",pause ? "true" : "false"); + printf("time : %5.2lf\n",time); + + printf("rect : (%5.2lf,\t%5.2lf)\n\n",x_coord,y_coord); + + printf(" (%5.2lf,\t%5.2lf)\n\n",x_coord+x_zoom,y_coord+y_zoom); + + printf("zoom : (%5.2lf,\t%5.2lf)\n\n",x_zoom,y_zoom); + printf("amp : %5.2lf,\n",amp); + printf("freq : %5.2lf\n",freq); + + printf("seed : %d\n\n\n",seed); + + "\tUse arrow keys to MOVE around\n" + "\tUse keys to ZOOM around\n" + "\tUse keys to ZOOM uniformly\n" + "\tUse keys to adjust AMPLITUDE (t variable)\n" + "\tUse keys to adjust FREQUENCY (t variable)\n" + "\tUse key to set everything to default\n" + "\tUse key to PAUSE\n" + "\tUse key to adjust the TIME (only works in pause)\n" + "\tUse key to get INFORMATION\n" + "==============================================================================================\n"); + } - if (IsKeyPressed(KEY_W)) { + + + + if (IsKeyPressed(KEY_UP)) { y_coord += 0.01; } - if (IsKeyPressed(KEY_S)) { + if (IsKeyPressed(KEY_DOWN)) { y_coord -= 0.01; } - if (IsKeyPressed(KEY_A)) { + if (IsKeyPressed(KEY_LEFT)) { x_coord += 0.01; } - if (IsKeyPressed(KEY_D)) { + if (IsKeyPressed(KEY_RIGHT)) { x_coord -= 0.01; } - if (IsKeyPressed(KEY_I)) { + if (IsKeyPressed(KEY_W)) { y_zoom /= 1.2; } - if (IsKeyPressed(KEY_K)) { + if (IsKeyPressed(KEY_S)) { y_zoom *= 1.2; } - if (IsKeyPressed(KEY_J)) { + if (IsKeyPressed(KEY_A)) { x_zoom /= 1.2; } - if (IsKeyPressed(KEY_L)) { + if (IsKeyPressed(KEY_D)) { x_zoom *= 1.2; } - if (IsKeyPressed(KEY_U)) { + + if (IsKeyPressed(KEY_I) ) { + amp *= 1.2; + } + if (IsKeyPressed(KEY_K)) { + amp /= 1.2; + } + + if (IsKeyPressed(KEY_J)) { + freq /= 1.2; + } + if (IsKeyPressed(KEY_L)) { + freq *= 1.2; + } + + if (IsKeyPressed(KEY_G)) { x_zoom /= 1.2; y_zoom /= 1.2; } From 9c4c8e481b1728710655357e55088a3f57a514c4 Mon Sep 17 00:00:00 2001 From: Ekin Igdir Date: Mon, 18 Nov 2024 23:40:56 +0100 Subject: [PATCH 5/5] added a dodgy restart mechanism --- src/randomart.c | 50 ++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/randomart.c b/src/randomart.c index 227a313..b41c43d 100644 --- a/src/randomart.c +++ b/src/randomart.c @@ -1083,6 +1083,7 @@ int main(int argc, char **argv) const char *input_path = shift(argv, argc); + GUI: String_Builder src = {0}; if (!read_entire_file(input_path, &src)) return 1; @@ -1144,17 +1145,19 @@ int main(int argc, char **argv) float y_zoom = 1; float amp = 1; float freq = 1; + bool restart = false; printf("==============================================================================================\n" - "\tUse arrow keys to MOVE around\n" - "\tUse keys to ZOOM around\n" - "\tUse keys to ZOOM uniformly\n" - "\tUse keys to adjust AMPLITUDE (t variable)\n" - "\tUse keys to adjust FREQUENCY (t variable)\n" + "\tUse <↑←↓→> key to MOVE around\n" + "\tUse key to ZOOM around\n" + "\tUse key to ZOOM uniformly\n" + "\tUse key to adjust AMPLITUDE (t variable)\n" + "\tUse key to adjust FREQUENCY (t variable)\n" "\tUse key to set everything to default\n" "\tUse key to PAUSE\n" "\tUse key to adjust the TIME (only works in pause)\n" "\tUse key to get INFORMATION\n" + "\tUse key to start a new run\n" "==============================================================================================\n"); while (!WindowShouldClose()) { float w = GetScreenWidth(); @@ -1182,7 +1185,10 @@ int main(int argc, char **argv) if (pause && IsKeyPressed(KEY_E)) { time += 0.5 * dt; } - + if (IsKeyPressed(KEY_N)) { + restart = true; + break; + } if (IsKeyPressed(KEY_R)) { ffmpeg = ffmpeg_start_rendering(width, height, fps); time = 0; @@ -1200,7 +1206,7 @@ int main(int argc, char **argv) freq = 1; } if (IsKeyPressed(KEY_EQUAL) || GetCharPressed() == '?') { - printf("==============================================================================================\n" + printf("==============================================================================================\n"); printf("pause : %s\n",pause ? "true" : "false"); printf("time : %5.2lf\n",time); @@ -1215,19 +1221,21 @@ int main(int argc, char **argv) printf("seed : %d\n\n\n",seed); - "\tUse arrow keys to MOVE around\n" - "\tUse keys to ZOOM around\n" - "\tUse keys to ZOOM uniformly\n" - "\tUse keys to adjust AMPLITUDE (t variable)\n" - "\tUse keys to adjust FREQUENCY (t variable)\n" - "\tUse key to set everything to default\n" - "\tUse key to PAUSE\n" - "\tUse key to adjust the TIME (only works in pause)\n" - "\tUse key to get INFORMATION\n" - "==============================================================================================\n"); - - } + printf( + "\tUse <↑←↓→> key to MOVE around\n" + "\tUse key to ZOOM around\n" + "\tUse key to ZOOM uniformly\n" + "\tUse key to adjust AMPLITUDE (t variable)\n" + "\tUse key to adjust FREQUENCY (t variable)\n" + "\tUse key to set everything to default\n" + "\tUse key to PAUSE\n" + "\tUse key to adjust the TIME (only works in pause)\n" + "\tUse key to get INFORMATION\n" + "\tUse key to start a new run\n" + "==============================================================================================\n"); + } + @@ -1342,6 +1350,10 @@ int main(int argc, char **argv) EndDrawing(); } CloseWindow(); + if (restart){ + seed ^= seed >> 3 ; + goto GUI; + } return 0; }