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 int[] ps = this.pixels;
111 int length = ps.length;
113 int group = this.group;
114 float startb = bmin + bdelta * id;
116 if(id + 1 == group) {
119 endb = bmax + bdelta * id;
121 float bspan = bdelta * group;
122 for(a=amin;a<amax;a+=adelta) {
123 for(b=startb;b<endb;b+=bspan) {
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);
142 if(iteration<=times & iteration>0) {
143 scaleda=(int)((a - amin)*appletWidth/(amax - amin));
144 scaledb=(int)((b - bmin)*appletHeight/(bmax - bmin));
145 int index = (scaledb * appletWidth + scaleda - id) / group;
147 ps[index] = alpha<<24 | red<<16 | iteration<<8 | blue;
160 private int[][] pixels;
161 private String outputfile;
163 public Image(int g) {
166 this.pixels = new int[g][];
167 this.outputfile = new String("/scratch/fractal/image.dat");
170 public boolean outputImage(int[] pixels, int index) {
173 this.pixels[index] = pixels;
175 boolean isFinish = (this.group == this.counter);
178 /*FileOutputStream oStream = new FileOutputStream(outputfile, true);
179 //System.printString(new String(ps, 0, ps.length) + "\n");
180 oStream.write(ps, 0, ps.length);