more
[ICEs.git] / 200089 / mandel.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include <complex.h>
5 #include <math.h>
6
7 const int MAXX = 1000, MAXY = 1000;
8
9 void draw(double re, double im, int its, int mits) {
10 //putchar(33 + its % 128);
11 struct pxl {
12 char a,b,c;
13 } p;
14 p.a = 255 * (1.0 - powf((float)its/(float)mits,1/3.0));
15 p.b = 255 * (1.0 - powf((float)((2*its)%(mits/5))/(float)(mits/5),1/3.0));
16 p.c = 255 * (1.0 - powf((float)((3*its)%(mits/3))/(float)(mits/3),1/3.0));
17 //write(stdout, &p, sizeof(p));
18 putchar(p.a);
19 putchar(p.b);
20 putchar(p.c);
21 };
22
23 void mandel(double complex Zin, double complex C, int mits) {
24 int its = 0;
25 int drwn = 0;
26 int px, py;
27 // const int MAXX = 80, MAXY = 40;
28
29 double complex Z = 0 + 0;
30
31 for (py = 0; py != MAXY; py++) {
32 for (px = 0; px != MAXX; px++) {
33 Z = 0;
34 C = 4.0 * ((double)px / (double)MAXX) - 2.0 + \
35 I * (4.0 * ((double)py / (double)MAXY) - 2.0);
36 // printf("re = %g im = %g\n",(float)(creal(Z)), (float)(cimag(Z)));
37 its = 0;
38 drwn = 0;
39 while (its < mits) {
40 Z = Z*Z + C;
41 its++;
42 // printf("re = %g im = %g\n",(float)(creal(Z)), (float)(cimag(Z)));
43 if (cabs(Z) > 2) {
44 draw(px, py, its, mits);
45 // putchar('x');
46 drwn = 1;
47 break;
48 };
49 };
50 if (!drwn) {
51 char p[]={0,0,0}; /*write(stdout,p,sizeof(p));*/
52 putchar(p[0]);
53 putchar(p[1]);
54 putchar(p[2]);
55 }; /*putchar(' ');*/
56 } //putchar('\n');
57 };
58 };
59
60 int main(void) {
61 printf("P6\n%i %i\n255\n",MAXX, MAXY);
62 mandel(0,0,400);
63 return 0;
64 };
65