/* Filename: fract3.c */ #include extern double sqrt(); int contrl[12], intin[256], ptsin[256], intout[256], ptsout[256]; int x_boundary; int y_boundary; double x_change; double y_change; double start_x; double start_y; double x_realpart; double y_imagpart; double x_plus_y_squared; double window_size; double temp_x,temp_y,temp1,temp2,temp3; double x,y,tempr; int i,plot_x,plot_y,count,num_random; int dummy,handle,pxy[4],kbak; int rgb_in[3],clr_count; int mx,my,width,height; int pen_color; char decimal[80]; main() { x=0.50001; y=0.; /* The following is the setup to use the VDI and AES */ /* Set the system up to do GEM calls*/ /* the appl_init() call initials the application, and */ /* is required for us to use GEM/VDI. */ appl_init(); /* Get the handle of the desktop */ /* The 'handle' is the way we refer to a GEM virtual device, */ /* without having to know what that device is, how it works */ /* internally, or even what type of device it is (screen, */ /* plotter, or something else.). We can use GEM calls, such as */ /* line drawing, fill, and plot commands, without regards as to */ /* how those commands are actually implemented, or how they */ /* show up. Notice also that later on we read the device's */ /* resolution, in terms of pixels. This allows us to write */ /* screen resolution independent code, which will work on all */ /* current and future versions of the ST, (both b/w and color) */ /* since although the program plots points, it only plots points */ /* within the capable resolution of the device... HIGHLY */ /* RECOMMENDED as a way of writing code, sinc it ensures */ /* future compability, with very little extra work. */ handle=graf_handle(&width,&height,&dummy,&dummy); /* Open the workstation. */ /* This does a series of setup commands, which initial the */ /* physical device, set up what kind of write mode we're in, */ /* and performs other random stuff. Read the GEM VDI programmer's */ /* reference guide for further info. */ for (i=1; i<10; ++i) intin[i] = i; intin[10] = 2; /* This opens the device as a virtual workstation... See GEM VDI. */ v_opnvwk(intin, &handle, intout); /* read in the device's actual screen resolution here, and save */ /* it for future use... */ pxy[0]=0; pxy[1]=0; pxy[2]=intout[0]; pxy[3]=intout[1]; x_boundary=pxy[2]/2; y_boundary=pxy[3]/2; /* This command sets up automatic clipping by the device. */ /* This means that any point drawn outside the screen, in */ /* pixel coordinates, will simply not show up, but will also */ /* not detonate the program, by writing to program RAM, or some */ /* other nasty kind of error. Very handy, since it means that */ /* our program itself doesn't have to do boundary checking... */ vs_clip(handle,1,pxy); /*turn on clipping*/ /* define the mouse graphics to be the pointing hand. */ graf_mouse(3,&dummy); /* Setup the pen colors here */ for(count=2;count<16;count=count + 2) { rgb_in[0]=125 * ((count-2)/2); rgb_in[1]=125 * (count/2); rgb_in[2]=0; vs_color(handle,count,rgb_in); rgb_in[0]=125 * (count/2); rgb_in[1]=125 * (count/2); rgb_in[2]=0; vs_color(handle,count+1,rgb_in); } /* The setup is now complete */ restart: pen_color=2; rgb_in[0]=1000; rgb_in[1]=1000; rgb_in[2]=1000; vs_color(handle,0,rgb_in); v_hide_cursor(handle); v_clrwk(handle); vst_effect(handle,32); v_gtext(handle,0,height*10,"Fractal slice drawing program by"); v_gtext(handle,0,height*11,"Alex Leavens and Leonard Tramiel"); v_gtext(handle,0,height*13,"Please enter x,y and window size, using"); v_gtext(handle,0,height*14,"the mouse and the bar. Left edge is 0,"); v_gtext(handle,0,height*15,"right edge of bar is 4."); v_gtext(handle,0,height*17,"To input new starting values,"); v_gtext(handle,0,height*18,"press any key while program is"); v_gtext(handle,0,height*19,"drawing. To exit, press F1."); v_gtext(handle,0,height*21,"Note: This program DOES take a while"); v_gtext(handle,0,height*22,"to run, and works ONLY IN LORES COLOR"); v_gtext(handle,0,height*23,"mode. Just hang in there!"); /* Set color of polyline used to draw points */ vsl_color(handle,pen_color); pen_color=pen_color+1; v_show_cursor(handle,0); initial(); /*Now clear the screen*/ v_clrwk(handle); rgb_in[0]=0; rgb_in[1]=0; rgb_in[2]=0; vs_color(handle,0,rgb_in); while((evnt_multi(0x0021, 0,0,0, 0,0,0,0,0, 0,0,0,0,0, &dummy, 0,0, &dummy,&dummy,&dummy, &dummy,&kbak,&dummy))==0x0020) { whango: for(count=0;count<10;++count) { function(); } /* Now plot points */ vsl_color(handle,pen_color); pen_color=pen_color+1; for(count=0;count<10000;++count) { plotpoint(); function(); } start_x=start_x + x_change; start_y=start_y + y_change; x=.50001; y=0; x_realpart=start_x; y_imagpart=start_y; x_plus_y_squared=x_realpart * x_realpart + y_imagpart * y_imagpart; x_realpart=4 * x_realpart / x_plus_y_squared; y_imagpart=(-4) * y_imagpart / x_plus_y_squared; if(pen_color!=16) goto whango; /* ok, we're done drawing it. just sit and wait... */ plotpoint(); } if (kbak!=0x3b00) goto restart; rgb_in[0]=1000; rgb_in[1]=1000; rgb_in[2]=1000; vs_color(handle,0,rgb_in); } /*-----------------End of main()---------------------*/ function() { temp_x=x; temp_y=y; x=temp_x * x_realpart - temp_y * y_imagpart; y=temp_x * y_imagpart + temp_y * x_realpart; x=1.-x; temp1=y; x_plus_y_squared=(x * x) + (y * y); x_plus_y_squared=sqrt(x_plus_y_squared); temp3=(x_plus_y_squared - x) / 2.; if(temp3<0.) temp3=temp3 * (-1.); y=sqrt(temp3); temp3=(-x) + x_plus_y_squared; if(temp3<0.) y=y * (-1.); temp3=(x + x_plus_y_squared) / 2.; if(temp3<0.) temp3=temp3 * (-1.); x=sqrt(temp3); temp3=x + x_plus_y_squared; if(temp3<0.) x=x * (-1.); if(temp1<0.) x=x * (-1.); num_random=rand(); if(num_random<16000) { x=x * (-1.); y=y * (-1.); } x=1.-x; x=x/2.; y=y/2.; } /*-----------------End of Doroot()----------------------*/ plotpoint() { temp1=window_size * (x - .5) + x_boundary; temp2=y_boundary - window_size * y; plot_x=temp1; plot_y=temp2; Plot(plot_x,plot_y); } /*---------------END plotpoint()---------------------*/ initial() { temp3=x_boundary * 2.; temp3=temp3 / 4.; /* Get the x value for the equation... */ v_hide_cursor(handle); v_gtext(handle,0,height,"what is x-->"); pxy[0]=0;pxy[1]=2*height;pxy[2]=2*x_boundary;pxy[3]=3*height; v_bar(handle,pxy); v_show_cursor(handle,0); evnt_button(1,1,1,&mx,&my,&dummy,&dummy); evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy); v_hide_cursor(handle); x_realpart=mx; x_realpart=x_realpart / temp3; /*scale 0-200 to real # 0-4 */ start_x=x_realpart; ftoa(x_realpart,decimal,6); decimal[79]=0; v_gtext(handle,width,4*height,decimal); /* Get the y value for the equation... */ v_gtext(handle,0,height,"what is y-->"); pxy[0]=0;pxy[1]=2*height;pxy[2]=2*x_boundary;pxy[3]=3*height; v_bar(handle,pxy); v_show_cursor(handle,0); evnt_button(1,1,1,&mx,&my,&dummy,&dummy); evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy); v_hide_cursor(handle); y_imagpart=mx; y_imagpart=y_imagpart / temp3; /*scale 0-200 to real # 0-4 */ start_y=y_imagpart; ftoa(y_imagpart,decimal,6); decimal[79]=0; v_gtext(handle,width,4*height,decimal); x_plus_y_squared=(x_realpart * x_realpart) + (y_imagpart * y_imagpart); x_realpart=4 * x_realpart/x_plus_y_squared; y_imagpart=(-4) * y_imagpart/x_plus_y_squared; /* Get the change value for X */ temp2=x_boundary * 2.; v_gtext(handle,0,height,"what is change value for x-->"); pxy[0]=0;pxy[1]=2*height;pxy[2]=2*x_boundary;pxy[3]=3*height; v_bar(handle,pxy); v_show_cursor(handle,0); evnt_button(1,1,1,&mx,&my,&dummy,&dummy); evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy); v_hide_cursor(handle); x_change=mx; x_change=x_change / temp2; /*scale 0-200 to real # 0-4 */ ftoa(x_change,decimal,6); decimal[79]=0; v_gtext(handle,width,4*height,decimal); /* Get the change value for y */ v_gtext(handle,0,height,"what is change value for y-->"); pxy[0]=0;pxy[1]=2*height;pxy[2]=2*x_boundary;pxy[3]=3*height; v_bar(handle,pxy); v_show_cursor(handle,0); evnt_button(1,1,1,&mx,&my,&dummy,&dummy); evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy); v_hide_cursor(handle); y_change=mx; y_change=y_change / temp2; /*scale 0-200 to real # 0-4 */ ftoa(y_change,decimal,6); decimal[79]=0; v_gtext(handle,width,4*height,decimal); /* Get the window size for the fractal */ v_gtext(handle,0,height,"what's the window size-->"); pxy[0]=0;pxy[1]=2*height;pxy[2]=2*x_boundary;pxy[3]=3*height; v_bar(handle,pxy); v_show_cursor(handle,0); evnt_button(1,1,1,&mx,&my,&dummy,&dummy); evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy); window_size=mx; temp3=x_boundary * 2.; temp3=temp3 / 4.; window_size=window_size / temp3; /* scale number to 0-4 real */ tempr=2.; tempr=tempr * x_boundary; window_size=tempr/ window_size; ftoa(window_size,decimal,6); v_hide_cursor(handle); decimal[79]=0; v_gtext(handle,width,4*height,decimal); } /*------------------rand()-----------------*/ /*This function will return a 16 bit random number*/ rand() { return(Random()&0xffff); } /*__________End of rand_________________*/ /*------------Plot(x,y)------------------*/ Plot(x,y) { int pxy[4]; pxy[0]=x; pxy[1]=y; pxy[2]=x; pxy[3]=y; v_pline(handle,2, pxy); } /*------------------End of Plot (x,y)---------------*/ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ?ÿÿÿÿÿÿ