summary refs log tree commit diff
path: root/minic/test/mandel.c
blob: 68049a3bfc9e0f438340eede2bc34a9896ddb893 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
void *malloc();
void *SDL_CreateWindow();
void *SDL_CreateRenderer();
int SDL_SetRenderDrawColor();
int SDL_RenderDrawPoint();
int SDL_RenderClear();
int SDL_RenderPresent();
int SDL_PollEvent();
int SDL_DestroyRenderer();
int SDL_DestroyWindow();
int SDL_Quit();
int SDL_Init();

void *win;
void *rnd;
int W;
int H;
int *col;

plot(int x, int y)
{
	int n;
	int fx;
	int fy;
	int zx;
	int zy;
	int nx;
	int ny;

	fx = (x - W/2)*4000 / W;
	fy = (y - H/2)*4000 / H;
	zx = fx;
	zy = fy;

	for (n=0; n<200; n++) {
		if (zx*zx + zy*zy > 4000000)
			break;
		nx = (zx*zx)/1000 - (zy*zy)/1000 + fx;
		ny = zx*zy/500 + fy;
		zx = nx;
		zy = ny;
	}
	n = col[n];
	SDL_SetRenderDrawColor(rnd, 100, n, n, 255);
	SDL_RenderDrawPoint(rnd, x, y);
	return 0;
}

main() {
	int c;
	int n;
	int x;
	int y;
	void *e;
	int *ie;

	W = 800;
	H = 800;
	SDL_Init(32);
	win = SDL_CreateWindow("Mandelbrot MiniC", 0, 0, W, H, 0);
	rnd = SDL_CreateRenderer(win, -1, 0);
	e = malloc(56);
	ie = e;
	col = malloc(201 * sizeof (int));
	c = 20;
	for (n=0; n<200; n++) {
		col[n] = c;
		c = c + (255-c)/8;
	}
	col[n] = 30;

	SDL_RenderClear(rnd);
	for (x=0; x<W; x++)
		for (y=0; y<H; y++)
			plot(x, y);
	SDL_RenderPresent(rnd);

	for (;;) {
		if (SDL_PollEvent(e)) {
			if (ie[0] == 769)
				break;
		}
	}

	SDL_DestroyRenderer(rnd);
	SDL_DestroyWindow(win);
	SDL_Quit();
}