#include #include #include #include SDL_Surface *screen; nSDL_Font *font; SDL_bool done = SDL_FALSE; #define MANDEL_VERSION "1.0a" int PIXELZOOM = 1; int SPEED_UP = 1; #define SCR_WIDTH 320 #define SCR_HEIGHT 240 int SCR_WID_PIXEL; int SCR_HEI_PIXEL; int MAX_ITERATION; float cr, ci; Uint32 timerstart; Uint32 timerend; bool INFO_ON_SCREEN = SDL_TRUE; void init_SDL(void) { if(SDL_Init(SDL_INIT_VIDEO) == -1) { printf("Sorry, can't init SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } screen = SDL_SetVideoMode(320, 240, has_colors ? 16 : 8, SDL_SWSURFACE); if(screen == NULL) { printf("Sorry, can't init display: %s\n", SDL_GetError()); SDL_Quit(); exit(EXIT_FAILURE); } SDL_ShowCursor(SDL_DISABLE); font = nSDL_LoadFont(NSDL_FONT_TINYTYPE, 255, 255, 255); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); } void quit(void) { SDL_Quit(); } void draw_fractal_Julia_Quick( void ) { float zr, zi; int u; int maxiter = MAX_ITERATION; float tmp,zr2,zi2; float xmin, xmax, ymin, ymax; float xinc, yinc; xmin = -1.6f; xmax = 1.6f; ymin = -1.2f; ymax = 1.2f; xinc = (xmax-xmin)/SCR_WID_PIXEL; yinc = (ymax-ymin)/SCR_HEI_PIXEL; for(int j=0; j<=SCR_HEI_PIXEL/2; j++) { for(int i=0; i<=SCR_WID_PIXEL; i++) { zr=xmin+i*xinc; zi=ymax-j*yinc; zi2=zi*zi; zr2=zr*zr; u=0; while(((zr2+zi2)<4) && (u1) SPEED_UP--; break; case SDLK_5: if (PIXELZOOM>1) PIXELZOOM--; break; case SDLK_6: if (PIXELZOOM<5) PIXELZOOM++; break; case SDLK_ESCAPE: done = SDL_TRUE; break; default: break; } SCR_WID_PIXEL = (SCR_WIDTH/PIXELZOOM); SCR_HEI_PIXEL = (SCR_HEIGHT/PIXELZOOM); MAX_ITERATION = (256/SPEED_UP); timerstart = SDL_GetTicks(); draw_fractal_Julia_Quick(); timerend = SDL_GetTicks(); if (INFO_ON_SCREEN) { nSDL_DrawString( screen, font, 5, 5, "Dt= %d ms", timerend-timerstart ); nSDL_DrawString( screen, font, 5, 15, "Cr= %f", cr ); nSDL_DrawString( screen, font, 5, 25, "Ci= %f", ci ); nSDL_DrawString( screen, font, 5, 35, "IT = %d", MAX_ITERATION/SPEED_UP ); nSDL_DrawString( screen, font, 5, 45, "[%dx%dpx]", PIXELZOOM, PIXELZOOM ); } SDL_Flip(screen); } int main(void) { SDL_Event event; SCR_WID_PIXEL = SCR_WIDTH/PIXELZOOM; SCR_HEI_PIXEL = SCR_HEIGHT/PIXELZOOM; MAX_ITERATION = 256/SPEED_UP; init_SDL(); cr=0.285f; ci=0.010f; Uint32 timerstart = SDL_GetTicks(); draw_fractal_Julia_Quick(); Uint32 timerend = SDL_GetTicks(); nSDL_DrawString( screen, font, 5, 5, "Dt= %d ms", timerend-timerstart ); nSDL_DrawString( screen, font, 5, 15, "Cr= %f", cr ); nSDL_DrawString( screen, font, 5, 25, "Ci= %f", ci ); nSDL_DrawString( screen, font, 5, 35, "IT = %d", MAX_ITERATION/SPEED_UP ); nSDL_DrawString( screen, font, 5, 45, "[%dx%dpx]", PIXELZOOM, PIXELZOOM ); SDL_Flip(screen); while(!done) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: handle_keydown(event.key.keysym.sym); break; default: break; } } } nSDL_FreeFont(font); quit(); return EXIT_SUCCESS; }