#include /* module graphic9 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct dostime_t tym; struct pts{int x,y;}; /***************************************************************************/ box(bcolor,x1,y1,x2,y2,lcolor,label) /* draw a label in a box */ /* bcolor = box color */ /* x1,y1 = lower left box coordinates */ /* x2,y2 = upper right box coordinates */ /* lcolor = label color */ /* label = label to be placed in center of box */ char *label; { int fail,x0,y0; x0=(x1+x2)/2; /* center coord */ y0=(y1+y2)/2; if(fail=setcolor(DARKBLUE)) goto abort; grSetFillStyle(grFSOLID,bcolor,grTRANS); grDrawRect(x1,y1,x2,y2,grOUTLINE+grFILL); txSetAlign(txCENTER,txMIDDLE); text(lcolor,x0,y0,label); txSetAlign(txLEFT,txTOP); abort: return(fail); } /****************************************************************************/ box2(bcolor,x1,y1,x2,y2,lcolor,label1,label2) /* two labels in a box */ char *label1,*label2; { int fail,half,x0,y0; x0=(x1+x2)/2; /* center coord */ y0=(y1+y2)/2; half=txChrHeight()/2; if(fail=setcolor(DARKBLUE)) goto abort; grSetFillStyle(grFSOLID,bcolor,grTRANS); grDrawRect(x1,y1,x2,y2,grOUTLINE+grFILL); txSetAlign(txCENTER,txMIDDLE); text(lcolor,x0,y0+half+2,label1); text(lcolor,x0,y0-half-2,label2); txSetAlign(txLEFT,txTOP); abort: return(fail); } /*****************************************************************************/ box3(color,w,bcolor,x1,y1,x2,y2,lcolor,label1,label2) /* draw labels in a box */ /* color = border color */ /* w = border width */ /* bcolor = box color */ /* x1,y1 = lower left box coordinates */ /* x2,y2 = upper right box coordinates */ /* lcolor = label color */ /* label = label to be placed in center of box */ char *label1,*label2; { int x0,y0,y3,y4; x0=(x1+x2)/2; /* center coord */ y0=(y1+y2)/2; if(strlen(label2)) { /* two messages */ y3=y0+10; y4=y0-10; } else /* one message */ { y3=y0; y4=y0; } border(color,bcolor,x1,y1,x2,y2,w); txSetAlign(txCENTER,txMIDDLE); text(lcolor,x0,y3,label1); text(lcolor,x0,y4,label2); txSetAlign(txLEFT,txTOP); } /****************************************************************************/ boxit(char *message) /* stick a big note on the screen */ { box3(BLUE,5,YELLOW,100,100,540,200,BLUE,message,""); } /****************************************************************************/ boxit2(char *message1, char *message2) /* stick a note on the screen */ { box3(BLUE,5,YELLOW,100,100,540,200,BLUE,message1,message2); } /****************************************************************************/ boxit3(char *message) /* big note with mouse targets */ { box3(BLUE,5,YELLOW,100,100,540,200,BLUE,message,""); box(BLUE,220,120,240,140,WHITE,"Y"); box(BLUE,400,120,420,140,WHITE,"N"); } /**************************************************************************/ square(color,x,y) /* 20 by 20 square with black border */ { box(color,x,y,x+20,y+20,color," "); } /****************************************************************************/ rect(color,x1,y1,x2,y2) /* draw colored rectangle */ { int fail; if(fail=grSetFillStyle(grFSOLID,color,grTRANS)) printf("COULD NOT SET FILL STYLE\n"); if(fail=grDrawRect(x1,y1,x2,y2,grFILL)) printf("COULD NOT DRAW RECTANGLE\n"); return(fail); } /****************************************************************************/ frame(color,x1,y1,x2,y2) /* draw box outline */ { setcolor(color); line(x1,y1,x1,y2); line(x2,y1,x2,y2); line(x1,y1,x2,y1); line(x1,y2,x2,y2); } /****************************************************************************/ border(color,bcolor,x1,y1,x2,y2,w) /* draw rectangle border */ /* w = line width inside rectangle color = border color bcolor = interior color */ { int xa,xb,ya,yb; if(x1=low&&y2<=high) line2(BLUE,x+dx,y2,x+dx+10,y2); /* histogram tick */ } /****************************************************************************/ col(color,x,y,y2,dx,low,high) /* draw column */ /* x,y = lower left starting coordinates */ /* y2 = ending vertical coordinate */ /* dx = column width */ /* low = minimum, high = maximum height limit */ { int fail,savcolor=color; if(y2high) { color=VIOLET; y2=high; } if(y2>y) { rect(BLACK,x,y2,x+dx,high); /* erase old bar */ rect(BLACK,x,y,x+dx,low); } else { rect(BLACK,x,y2,x+dx,low); /* erase old bar */ rect(BLACK,x,y,x+dx,high); } rect(color,x,y,x+dx,y2); /* draw new bar */ fail=setcolor(savcolor); return(fail); } /****************************************************************************/ setback(color) /* set background color */ { int fail; if(fail=grSetBkColor(color)) printf("BACKGROUND COLOR WON'T SET\n"); return(fail); } /****************************************************************************/ setcolor(color) /* set drawing color */ { int fail; if(fail=grSetColor(color)) printf("FOREGROUND COLOR WON'T SET\n"); return(fail); } /****************************************************************************/ getcolor(void) /* get drawing color */ { int color; color=grGetColor(); return(color); } /***************************************************************************/ erase(void) /* clear prompt line */ { rect(BLACK,0,0,639,15); } /****************************************************************************/ clear(void) /* clear entire screen */ { int fail; offmouse(); if(fail=gxClearDisplay(BLACK,0)) printf("DISPLAY WON'T CLEAR\n"); if(fail=setback(BLACK)) goto abort; if(fail=grClearViewPort()) printf("VIEWPORT WON'T CLEAR\n"); abort: return(fail); } /*************************************************************************/ ground(x,y,state) /* draw ground symbol at coords x,y */ { int color; if(state) color=GREEN; else color=YELLOW; line2(color,x,y,x,y-10); line2(color,x-10,y-10,x+10,y-10); line2(color,x-5,y-15,x+5,y-15); line2(color,x-1,y-20,x+1,y-20); } /*****************************************************************************/ fan(x,y,on,color1,color2) /* draw fan symbol */ { int fail,x1,x2,y1,y2,r=15,color; if(on) color=color1; else color=color2; circle(color,x,y,r); /* draw a solid circle */ x1=x-.7*r; /* draw a star inside circle */ x2=x+.7*r; y1=y+.7*r; y2=y-.7*r; if(fail=setcolor(BLACK)) goto abort; line(x1,y1,x2,y2); line(x1,y2,x2,y1); line(x,y1,x,y2); line(x1,y,x2,y); abort: return(fail); } /*****************************************************************************/ runfan(x,y) /* animate fan blades */ { int fail,x1,x2,y1,y2,r=15; x1=x-.7*r; /* draw a star inside circle */ x2=x+.7*r; y1=y+.7*r; y2=y-.7*r; _dos_gettime(&tym); if(tym.hsecond<50) /* 50 hundredths of a sec */ { if(fail=setcolor(WHITE)) goto abort; line(x1,y1,x2,y2); line(x1,y2,x2,y1); if(fail=setcolor(BLACK)) goto abort; line(x,y1,x,y2); line(x1,y,x2,y); } else { if(fail=setcolor(BLACK)) goto abort; line(x1,y1,x2,y2); line(x1,y2,x2,y1); if(fail=setcolor(WHITE)) goto abort; line(x,y1,x,y2); line(x1,y,x2,y); } abort: return(fail); } /*************************************************************************/ arc(x,y,state) /* draw arc sensor symbol at coords x,y */ { int color; if(state) color=RED; /* arc sensor triggered */ else color=GREEN; circle(color,x,y,5); /* solid circle */ setcolor(DARKBLUE); cyrcle(x,y,6); /* ring */ } /***************************************************************************/ circle(color,x,y,r) /* draw solid circle of radius r at coords x,y */ { int fail; if(fail=grSetFillStyle(grFSOLID,color,grTRANS)) goto abort; fail=grDrawCircle(x,y,r,grFILL); abort: return(fail); } /***************************************************************************/ cyrcle(x,y,r) /* draw circle of radius r at coords x,y */ { int fail; fail=grDrawCircle(x,y,r,grOUTLINE); return(fail); } /****************************************************************************/ getimage(x1,y1,x2,y2) /* save image from screen */ { int fail; if(fail=gxDisplayVirtual(x1,479-y1,x2,479-y2,0,&vhptr,x1,479-y1)) printf("CAN'T SAVE VIRTUAL IMAGE\n"); return(fail); } /****************************************************************************/ putimage(x1,y1,x2,y2) /* put saved image on screen */ { int fail; if(fail=gxVirtualDisplay(&vhptr,x1,479-y1,x1,479-y1,x2,479-y2,0)) printf("CAN'T RETRIEVE VIRTUAL IMAGE\n"); return(fail); } /***************************************************************************/ scrsaver(void) { clear(); loop: console3(); /* (RS) */ if(kbhit()||stats()||sysbuf[0]) /* (RS) */ goto abort; average(); if(counter[45]) goto abort; goto loop; switch(gxGetRandom(5)) { case 0: rndell(0); /* random ellipse field */ break; case 1: rndell(1); /* random circle field */ break; case 2: rndot(); /* random dot field */ break; case 3: rndbar(); /* random rectangle field */ break; case 4: rndpoly(); /* random polygon field */ break; } abort: counter[9]=0; /* reset timer (RS) */ time(&scrstart); if(kbhit()) { caps(); clrkey(); } refresh=1; } /****************************************************************************/ rndell(flag) /* random ellipses */ { int scale,i,x,y,ax,ay,fail,oldpal[48]; for(i=0;i<48;i++) oldpal[i]=pal[i]; /* save old palette */ loop: rndpal(); /* change color palette */ scale=gxGetRandom(9)+1; for(i=0;i<(gxGetRandom(400)+200)*scale;i++) { if(fail=setcolor(gxGetRandom(16))) goto abort; if(fail=grSetFillStyle(grFSOLID,gxGetRandom(12),grOPAQUE)) goto abort; x=gxGetRandom(639); y=gxGetRandom(479); ax=gxGetRandom(639/scale); ay=gxGetRandom(479/scale); if(flag) { if(fail=grDrawCircle(x,y,(ax+ay)/2,grOUTLINE+grFILL)) goto abort; } else { if(fail=grDrawEllipse(x,y,ax,ay,grOUTLINE+grFILL)) goto abort; } if(kbhit()||stats()) goto abort; } goto loop; abort: for(i=0;i<16;i++) /* restore old palette */ { pal[3*i]=oldpal[3*i]; pal[3*i+1]=oldpal[3*i+1]; pal[3*i+2]=oldpal[3*i+2]; gxSetPaletteRGB(i,pal[3*i],pal[3*i+1],pal[3*i+2]); } return(fail); } /****************************************************************************/ rndpal(void) /* random color palette */ { int i,fail; for(i=0;i<16;i++) { pal[3*i]=gxGetRandom(64); pal[3*i+1]=gxGetRandom(64); pal[3*i+2]=gxGetRandom(64); if(fail=gxSetPaletteRGB(i,pal[3*i],pal[3*i+1],pal[3*i+2])) goto abort; } abort: return(fail); } /****************************************************************************/ rndot(void) /* random color pixels */ { int x,y,color; while(!kbhit()&&(!stats())) { x=gxGetRandom(637)+1; y=gxGetRandom(477)+1; color=gxGetRandom(16); rect(color,x,y,x+2,y+2); } } /***************************************************************************/ rndbar(void) /* random rectangles */ { struct pts vp[2]; int color; grGetViewPort(&vp[0].x,&vp[0].y,&vp[1].x,&vp[1].y); while(!kbhit()&&!stats()) { color=gxGetRandom(16); setcolor(color); grSetFillStyle(gxGetRandom(11)+1,color,grOPAQUE); grDrawRect(gxGetRandom(vp[1].x),gxGetRandom(vp[1].y), gxGetRandom(vp[1].y),gxGetRandom(vp[1].y),grOUTLINE+grFILL); } } /***************************************************************************/ rndpoly(void) /* random polygons */ { struct pts coord[30]; int fail,color,i; while(!kbhit()&&!stats()) { color=gxGetRandom(16); setcolor(color); grSetFillStyle(gxGetRandom(11)+1,color,grOPAQUE); for(i=0;i