cpaturing some makefile updates and have OoOJava print number of sites disjoint reach...
[IRC.git] / Robust / src / Benchmarks / Performance / Fractal.c
1 /*  Draw a Mandelbrot set, maximum magnification 10000000 times;
2  */
3 #include <math.h>
4 #ifdef RAW
5 #include <raw.h>
6 #else
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #endif
11
12 const int AppletWidth = 3200; 
13 const int AppletHeight = 3200;
14 int length;
15 const float amin = (float)-2.0;
16 const float amax = (float)1.0;
17 const float bmin = (float)-1.5;
18 const float bmax = (float)1.5;
19 const float alen = (float)3.0;
20 const float blen = (float)3.0;
21 const int times = 255;
22 int alpha = 0xff;
23 int red = 0xff;
24 int green = 0xff;
25 int blue = 0xff;
26 int* pixels;
27
28 void begin(void);
29 void run(void);
30
31 #ifndef RAW
32 int main(int argc, char **argv) {
33   int option;
34
35   begin();
36   return 0;
37 }
38 #endif
39
40 void begin(void){
41     length = AppletWidth * AppletHeight;
42     pixels = (int*)malloc(sizeof(int) * length);;
43         int incr=0;
44         while (incr < length) {
45             pixels[incr++] = alpha<<24 | 0x00<<16 | 0x00<<8 | 0xff;
46         }
47         int maxint = RAND_MAX;
48         red   = (int)(((float)rand()/maxint)*255);
49         green = (int)(((float)rand()/maxint)*255);
50         blue  = (int)(((float)rand()/maxint)*255);
51     run();
52     
53     free(pixels);
54
55 #ifdef RAW
56     raw_test_pass(raw_get_cycle());
57         raw_test_done(1);
58 #endif
59 }
60
61 void run () {
62         float a,b,x,y; //a--width, b--height
63         int scaleda,scaledb;
64         float adelta = (float)(alen/AppletWidth);
65         float bdelta = (float)(blen/AppletHeight);
66         for(a=amin;a<amax;a+=adelta) {
67             for(b=bmin;b<bmax;b+=bdelta) {
68                     x=(float)0.0;
69                     y=(float)0.0;
70                 int iteration=0;
71                 float x2 = (float)0.0;
72                 float y2 = (float)0.0;
73                     float xy = (float)0.0;
74                     int finish = 1; //(x2 + y2 <= 4.0) & (iteration != times);
75                     while(finish) {
76                         float tmpy = (float)2.0*xy;
77                         x = x2 - y2 + a;
78                         y = tmpy + b;
79                         x2 = x*x;
80                         y2 = y*y;
81                         xy = x*y;
82                         iteration++;
83                         int tmpf = (x2 + y2 <= 4.0);
84                         finish = tmpf & (iteration != times);
85                     }
86                     if(iteration<=times & iteration>0) {
87                         scaleda=(int)((a - amin)*AppletWidth/(amax - amin));
88                         scaledb=(int)((b - bmin)*AppletHeight/(bmax - bmin));
89                         int index = scaledb * AppletWidth + scaleda;
90                         pixels[index] = alpha<<24 | red<<16 | iteration<<8 | blue;
91                     }
92             }
93         }
94         
95         // output image
96 }