#include #include #include #define MAXX 320 #define MAXY 240 #define SPOKES 1200 #define SPOKES2 600 #define XCENTER (MAXX/2) #define YCENTER ((MAXY - MAXY/2)/2) #define TEXTUREWIDTH 15 int main(void) { SDL_Surface *screen; SDL_Rect pixel; int shiftX, shiftY; static char wormImg[MAXX*MAXY]; static float spokeCalc[SPOKES], spokeCosCalc[SPOKES], spokeSinCalc[SPOKES]; static unsigned short texture[] = { 0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c, 0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c, 0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77, 0x3b77,0x3b77,0x3b77,0x4c1c,0x4c1c,0x3b77,0x21ed,0x21ed,0x21ed,0x21ed, 0x21ed,0x21ed,0x21ed,0x21ed,0x21ed,0x21ed,0x21ed,0x3b77,0x4c1c,0x4c1c, 0x3b77,0x21ed,0x08a5,0x08a5,0x08a5,0x08a5,0x08a5,0x08a5,0x08a5,0x08a5, 0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c,0x3b77,0x21ed,0x08a5,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c, 0x3b77,0x21ed,0x08a5,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c,0x3b77,0x21ed,0x08a5,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c, 0x3b77,0x21ed,0x08a5,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c,0x3b77,0x21ed,0x08a5,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c, 0x3b77,0x21ed,0x08a5,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c,0x3b77,0x21ed,0x08a5,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c, 0x3b77,0x21ed,0x08a5,0x08a5,0x08a5,0x08a5,0x08a5,0x08a5,0x08a5,0x08a5, 0x08a5,0x21ed,0x3b77,0x4c1c,0x4c1c,0x3b77,0x21ed,0x21ed,0x21ed,0x21ed, 0x21ed,0x21ed,0x21ed,0x21ed,0x21ed,0x21ed,0x21ed,0x3b77,0x4c1c,0x4c1c, 0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77,0x3b77, 0x3b77,0x3b77,0x3b77,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c, 0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c,0x4c1c }; SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(320, 240, is_cx?16:8, SDL_SWSURFACE); pixel.w = pixel.h = 2; int i, j, temp; float x, y, z, divCalcX, divCalcY, tempConst1, tempConst2; tempConst1 = M_PI / (float)SPOKES2; for (i = 0; i < SPOKES; i++) { spokeCalc[i] = i * tempConst1; spokeCosCalc[i] = cos(spokeCalc[i]); spokeSinCalc[i] = sin(spokeCalc[i]); } tempConst1 = (float)MAXX / (float)SPOKES2; tempConst2 = (float)MAXY / (float)SPOKES2; for (j = 1; j < SPOKES2 + 1; j++) { z = -1.0 + (log(2.0 * j / SPOKES2)); divCalcX = (float)(j * tempConst1); divCalcY = (float)(j * tempConst2); for (i = 0; i < SPOKES; i++) { x = divCalcX * spokeCosCalc[i]; y = divCalcY * spokeSinCalc[i]; y -= (25 * z); x += XCENTER; y += YCENTER; if ((x >= 0) && (x < MAXX) && (y >= 0) && (y < MAXY)) wormImg[(int)x + (int)y * MAXX] = (char)((i / 8) % TEXTUREWIDTH + TEXTUREWIDTH * ((j / 7) % TEXTUREWIDTH) & 0xff); } } while(!isKeyPressed(KEY_NSPIRE_ESC)) { for(pixel.y = 0; pixel.y < MAXY; pixel.y += 2) { for(pixel.x = 0; pixel.x < MAXX; pixel.x += 2) { SDL_FillRect(screen, &pixel, texture[wormImg[pixel.y * MAXX + pixel.x]]); } } SDL_Flip(screen); // Shifts texture right for(j = 0; j < TEXTUREWIDTH; j++) { temp = texture[(j+1) * TEXTUREWIDTH - 1]; for(i = TEXTUREWIDTH - 2; i > -1; i--) { texture[j * TEXTUREWIDTH + i + 1] = texture[j * TEXTUREWIDTH + i]; } texture[j * TEXTUREWIDTH] = temp; } // Shift texture up for(i = 0; i < TEXTUREWIDTH; i++) { temp = texture[i]; for(j = 1; j < TEXTUREWIDTH; j++) { texture[(j-1) * TEXTUREWIDTH + i] = texture[j * TEXTUREWIDTH +i]; } texture[TEXTUREWIDTH * TEXTUREWIDTH - TEXTUREWIDTH + i] = temp; } } SDL_Quit(); return 0; }