diff --git a/.gitignore b/.gitignore index f7dc836..33166be 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ auto-save-list tramp .\#* +shapes # Org-mode .org-id-locations diff --git a/01-one-shape/.game b/01-one-shape/.game new file mode 100755 index 0000000..f072024 Binary files /dev/null and b/01-one-shape/.game differ diff --git a/01-one-shape/Makefile b/01-one-shape/Makefile new file mode 100644 index 0000000..91697a4 --- /dev/null +++ b/01-one-shape/Makefile @@ -0,0 +1,22 @@ +PROG=shapes +CC=gcc +STD=c2x +SRC_FILES=main.c +OUT_DIR=./ +CFLAGS=-std=$(STD) -ggdb +EXPERIMENTAL_FLAGS=-pg -Ofast +LIBS=-lraylib -lGL -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lm -lpthread -ldl -lrt -lm + + +shapes: + $(CC) $(SRC_FILES) -o $(OUT_DIR)$@ $(CFLAGS) $(EXPERIMENTAL_FLAGS) $(LIBS) + +run: shapes + $(OUT_DIR)$(PROG) + +clean: + rm $(OUT_DIR)$(PROG) + + +.PHONY: shapes run clean + diff --git a/01-one-shape/main.c b/01-one-shape/main.c new file mode 100644 index 0000000..f91a5cf --- /dev/null +++ b/01-one-shape/main.c @@ -0,0 +1,153 @@ +#include +#include +#include +#include +#include +#include + +/* +Jedan oblik, jedna boja. Ovo je program koji mozda generise takvu sliku, mozda ne. +Radi na sansu, preko `chance` promenljive se kontrolise da li ce sansa da svi +budu isti oblici i boja, a verovatno nece biti. + +Svake sekunde se dodaje novi, svake sekunde postoji sansa da resenje ovog zadatka +propadne. + +Sada kada razmislim, ovo bas i ne radi tako, ali u nekom sirem smislu radi. Samo +sanse nisu to sto se misli da jesu. Bice neki bugfix. + +Dostupna je i 2D kamera. Tako da sto duze traje, ako se dovoljno odzumira greske +se i ne vide iako ce se kad tad pojaviti. + +Nisam se setio necega kreativnijeg +pod ovim ogranicenjima. + +EN: +One shape, one color. +This is a program that might generate such an image, maybe not. +It works based on chance, with the chance variable controlling whether everything will be the same shape and color, though it's unlikely. + +Every second, a new object is added, and each second there's a chance that the solution to this task will fail. + +Now that I think about it, this doesn't quite work as expected, but in a broader sense, it does. It's just that the chances aren't quite what one would think. There will be a bugfix. + +2D camera is also available. So the longer it lasts, if it's zoomed out enough mistakes +won't be seen even though they will eventually show up. + +I couldn't come up with something more creative under these constraints. +*/ + + +typedef struct Circle { + int radius; + int x; + int y; +} Circle; + + +int main(int argc, char *argv[]) { + const int SCREEN_WIDTH = 500; + const int SCREEN_HEIGHT = 500; + + InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "one color one shape"); + SetTargetFPS(60); + + Rectangle rects[100] = {0}; + Circle circles[100] = {0}; + + double previous_time = GetTime(); + double current_time = 0.0; + double update_draw_time = 0.0; + double wait_time = 0.0; + float delta_time = 0.0f; + float time_counter = 0.0f; + int target_fps = 60; + + Camera2D camera = {0}; + camera.target = (Vector2){ 0.0f, 0.0f }; + camera.offset = (Vector2){250.0f, 250.0f}; + camera.rotation = 0.0f; + camera.zoom = 1.0f; + + Vector2 prevMousePos = GetMousePosition(); + + srand(time(NULL)); + int rand_int = rand() % 101 + 1; + int chance = 10; + if(argc == 2) { + chance = atoi(argv[1]); + } + int current_objects=0; + + while(!WindowShouldClose()) { + float mouseDelta = GetMouseWheelMove(); + + float newZoom = camera.zoom + mouseDelta * 0.01f; + if (newZoom <= 0) + newZoom = 0.01f; + + camera.zoom = newZoom; + // Kod za 2D kameru od: + //https://gist.github.com/JeffM2501/3c7da5c2b7e078e254d673f91489c78f + // arhivirano: + Vector2 thisPos = GetMousePosition(); + + Vector2 delta = Vector2Subtract(prevMousePos, thisPos); + prevMousePos = thisPos; + + if (IsMouseButtonDown(0)) + camera.target = GetScreenToWorld2D(Vector2Add(camera.offset, delta),camera); + + time_counter += delta_time; + camera.zoom = expf(logf(camera.zoom) + ((float)GetMouseWheelMove()*0.1f)); + rand_int = rand() % 101 + 1; + + if(time_counter >= 1.0f) { + rand_int = rand() % 100 + 1; + if(rand_int < chance) { + rects[current_objects] =(Rectangle){current_objects*30, 0, 30, 30}; + } else { + circles[current_objects] = (Circle){.radius=30, .x=current_objects*30, 0}; + } + time_counter = 0.0f; + current_objects++; + } + + BeginDrawing(); + ClearBackground(RAYWHITE); + BeginMode2D(camera); + for(int i = 0; i 0) { + wait_time = (1.0f/(float)target_fps) - update_draw_time; + if (wait_time > 0.0) { + WaitTime((float)wait_time); + current_time = GetTime(); + delta_time = (float)(current_time - previous_time); + } + } + else { + delta_time = (float)update_draw_time; + } + previous_time = current_time; + } +} diff --git a/README.md b/README.md index 3b96cd3..29a5cb3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # genuary -genuary 2026 \ No newline at end of file +genuary 2026 + +# 01 one shape, one color