1 /* Draw a Mandelbrot set, maximum magnification 10000000 times;
3 task t1(StartupObject s{initialstate}) {
4 //System.printString("task t1\n");
10 int h = height / group;
11 for(int i = 0; i < group; i++) {
12 Fractal fratal = new Fractal(i,
17 Image image = new Image(group){!finish};
19 taskexit(s{!initialstate});
22 task t2(Fractal fractal{run}) {
23 //System.printString("task t2\n");
25 // Now do the computation.
28 taskexit(fractal{!run, output});
31 //task t3(Image image{!finish}, Fractal fractal{output}) {
32 //System.printString("task t3\n");
34 // if(image.outputImage(fractal.pixels, fractal.id)) {
35 //System.printString("Finish!\n");
36 // taskexit(image{finish}, fractal{!output});
38 // taskexit(fractal{!output});
42 public class Fractal {
48 public int AppletWidth;
49 private int AppletHeight;
54 private float alen, blen;
62 public Fractal(int index,
68 this.AppletWidth = width;
69 this.AppletHeight = height;
70 this.amin = (float)-2.0;
71 this.amax = (float)1.0;
72 this.bmin = (float)-1.5;
73 this.bmax = (float)1.5;
74 this.alen = (float)3.0;//this.amax - this.amin;
75 this.blen = (float)3.0;//this.bmax - this.bmin;
81 int length = this.AppletWidth * this.AppletHeight / this.group;
82 this.pixels = new int[length];
83 int[] ps = this.pixels;
85 while (incr < length) {
86 ps[incr++] = this.alpha<<24 | 0x00<<16 | 0x00<<8 | 0xff;
88 Random rnd = new Random();
89 int maxint = (1<<32) - 1;
90 red = (int)(((float)rnd.nextInt()/maxint)*255);
91 green = (int)(((float)rnd.nextInt()/maxint)*255);
92 blue = (int)(((float)rnd.nextInt()/maxint)*255);
96 float amin = this.amin;
97 float amax = this.amax;
98 float bmin = this.bmin;
99 float bmax = this.bmax;
100 int appletWidth = this.AppletWidth;
101 int appletHeight = this.AppletHeight;
102 int times = this.times;
103 int alpha = this.alpha;
105 int blue = this.blue;
106 float a,b,x,y; //a--width, b--height
108 float adelta = (this.alen/appletWidth);
109 float bdelta = (this.blen/appletHeight);
110 float bspan = (this.blen/group);
111 int[] ps = this.pixels;
112 int length = ps.length;
114 int group = this.group;
115 float startb = bmin + bspan * id;
120 endb=bmin+bspan*(id+1);
122 for(a=amin;a<amax;a+=adelta) {
123 for(b=startb;b<endb;b+=bdelta) {
127 float x2 = (float)0.0;
128 float y2 = (float)0.0;
129 float xy = (float)0.0;
130 boolean finish = true; //(x2 + y2 <= 4.0) & (iteration != times);
132 float tmpy = (float)2.0*xy;
139 boolean tmpf = (x2 + y2 <= 4.0);
140 finish = tmpf & (iteration != times);
143 if(iteration<=times & iteration>0) {
144 scaleda=(int)((a - amin)*appletWidth/(amax - amin));
145 scaledb=(int)((b - bmin)*appletHeight/(bmax - bmin));
146 int index = (scaledb * appletWidth + scaleda - id) / group;
148 ps[index] = alpha<<24 | red<<16 | iteration<<8 | blue;
153 System.printString(count+"\n");
162 private int[][] pixels;
163 private String outputfile;
165 public Image(int g) {
168 this.pixels = new int[g][];
169 this.outputfile = new String("/scratch/fractal/image.dat");
172 public boolean outputImage(int[] pixels, int index) {
175 this.pixels[index] = pixels;
177 boolean isFinish = (this.group == this.counter);
180 /*FileOutputStream oStream = new FileOutputStream(outputfile, true);
181 //System.printString(new String(ps, 0, ps.length) + "\n");
182 oStream.write(ps, 0, ps.length);