Created
June 8, 2010 00:48
-
-
Save robbrit/429443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This program uses SDL. | |
* To install: | |
* | |
* sudo apt-get install libsdl1.2-dev | |
* | |
* To compile: | |
* | |
* gcc -lSDL filename.c | |
* | |
*/ | |
#include <SDL/SDL.h> | |
// The size of the window | |
#define SIZE 800 | |
// number of iterations to do | |
#define ITERATIONS 1000000 | |
// start drawing after this many iterations | |
#define START_DRAWING (ITERATIONS - 100) | |
// the lower bound for a | |
#define LEFTMOST 3.45 | |
// the initial value of X | |
// note that this value doesn't actually matter that much, | |
// so long as it is between 0 and 1 | |
#define INITIAL_X 0.0001 | |
void plot_pixel(SDL_Surface * surface, int x, int y){ | |
*((Uint32*)surface->pixels + y * surface->w + x) = | |
SDL_MapRGB(surface->format, 0, 0, 0); | |
} | |
void render(SDL_Surface * screen){ | |
int i, j; | |
double a; | |
double x; | |
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); | |
for (i = 0; i < SIZE; i++){ | |
x = INITIAL_X; | |
// a goes from LEFTMOST to 4 | |
a = LEFTMOST + (double)i / (double)SIZE * (4.0 - LEFTMOST); | |
for (j = 0; j < ITERATIONS; j++){ | |
x = a * x * (1 - x); | |
if (j > START_DRAWING){ | |
plot_pixel(screen, i, SIZE - (int)(x * SIZE) - 1); | |
} | |
} | |
} | |
SDL_UpdateRect(screen, 0, 0, 0, 0); | |
} | |
int main(){ | |
SDL_Surface * screen; | |
SDL_Event evt; | |
SDL_Init(SDL_INIT_VIDEO); | |
screen = SDL_SetVideoMode(SIZE, SIZE, 32, SDL_HWSURFACE); | |
render(screen); | |
while(1){ | |
if (SDL_PollEvent(&evt)){ | |
if(evt.type == SDL_QUIT) break; | |
} | |
SDL_Delay(1); | |
} | |
SDL_Quit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment