#include #include #include"SDL.h" #define A 64 #define B 256 #define Z(a, b, c) a ## b ## c typedef Sint32 i; i p[A][4][B][2], d[4][B][2], q = 0, b[4][2], S, C, H, I, e, R, K, E = 1, w = 800, h = 600, G, u, t, s = SDL_HWSURFACE|SDL_DOUBLEBUF, P[4][3] = { {255, 16, 16}, {0, 255, 0}, {255, 255, 64}, {64, 128, 255} }; SDL_Event n; const SDL_VideoInfo *v; SDL_Surface *o; i O(i x, i y) { return (y - x) * (float)rand() / RAND_MAX + x; } void g(i z, i x, i y) { if( p[q][I][S][C] < z ) d[I][S][C] += O(x, y); if( p[q][I][S][C] > z ) d[I][S][C] -= O(x, y); e = d[I][S][C]; d[I][S][C] = e < -H ? -H : (e > H ? H : e); } void c(i x, i y, i z) { t = SDL_MapRGB(o->format, x * S / A, y * S / A, z * S / A); } #define r(type) \ { \ for(S = 1; S <= A; S++) \ { \ C = (q + S) % A; \ for(I = 0; I < 4; I++) \ { \ c(255, 255, 255); \ for(H = 0; H < B; H++) \ { \ if( H == 1 ) \ c(P[I][0], P[I][1], P[I][2]); \ \ e = p[C][I][H][0]; \ e >>= 16; \ if( e >= 0 && e < w ) \ { \ R = p[C][I][H][1]; \ R >>= 16; \ if( R >= 0 && R < h ) \ *(type*)((Uint8*)(o->pixels) + \ R * o->pitch + \ e * K) \ = (type)t; \ } \ } \ } \ } \ } int main(int x, char **y) { if( SDL_Init(SDL_INIT_VIDEO) < 0 ) puts("Unable to init SDL"); else { atexit(SDL_Quit); v = SDL_GetVideoInfo(); K = v->vfmt->BytesPerPixel; if( K - 2 && K - 4 ) puts("Unsupported pixel format"); else { if( x > 1 ) s |= SDL_FULLSCREEN; o = SDL_SetVideoMode(w, h, K * 8, s); if( o == NULL ) puts("Error initializing screen"); else { SDL_WM_SetCaption("Schierke", NULL); SDL_ShowCursor(SDL_DISABLE); srand(time(NULL)); for(I = 0; I < 4; I++) { for(S = 0; S < B; S++) { p[0][I][S][0] = O(0, w << 16); for(p[C = 0][I][S][1] = O(0, h << 16); C < 2; d[I][S][C++] = O(-3 << 16, 3 << 16)); } for(S = 1; S < A; S++) for(C = 0; C < B; C++) for(H = 0; H < 2; H++) p[S][I][C][H] = p[0][I][C][H]; b[I][0] = O(0, w << 16); b[I][1] = O(0, h << 16); } for(u = SDL_GetTicks(); E;) { u += 16; c(0, 0, 0); SDL_LockSurface(o); SDL_FillRect(o, NULL, t); if( o->format->BytesPerPixel == 4 ) r(Uint32) else r(Uint16) SDL_UnlockSurface(o); SDL_Flip(o); for(I = 0; I < 4; I++) { if( !O(0, 60) ) { b[I][0] = O(50 << 16, (w - 50) << 16); b[I][1] = O(50 << 16, (h - 50) << 16); } H = 2 << 16; g(b[I][S = C = 0], 16, 1 << 12); g(b[I][C = 1], 16, 1 << 12); H *= 2; for(S = 1; S < B; S++) { g(p[q][I][0][C = 0], 32, 3 << 11); g(p[q][I][0][C = 1], 32, 3 << 11); } H = (q + 1) % A; for(S = 0; S < B; S++) for(C = 0; C < 2; C++) p[H][I][S][C] = p[q][I][S][C] + d[I][S][C]; } for (q = H; SDL_PollEvent(&n);) if( n.type == SDL_KEYDOWN || n.type == SDL_QUIT ) E = 0; G = SDL_GetTicks(); if( G < u ) SDL_Delay(u - G); } SDL_FreeSurface(o); } } SDL_Quit(); } return 0; }