#include #include #include #include #include #include #define IMAGE_WIDTH 200 #define IMAGE_HEIGHT 200 #define X_MIN -1.5 #define X_MAX 0.5 #define Y_MIN -1 #define Y_MAX 1 #define MAX_ITERATIONS 200 SDL_Surface *screen = NULL; SDL_Color colours[MAX_ITERATIONS]; colours[0].r = 0; colours[0].g = 0; colours[0].b = 0; SDL_Surface *palette; palette = SDL_LoadBMP('palette.png'); int i; for(i = 0; i<=MAX_ITERATIONS; i++) { SDL_Color *rgb = SDL_GetRGB(palette, i, 0); //colours[i] = Color.new(@rgb.red,@rgb.green,@rgb.blue) } static void draw () { SDL_Flip (screen); SDL_Delay (1); } int main (int argc, char *argv[]) { char *msg; int done; /* Initialize SDL */ if (SDL_Init (SDL_INIT_VIDEO) < 0) { sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ()); MessageBox (0, msg, "Error", MB_ICONHAND); free (msg); exit (1); } atexit (SDL_Quit); /* Set 640x480 16-bits video mode */ screen = SDL_SetVideoMode (IMAGE_WIDTH, IMAGE_HEIGHT, 16, SDL_SWSURFACE | SDL_DOUBLEBUF); if (screen == NULL) { sprintf (msg, "Couldn't set 640x480x16 video mode: %s\n", SDL_GetError ()); MessageBox (0, msg, "Error", MB_ICONHAND); free (msg); exit (2); } SDL_WM_SetCaption ("C++/SDL Mandlebrot Fractal", NULL); done = 0; while (!done) { SDL_Event event; /* Check for events */ while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: break; case SDL_QUIT: done = 1; break; default: break; } } /* Draw to screen */ draw (); } return 0; }