diff --git a/src/randomart.c b/src/randomart.c index cf9755b..b41c43d 100644 --- a/src/randomart.c +++ b/src/randomart.c @@ -775,14 +775,20 @@ 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"); 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 t = sin(time);\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 = 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"); @@ -1077,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; @@ -1114,6 +1121,11 @@ 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"); + int amp_loc = GetShaderLocation(shader, "amp"); + int freq_loc = GetShaderLocation(shader, "freq"); + SetTargetFPS(fps); SetExitKey(KEY_NULL); Texture default_texture = { @@ -1124,8 +1136,29 @@ 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; + float x_zoom = 1; + float y_zoom = 1; + float amp = 1; + float freq = 1; + bool restart = false; + + printf("==============================================================================================\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(); float h = GetScreenHeight(); @@ -1133,15 +1166,29 @@ 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); + SetShaderValue(shader, amp_loc, &, SHADER_UNIFORM_FLOAT); + SetShaderValue(shader, freq_loc, &freq, SHADER_UNIFORM_FLOAT); + BeginShaderMode(shader); DrawTexturePro( default_texture, - (Rectangle){0, 0, 1, 1}, + (Rectangle){x_coord, y_coord, x_coord+x_zoom, y_coord+y_zoom}, (Rectangle){0, 0, w, h}, (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_N)) { + restart = true; + break; + } if (IsKeyPressed(KEY_R)) { ffmpeg = ffmpeg_start_rendering(width, height, fps); time = 0; @@ -1150,6 +1197,99 @@ int main(int argc, char **argv) if (IsKeyPressed(KEY_SPACE)) { pause = !pause; } + if (IsKeyPressed(KEY_O)) { + x_zoom = 1; + y_zoom = 1; + x_coord = 0; + y_coord = 0; + amp = 1; + freq = 1; + } + 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); + + 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"); + + } + + + + + if (IsKeyPressed(KEY_UP)) { + y_coord += 0.01; + } + if (IsKeyPressed(KEY_DOWN)) { + y_coord -= 0.01; + } + + if (IsKeyPressed(KEY_LEFT)) { + x_coord += 0.01; + } + if (IsKeyPressed(KEY_RIGHT)) { + x_coord -= 0.01; + } + + if (IsKeyPressed(KEY_W)) { + y_zoom /= 1.2; + } + if (IsKeyPressed(KEY_S)) { + y_zoom *= 1.2; + } + + if (IsKeyPressed(KEY_A)) { + x_zoom /= 1.2; + } + if (IsKeyPressed(KEY_D)) { + x_zoom *= 1.2; + } + + + 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; + } + if (IsKeyPressed(KEY_H)) { + x_zoom *= 1.2; + y_zoom *= 1.2; + } } else { if (time < max_render_length) { BeginTextureMode(screen); @@ -1210,6 +1350,10 @@ int main(int argc, char **argv) EndDrawing(); } CloseWindow(); + if (restart){ + seed ^= seed >> 3 ; + goto GUI; + } return 0; }