no mul->shl as it confuses address matching
[qbe.git] / minic / test / mandel.c
blob68049a3bfc9e0f438340eede2bc34a9896ddb893
1 void *malloc();
2 void *SDL_CreateWindow();
3 void *SDL_CreateRenderer();
4 int SDL_SetRenderDrawColor();
5 int SDL_RenderDrawPoint();
6 int SDL_RenderClear();
7 int SDL_RenderPresent();
8 int SDL_PollEvent();
9 int SDL_DestroyRenderer();
10 int SDL_DestroyWindow();
11 int SDL_Quit();
12 int SDL_Init();
14 void *win;
15 void *rnd;
16 int W;
17 int H;
18 int *col;
20 plot(int x, int y)
22 int n;
23 int fx;
24 int fy;
25 int zx;
26 int zy;
27 int nx;
28 int ny;
30 fx = (x - W/2)*4000 / W;
31 fy = (y - H/2)*4000 / H;
32 zx = fx;
33 zy = fy;
35 for (n=0; n<200; n++) {
36 if (zx*zx + zy*zy > 4000000)
37 break;
38 nx = (zx*zx)/1000 - (zy*zy)/1000 + fx;
39 ny = zx*zy/500 + fy;
40 zx = nx;
41 zy = ny;
43 n = col[n];
44 SDL_SetRenderDrawColor(rnd, 100, n, n, 255);
45 SDL_RenderDrawPoint(rnd, x, y);
46 return 0;
49 main() {
50 int c;
51 int n;
52 int x;
53 int y;
54 void *e;
55 int *ie;
57 W = 800;
58 H = 800;
59 SDL_Init(32);
60 win = SDL_CreateWindow("Mandelbrot MiniC", 0, 0, W, H, 0);
61 rnd = SDL_CreateRenderer(win, -1, 0);
62 e = malloc(56);
63 ie = e;
64 col = malloc(201 * sizeof (int));
65 c = 20;
66 for (n=0; n<200; n++) {
67 col[n] = c;
68 c = c + (255-c)/8;
70 col[n] = 30;
72 SDL_RenderClear(rnd);
73 for (x=0; x<W; x++)
74 for (y=0; y<H; y++)
75 plot(x, y);
76 SDL_RenderPresent(rnd);
78 for (;;) {
79 if (SDL_PollEvent(e)) {
80 if (ie[0] == 769)
81 break;
85 SDL_DestroyRenderer(rnd);
86 SDL_DestroyWindow(win);
87 SDL_Quit();