From cb4baa44798e10ab50a91cc797a050a832d481ac Mon Sep 17 00:00:00 2001 From: neingeist Date: Sat, 11 May 2013 13:10:00 +0200 Subject: [PATCH] more mandelbrot --- Makefile | 9 +++++++-- mandelbrot.c | 14 +++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index af9ef9c..867b9e3 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,16 @@ CFLAGS=-std=c99 -Wall -g INDENTOPTS=-kr --no-tabs --braces-on-func-def-line --indent-level2 -all: approximate-pi linked-list +.PHONY: all +all: approximate-pi linked-list mandelbrot +.PHONY: clean clean: - rm -f approximate-pi linked-list *~ + rm -f approximate-pi linked-list mandelbrot *~ .PHONY: indent indent: indent $(INDENTOPTS) *.c + +mandelbrot: mandelbrot.c + $(CC) $(CFLAGS) $(shell sdl-config --cflags) -o $@ $< $(shell sdl-config --libs) -lm diff --git a/mandelbrot.c b/mandelbrot.c index ae5a9d3..c55f32c 100644 --- a/mandelbrot.c +++ b/mandelbrot.c @@ -22,8 +22,8 @@ int main(int argc, char *argv[]) { printf("y = %d\n", y); } - float complex c = (3.0 * x / 640.0) - 2.0 - + I * ((2.0 * y / 480.0) - 1.0); + float complex c = ((3.0 * x / screen->w) - 2.0) + + I * ((2.0 * y / screen->h) - 1.0); bool diverges = false; float complex z = 0; @@ -36,17 +36,21 @@ int main(int argc, char *argv[]) { } } - Uint32 color = 0x00000000; + Uint32 color; if (diverges) { - color = 0x01010101 * it; + color = 0x00020304 * it; + } else { + color = 0x00000000; } pixels[i] = color; + if (y % 10 == 0) + SDL_Flip(screen); } if (SDL_MUSTLOCK(screen)) { SDL_UnlockSurface(screen); } - SDL_Flip(screen); /* XXX */ + SDL_Flip(screen); SDL_Delay(20000);