diff options
| author | iceyrazor <iceyrazor@mailfence.com> | 2026-03-08 01:48:04 -0600 |
|---|---|---|
| committer | iceyrazor <iceyrazor@mailfence.com> | 2026-03-08 01:48:04 -0600 |
| commit | 35e376baba0afb032e34b46b2ffe53cf6bd4575e (patch) | |
| tree | ec9d2dfa6813555b8a6930481f4923199a74e963 | |
main
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | LICENSE | 54 | ||||
| -rw-r--r-- | README.md | 21 | ||||
| -rwxr-xr-x | build.sh | 19 | ||||
| -rw-r--r-- | fish.png | bin | 0 -> 38751 bytes | |||
| -rwxr-xr-x | src/.clangd | 2 | ||||
| -rw-r--r-- | src/config.h | 10 | ||||
| -rw-r--r-- | src/global_objects.c | 72 | ||||
| -rwxr-xr-x | src/main.c | 133 | ||||
| -rwxr-xr-x | src/objects.c | 120 | ||||
| -rwxr-xr-x | src/objects.h | 49 |
11 files changed, 481 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9de98d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/** @@ -0,0 +1,54 @@ +The Giant Penis License (GPL) + +Copyright (c) 2026 iceyrazor + + ▄▄██▄██▄▄ + ▄█ █ █▄ + ▄█ █▄ + █ █ + █ █ + █ █ + █ █ + █ █ + █▄ █ ▄█ + █ ▄▄▄ █ + █ █ + █ █ + █ █ + █ █ + █ █ + █ █ + █ █ + █ █ + █ █ + █ █ + █ █ + █ █ + ▄████▄█ █▄████▄ + ▄█ █▄ + █ █ +█ █ +█ █ +█ █ +█ ▄▄█▄▄ █ + █ █ █ █ + █▄ ▄█ █▄ ▄█ + █▄▄▄▄▄█ █▄▄▄▄▄█ + +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/README.md b/README.md new file mode 100644 index 0000000..79d4971 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# dactal fish + +just a small C SDL2 project to render the patreon +list as a animation from a textfile. + +## requirements + +- clang +- sdl2 +- sdl2_ttf +- sdl2_image +- sdl2_gfx + +## usage + +- edit ``obj_n`` to the amount of users/lines in ``src/config.h``. +- run ``./build.sh`` +- make a file called ``bin/patreons.txt`` +- seperate patreons by line +- cd ``bin/`` +- run ``./dacc_fish`` diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..3f16adf --- /dev/null +++ b/build.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +DEBUG="" +LIB="-Ilib/ -lSDL2_gfx -lSDL2_ttf -lSDL2_image" + +[ ! -d "bin" ] && mkdir bin + +while getopts "d" opt; do + case "$opt" in + d) DEBUG="-Wall -fsanitize=address -g" + ;; + esac +done + +shift $((OPTIND-1)) +[ "${1:-}" = "--" ] && shift + +printf "\n\nmaking project\n" +clang -o "bin/dacc_fish" src/main.c $LIB `sdl2-config --cflags --libs` -lm $DEBUG diff --git a/fish.png b/fish.png Binary files differnew file mode 100644 index 0000000..c9ee0ac --- /dev/null +++ b/fish.png diff --git a/src/.clangd b/src/.clangd new file mode 100755 index 0000000..8d72125 --- /dev/null +++ b/src/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-lgfx] diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..3c2b7b2 --- /dev/null +++ b/src/config.h @@ -0,0 +1,10 @@ +#ifndef iconfig +#define iconfig + +#define obj_n 200 +#define fontfile "/usr/share/fonts/TTF/BigBlueTerm437NerdFont-Regular.ttf" +#define fontsize 80 +#define fish_speed 0.003 +#define scroll_speed 7 + +#endif diff --git a/src/global_objects.c b/src/global_objects.c new file mode 100644 index 0000000..2e3f2fd --- /dev/null +++ b/src/global_objects.c @@ -0,0 +1,72 @@ +#ifndef global_objects +#define global_objects + +#include <math.h> +#include <stdlib.h> + +#define flaot float + +typedef struct { + float x; + float y; +} Point; + +void point_add(Point *A, Point *B){ + A->x = A->x + B->x; + A->y = A->y + B->y; +} + +void point_sub(Point *A, Point *B){ + A->x = A->x - B->x; + A->y = A->y - B->y; +} + +void point_mul(Point *A, Point *B){ + A->x = A->x * B->x; + A->y = A->y * B->y; +} + +void point_div(Point *A, Point *B){ + A->x = A->x / B->x; + A->y = A->y / B->y; +} + +float magnitude(flaot x, flaot y) { + return sqrt((pow(x,2) + pow(y,2))); +} + +void point_set_mag(Point *point, float mag){ + flaot getmag = magnitude(point->x, point->y); + flaot rx = (point->x / getmag) * mag; + flaot ry = (point->y / getmag) * mag; + + point->x = rx; + point->y = ry; +} + +void point_limit(Point *point, float mag){ + flaot getmag = magnitude(point->x, point->y); + flaot rx, ry; + if (getmag > mag){ + rx = (point->x / getmag) * mag; + ry = (point->y / getmag) * mag; + } else { + rx = point->x; + ry = point->y; + } + + point->x = rx; + point->y = ry; +} + +float RandomFloat(float min, float max){ + return ((max - min) * ((float)rand() / (double)RAND_MAX)) + min; +} + +float constrain(float val, float min, float max){ + if(val > max) val=max; + else if(val < min) val=min; + return val; +} + +#endif diff --git a/src/main.c b/src/main.c new file mode 100755 index 0000000..eadda29 --- /dev/null +++ b/src/main.c @@ -0,0 +1,133 @@ +#include <SDL2/SDL_render.h> +#include <SDL2/SDL_timer.h> +#include <SDL2/SDL_ttf.h> +#include <SDL2/SDL_video.h> +#include <stdio.h> +#include <stdbool.h> +#include <time.h> +#include <pthread.h> +#include <SDL2/SDL.h> +#include <SDL2/SDL_ttf.h> + +bool running=true; + +#include "config.h" +#include "objects.h" +#include "objects.c" + +#define PROJECT_NAME "dacctal fish" + +int main(int argc, char *argv[]) +{ + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) + SDL_Log("SDL fails to initialize! %s\n", SDL_GetError()); + + if (TTF_Init() < 0){ + SDL_Log("SDL fails to initialize ttf! %s\n", SDL_GetError()); + } + + int startw=1920; + int starth=1080; + + SDL_Window *window = SDL_CreateWindow(PROJECT_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, startw, starth, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); + if (!window) { + printf("Failed to create window: %s\n", SDL_GetError()); + } + SDL_Renderer *renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_SOFTWARE); + if (!renderer) { + printf("Failed to create renderer: %s\n", SDL_GetError()); + } + + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); + + srand(time(NULL)); + TEXT obj_storage[obj_n]; + + STUFFS stuff = { + startw, + starth, + window, + renderer, + false, + 0, + 0, + (OBJECT){}, + 0, + false, + }; + + //EDIT this to your font you want to use + stuff.font = TTF_OpenFont(fontfile, fontsize); + + init_stuffs(startw,starth,obj_storage,&stuff); + + for (int i = 0; i < obj_n; i++) + stuff.obj.txtobj[i] = &obj_storage[i]; + + + bool window_visible; + Uint32 lastUpdate = 0; + SDL_Event e; + while (!stuff.quit) { + while (SDL_PollEvent(&e)) { + if (e.type == SDL_QUIT) { + stuff.quit = true; + } + else if(e.type == SDL_MOUSEBUTTONDOWN){ + if(e.button.button==SDL_BUTTON_LEFT){ + stuff.mousedown=true; + } else if(e.button.button==SDL_BUTTON_RIGHT){ + } + } else if(e.type==SDL_MOUSEBUTTONUP){ + stuff.mousedown=false; + } else if (e.type == SDL_WINDOWEVENT) { + if (e.window.event == SDL_WINDOWEVENT_MINIMIZED || + e.window.event == SDL_WINDOWEVENT_HIDDEN) { + + window_visible = false; + } + else if (e.window.event == SDL_WINDOWEVENT_SHOWN || + e.window.event == SDL_WINDOWEVENT_RESTORED || + e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { + + window_visible = true; + } + } + stuff.mx=e.button.x; + stuff.my=e.button.y; + } + + if(!window_visible){ + SDL_Delay(50); + continue; + } + + Uint64 start = SDL_GetPerformanceCounter(); + Uint32 current=SDL_GetTicks(); + stuff.dt = (current - lastUpdate); + draw(&stuff); + lastUpdate=current; + + Uint64 end = SDL_GetPerformanceCounter(); + float elapsedMS = (end - start) / (float)SDL_GetPerformanceFrequency() * 1000.0f; + + elapsedMS=floor(16.666f - elapsedMS); + if (elapsedMS > 500) elapsedMS=500; + if (elapsedMS < 0) elapsedMS=0; + SDL_Delay(elapsedMS); + } + + running=false; + + for (int i = 0; i < obj_n; i++) + SDL_DestroyTexture(stuff.obj.txtobj[i]->texture); + TTF_CloseFont(stuff.font); + TTF_Quit(); + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_Quit(); + + return 0; +} diff --git a/src/objects.c b/src/objects.c new file mode 100755 index 0000000..707d908 --- /dev/null +++ b/src/objects.c @@ -0,0 +1,120 @@ +#include <SDL2/SDL_render.h> +#include <stdbool.h> +#include <SDL2/SDL.h> +#include <SDL2/SDL_video.h> +#include <SDL2/SDL2_gfxPrimitives.h> +#include <SDL2/SDL_ttf.h> +#include <SDL2/SDL_image.h> +#include <stdlib.h> + +#include "config.h" +#include "global_objects.c" +#include "objects.h" + +void constructor(STUFFS *stuff, TEXT *text, int i, char *text_buf){ + SDL_Color color={ + 244,222,205 + }; + int w, h; + TTF_SizeUTF8(stuff->font,text_buf,&w,&h); + SDL_Rect textRect={ + 0,0,w,h + }; + textRect.x=(stuff->width/2)-(textRect.w/2); + textRect.y=(stuff->height/2)-(textRect.h/2); + SDL_Surface *textSurface = TTF_RenderUTF8_Solid_Wrapped(stuff->font, text_buf, color, textRect.w); + if(!textSurface){ + fprintf(stderr,"ERROR WITH TEXT SURFACE\n"); + exit(EXIT_FAILURE); + } + SDL_Texture *texture = SDL_CreateTextureFromSurface(stuff->renderer, textSurface); + SDL_FreeSurface(textSurface); + if(!texture){ + fprintf(stderr,"ERROR WITH TEXTURE\n"); + exit(EXIT_FAILURE); + } + + text->texture=texture; + text->textRect=textRect; + + text->obj.pos.x=0; + text->obj.pos.y=textRect.y+(float)textRect.h/2; + + SDL_Rect fishRect={ 0,0,100,100 }; + fishRect.y=(stuff->height/2)-(fishRect.h/2); + text->obj.fishRect=fishRect; + SDL_Texture *textllure; + textllure=IMG_LoadTexture(stuff->renderer,"../fish.png"); + if(!texture){ + fprintf(stderr,"FAILED TO LOAD THE FUCKING FISH\n"); + exit(EXIT_FAILURE); + } + + text->obj.fish=textllure; + text->pos.y=i*(fishRect.h+20)+stuff->height; +} + +void init_stuffs(int w, int h, TEXT *txt, STUFFS *stuff){ + char text_buf[256]; + FILE* file=fopen("patreons.txt","r"); + for (int i=0; i<obj_n; i++){ + fgets(text_buf,sizeof(text_buf),file); + constructor(stuff, &txt[i], i, text_buf); + } +} + +void update(STUFFS *stuff, TEXT *text,int i){ + i=i*30; + text->obj.counter+=stuff->dt*fish_speed; + text->obj.pos.x=(cos((double)text->obj.counter+i)*((float)text->textRect.w/2+80))+(text->textRect.x+(float)text->textRect.w/2); + text->obj.fishRect.x=text->obj.pos.x - (float)text->obj.fishRect.w/2; + + text->obj.fishRect.w=(sin(((double)text->obj.counter+i-20)*2)+1)*50; + + if(text->obj.pos.x > text->obj.lastx){ + text->obj.dir=1; + } else { + text->obj.dir=-1; + } + + text->textRect.y=text->pos.y-(float)text->textRect.h/2; + text->obj.fishRect.y=text->pos.y-(float)text->obj.fishRect.h/2; + text->pos.y=text->pos.y-scroll_speed; + + text->obj.lastx=text->obj.pos.x; +} + +void show(STUFFS *stuff, TEXT *text){ + if(text->pos.y > 0 && text->pos.y < stuff->height){ + int err2=SDL_RenderCopy(stuff->renderer,text->texture,NULL, &text->textRect); + if(err2!=0){ + SDL_Log("SDL Render Copy Failed! %s\n", SDL_GetError()); + } + + SDL_RendererFlip flip = SDL_FLIP_NONE; + Uint8 alpha=255; + if(text->obj.dir==-1){ + flip=SDL_FLIP_HORIZONTAL; + alpha=70; + } + + SDL_SetTextureAlphaMod(text->obj.fish, alpha); + SDL_RenderCopyEx(stuff->renderer,text->obj.fish, NULL, &text->obj.fishRect, 0, &(SDL_Point){(float)text->obj.fishRect.w/2,0}, flip); + } +} + +void draw(STUFFS *stuff){ + SDL_SetRenderDrawColor(stuff->renderer,15,15,15,255); + SDL_RenderClear(stuff->renderer); + + for (int i=0; i<obj_n; i++){ + update(stuff,stuff->obj.txtobj[i],i); + show(stuff,stuff->obj.txtobj[i]); + } + + if(stuff->obj.txtobj[obj_n-1]->pos.y < 0){ + stuff->quit=true; + } + + SDL_RenderPresent(stuff->renderer); +} diff --git a/src/objects.h b/src/objects.h new file mode 100755 index 0000000..c949b6a --- /dev/null +++ b/src/objects.h @@ -0,0 +1,49 @@ +#ifndef objects +#define objects + +#include <stdio.h> +#include <stdbool.h> +#include <SDL2/SDL.h> +#include <SDL2/SDL_ttf.h> +#include <SDL2/SDL_image.h> +#include "global_objects.c" +#include "config.h" + +#define flaot float + +typedef struct OBJECT_INER { + Point pos; + float lastx; + int dir; + double counter; + SDL_Texture *fish; + SDL_Rect fishRect; +} OBJECT_INER; + +typedef struct TEXT { + Point pos; + char *text; + SDL_Rect textRect; + SDL_Texture *texture; + OBJECT_INER obj; +} TEXT; + +typedef struct OBJECT { + TEXT *txtobj[obj_n]; +} OBJECT; + +typedef struct{ + int width; + int height; + SDL_Window* window; + SDL_Renderer* renderer; + bool mousedown; + int mx; + int my; + OBJECT obj; + Uint32 dt; + bool quit; + TTF_Font *font; +} STUFFS; + +#endif |
