This commit is contained in:
_N3m0 2024-03-28 15:20:17 +01:00
commit 3cb38a12d9
6 changed files with 115 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/*

20
LICENSE Normal file
View File

@ -0,0 +1,20 @@
Copyright (c) 2024 Hamza NANAHA <hamza.nanaha@hotmail.com>
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.

10
Makefile Normal file
View File

@ -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

17
README.md Normal file
View File

@ -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
```

BIN
exemple.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

67
main.c Normal file
View File

@ -0,0 +1,67 @@
#include <stdio.h>
#include <math.h>
#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;
}