commit 3cb38a12d9f2a989d2a3ffc0106e90c7d8972a0f Author: _N3m0 Date: Thu Mar 28 15:20:17 2024 +0100 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..89219dd --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2024 Hamza NANAHA + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..03c822f --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +$(shell mkdir -p build) + +all: + gcc -Wall -Wextra main.c -o build/main -lraylib -lm + +release: + gcc -Wall -Wextra -O3 -DRELEASE main.c -o build/main -lraylib -lm + +run: all + ./build/main diff --git a/README.md b/README.md new file mode 100644 index 0000000..762dcc5 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Fractouille + +![exemple](exemple.png) + +Small tree fractal. + +# Keybind + +- esc : quit +- d : decrease angle +- a or q : increase angle + +# Building + +```console +$ make +``` diff --git a/exemple.png b/exemple.png new file mode 100644 index 0000000..63f0827 Binary files /dev/null and b/exemple.png differ diff --git a/main.c b/main.c new file mode 100644 index 0000000..c0f5528 --- /dev/null +++ b/main.c @@ -0,0 +1,67 @@ +#include +#include + +#include "raylib.h" + +#define RAD_TO_DEG(rad) (rad) * (180 / PI) +#define DEG_TO_RAD(deg) (deg) / (180 / PI) + +#define COLOR ORANGE + +const Vector2 screen = {.x = 1000, .y = 1000}; + +void branche(Vector2 origin, float base_angle, float angle, float step, int level) +{ + if (level <= 0) + return; + + Vector2 dest = { + .x = origin.x + cos(DEG_TO_RAD(angle)) * step, + .y = origin.y - sin(DEG_TO_RAD(angle)) * step, + }; + DrawLineEx(origin, dest, level/6, COLOR); + + branche(dest, base_angle, angle + base_angle/2, step*3/4, level-1); + branche(dest, base_angle, angle - base_angle/2, step*3/4, level-1); +} + +void arbre(float angle, float step, float level) +{ + Vector2 origin = {screen.x/2, screen.y - 50}; + Vector2 dest = {origin.x, origin.y - step}; + DrawLineEx(origin, dest, level/4, COLOR); + + branche(dest, angle, 90.0f + angle/2, step/2, level); + branche(dest, angle, 90.0f - angle/2, step/2, level); +} + +int main(void) +{ + float angle = 90.0f; + + SetTraceLogLevel(LOG_ERROR); + InitWindow(screen.x, screen.y, "arbre"); + SetTargetFPS(60); + + while (!WindowShouldClose()) { + BeginDrawing(); + { + ClearBackground(BLACK); + + if (IsKeyDown(KEY_D)) + angle -= 0.7f; + if (IsKeyDown(KEY_A)) + angle += 0.7f; + + arbre(angle, screen.x/4, 16); + + printf(" %.02f \r", angle); + fflush(stdout); + } + EndDrawing(); + } + + CloseWindow(); + printf("\n"); + return 0; +}