home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / tc_3d / tc-09.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  7.4 KB  |  227 lines

  1. /* TC-09 */
  2. /* This program demonstrates the halftoning capabilities
  3.     of EGA and VGA graphics adapters */
  4.  
  5. /* ----------------------------------------------------------------------- */
  6. /* INCLUDE FILES */
  7. #include <process.h>
  8. #include <bios.h>
  9. #include <stdio.h>
  10. #include <graphics.h>
  11. #include <math.h>
  12.  
  13. /* ----------------------------------------------------------------------- */
  14. /* DECLARATIONS */
  15.  
  16. void keyboard(void);void quit_pgm(void);
  17. void notice(int x,int y);
  18. void coords(void);void graphics_setup(void);
  19. void swatches(void);
  20.  
  21. float        sx,sy;                                                            /* device-independent display coordinates */
  22. float        x_res,y_res;                                                    /* screen mode dimensions for windowing */
  23.  
  24. int        C0=0,C1=1,C2=2,C3=3,C4=4,C5=5,C6=6,C7=7,C8=8,        /* color variables */
  25.             C9=9,C10=10,C11=11,C12=12,C13=13,C14=14,C15=15,
  26.             mode_flag=0;
  27.  
  28. int        COLOR1=0;
  29. float        x1=0,y1=240,x2=0,y2=0,x3=0,y3=0,x4=0,y4=0;
  30. float        x_offset=54,y_offset=40,x_change=54,y_change=50;
  31. int        t1=1,t2=1,t3=1;                                                /* counters */
  32.  
  33. char fill_0[]={0,0,0,0,0,0,0,0};                                        /* 0% fill */
  34. char fill_3[]={0,32,0,0,0,2,0,0};                                    /* 3% fill */
  35. char fill_6[]={32,0,2,0,128,0,8,0};                                    /* 6% fill */
  36. char fill_12[]={32,2,128,8,32,2,128,8};                            /* 12% fill */
  37. char fill_25[]={68,17,68,17,68,17,68,17};                            /* 25% fill */
  38. char fill_37[]={170,68,170,17,170,68,170,17};                    /* 37% fill */
  39. char fill_50[]={85,170,85,170,85,170,85,170};                    /* 50% fill */
  40. char fill_62[]={85,187,85,238,85,187,85,238};                    /* 62% fill */
  41. char fill_75[]={187,238,187,238,187,238,187,238};                /* 75% fill */
  42. char fill_87[]={223,253,127,247,223,253,127,247};                /* 87% fill */
  43. char fill_93[]={255,223,255,223,255,223,255,223};                /* 93% fill */
  44. char fill_100[]={255,255,255,255,255,255,255,255};                /* 100% fill */
  45.  
  46. /* ----------------------------------------------------------------------- */
  47. /* MAIN ROUTINE */
  48.  
  49. main(){
  50. graphics_setup();
  51. setcolor(C7);
  52.  
  53. x1=0;y1=60;
  54. COLOR1=C1;swatches();
  55.  
  56. x1=0;y1=y1+y_change;
  57. COLOR1=C2;swatches();
  58.  
  59. x1=0;y1=y1+y_change;
  60. COLOR1=C4;swatches();
  61.  
  62. x1=0;y1=y1+y_change;
  63. COLOR1=C3;swatches();
  64.  
  65. x1=0;y1=y1+y_change;
  66. COLOR1=C5;swatches();
  67.  
  68. x1=0;y1=y1+y_change;
  69. COLOR1=C7;swatches();
  70.  
  71. sx=0;sy=440;coords();setcolor(C7);notice(sx,sy);
  72. for (t1=1;t2!=2;) keyboard();
  73. quit_pgm();}
  74.  
  75. /* ----------------------------------------------------------------------- */
  76. /* SUBROUTINE: DRAW HALFTONE SWATCHES */
  77.  
  78. void swatches(void){
  79.  
  80. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  81. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  82. setfillpattern(fill_0,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  83.  
  84. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  85. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  86. setfillpattern(fill_3,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  87.  
  88. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  89. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  90. setfillpattern(fill_6,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  91.  
  92. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  93. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  94. setfillpattern(fill_12,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  95.  
  96. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  97. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  98. setfillpattern(fill_25,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  99.  
  100. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  101. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  102. setfillpattern(fill_37,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  103.  
  104. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  105. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  106. setfillpattern(fill_50,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  107.  
  108. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  109. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  110. setfillpattern(fill_62,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  111.  
  112. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  113. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  114. setfillpattern(fill_75,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  115.  
  116. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  117. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  118. setfillpattern(fill_87,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  119.  
  120. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  121. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  122. setfillpattern(fill_93,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  123.  
  124. x2=x1+x_offset;y2=y1+y_offset;sx=x1;sy=y1;coords();x3=sx;y3=sy;
  125. sx=x2;sy=y2;coords();x4=sx;y4=sy;
  126. setfillpattern(fill_100,COLOR1);bar(x3,y3,x4,y4);x1=x1+x_change;
  127.  
  128. return;}
  129.  
  130. /* ----------------------------------------------------------------------- */
  131. /* SUBROUTINE: CHACK THE KEYBOARD BUFFER */
  132. void keyboard(void){
  133. if (bioskey(1)==0) return; else quit_pgm();}
  134.  
  135. /* ----------------------------------------------------------------------- */
  136. /* SUBROUTINE: GRACEFUL EXIT FROM PROGRAM */
  137.  
  138. void quit_pgm(void){
  139. cleardevice();restorecrtmode();exit(0);}
  140.  
  141. /* ----------------------------------------------------------------------- */
  142. /* SUBROUTINE: VGA/EGA/MCGA/CGA COMPATIBILITY MODULE */
  143.  
  144. void graphics_setup(void){
  145. int graphics_adapter,graphics_mode;
  146. detectgraph(&graphics_adapter,&graphics_mode);
  147. if (graphics_adapter==VGA) goto VGA_mode;
  148. if (graphics_mode==EGAHI) goto EGA_ECD_mode;
  149. if (graphics_mode==EGALO) goto EGA_SCD_mode;
  150. if (graphics_adapter==CGA) goto abort_message;
  151. if (graphics_adapter==MCGA) goto abort_message;
  152. goto abort_message;
  153.  
  154. VGA_mode:
  155. graphics_adapter=VGA;graphics_mode=VGAHI;
  156. initgraph(&graphics_adapter,&graphics_mode,"");
  157. x_res=640;y_res=480;mode_flag=1;
  158.           setcolor(7);moveto(0,472);
  159.           outtext("Revisions by A. Helder");
  160.         moveto(472,472);
  161.         outtext("Press any key to quit");
  162.           moveto(184,0);
  163.           outtext("HALFTONE RENDERING SYSTEM FOR VGA");
  164.         return;
  165.  
  166. EGA_ECD_mode:
  167. graphics_adapter=EGA;graphics_mode=EGAHI;
  168. initgraph(&graphics_adapter,&graphics_mode,"");
  169. x_res=640;y_res=350;mode_flag=2;
  170.           setcolor(7);moveto(0,342);
  171.           outtext("Revisions by A. Helder");
  172.         moveto(472,342);
  173.         outtext ("Press any key to quit");
  174.           moveto(152,0);
  175.           outtext("HALFTONE RENDERING SYSTEM FOR EGA AND VGA");
  176.         return;
  177.  
  178. EGA_SCD_mode:
  179. graphics_adapter=EGA;graphics_mode=EGALO;
  180. initgraph(&graphics_adapter,&graphics_mode,"");
  181. x_res=640;y_res=200;mode_flag=3;
  182.           setcolor(7);moveto(0,192);
  183.           outtext("Revisions by A. Helder");
  184.         moveto(472,192);
  185.         outtext("PRESS ANY KEY TO QUIT");
  186.           moveto(152,0);
  187.           outtext("HALFTONE RENDERING SYSTEM FOR EGA AND VGA");
  188.         return;
  189.  
  190. abort_message:
  191. printf("\n\nUnable to proceed - Requires VGA or EGA adapter");
  192. printf("\nWith appropriate monitor");
  193. exit(0);
  194. }
  195.  
  196. /* ----------------------------------------------------------------------- */
  197. /* SUBROUTINE: MAP 640*480 TEMPLATE TO 2D SCREEN */
  198. void coords(void)
  199. {
  200. sx=sx*(x_res/640);sy=sy*(y_res/480);return;
  201. }
  202.  
  203. /* ----------------------------------------------------------------------- */
  204. /* SUBROUTINE: COPYRIGHT NOTICE */
  205.  
  206. int copyright[][3]={0x7c00,0x0000,0x0000,0x8231,
  207. 0x819c,0x645e,0xba4a,0x4252,0x96d0,0xa231,0x8252,0x955e,0xba4a,
  208. 0x43d2,0xf442,0x8231,0x825c,0x945e,0x7c00,0x0000,0x0000};
  209.  
  210. void notice(int x, int y){
  211. int a,b,c; int t1=0;
  212.  
  213. for (t1=0;t1<=6;t1++)
  214.     {
  215.     a=copyright[t1][0];b=copyright[t1][1];
  216.     c=copyright[t1][2];
  217.     setlinestyle(USERBIT_LINE,a,NORM_WIDTH);
  218.     moveto(x,y);lineto(x+15,y);
  219.     setlinestyle(USERBIT_LINE,b,NORM_WIDTH);
  220.     moveto(x+16,y);lineto(x+31,y);
  221.     setlinestyle(USERBIT_LINE,c,NORM_WIDTH);
  222.     moveto(x+32,y);lineto(x+47,y);y++;
  223.     };
  224. setlinestyle(USERBIT_LINE,0xFFFF,NORM_WIDTH);
  225. return;}
  226.  
  227. /* END OF SOURCE CODE */