/* Kääntäminen: gcc -o metaballs metaballs.c -O3 -ggdb -lSDL -lm */ #include #include #include #define RES_X 800 #define RES_Y 800 typedef struct metaball { int x, y; } metaball; typedef union { struct {unsigned char b, g, r;} rgb; Uint32 sdl; } unioncolor; #define pallot_count 5 metaball pallot[pallot_count] = {{0,0}}; unioncolor *pixelcoord(SDL_Surface *screen, int x, int y) { return (unioncolor *) ((Uint8 *)screen->pixels + y * screen->pitch + (x << 2)); } inline long calcfactor(int dx, int dy) { /* Range is 0 - 2^24 */ const long max = 0x1000000; long long div = dx * dx + dy * dy; if (div == 0) return max; return max / div; } inline long calctotal(int x, int y) { int i, dx, dy; long total = 0; for (i=0; ipixels, 255, 4 * RES_X * RES_Y); for (x=0; x t_max && topleft > t_max && bottomright > t_max && bottomleft > t_max)) continue; for (ix=x; ix treshold_min && total < treshold_max) { pixel = pixelcoord(screen, ix, iy); pixel->sdl = 0; } } } } } SDL_Flip(screen); } void reposition() { int cycle; int i; cycle = SDL_GetTicks() / 2; for (i=0; i 0) SDL_Delay(ticks); } return 0; }