/* Fractal drawing program number 4. Draws complete 3d fractal */ /* FILENAME: fract2.c */ #include extern double sqrt(); int contrl[12], intin[256], ptsin[256], intout[256], ptsout[256]; int scr_array[210]; int tempo; int screen_size; int x_boundary; int y_boundary; int line_count; int pixel_value; int clr_index; 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*/ appl_init(); /* Get the handle of the desktop */ handle=graf_handle(&width,&height,&dummy,&dummy); /* Open the workstation. */ for (i=1; i<10; ++i) intin[i] = i; intin[10] = 2; v_opnvwk(intin, &handle, intout); pxy[0]=0; pxy[1]=0; pxy[2]=intout[0]; pxy[3]=intout[1]; x_boundary=pxy[2]/2; y_boundary=pxy[3]/2; vs_clip(handle,1,pxy); /*turn on clipping*/ 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; line_count=1; 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_effects(handle,32); v_gtext(handle,0,height*9,"Another Fractal drawing program by"); v_gtext(handle,0,height*10,"Alex Leavens and Leonard Tramiel"); v_gtext(handle,0,height*12,"Please enter x,y, change values for"); v_gtext(handle,0,height*13,"x and 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 takes about 6 hours"); v_gtext(handle,0,height*22,"to run, and only works in lo-res color"); v_gtext(handle,0,height*23,"mode. Just hang in there!"); 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); for(count=0;count<10;++count) { function(); } /* zero out the array of plot values... */ for(count=0;count<210;count++) { scr_array[count]=0; } /* Now plot points */ while((evnt_multi(0x0021, 0,0,0, 0,0,0,0,0, 0,0,0,0,0, &dummy, 1,0, &dummy,&dummy,&dummy, &dummy,&kbak,&dummy))==0x0020) { plotpoint(); function(); } if (kbak!=0x3b00) goto restart; rgb_in[0]=1000; rgb_in[1]=1000; rgb_in[2]=1000; vs_color(handle,0,rgb_in); v_clsvwk(handle); } /*-----------------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; tempo=plot_x / 22 + 1; if(tempo<2) { tempo=2; } if(tempo>15) { tempo=15; } vsl_color(handle,tempo); 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)---------------*/   <T0: : ¨ ¨ ¨ ¨