home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 325_02 / demo.c < prev    next >
C/C++ Source or Header  |  1990-03-28  |  24KB  |  1,054 lines

  1. #include    <math.h>
  2. #include    <time.h>
  3. #include    <stdio.h>
  4. #include    <conio.h>
  5. #include    <stdlib.h>
  6. #include    <string.h>
  7. #include    <grph.h>
  8. #include    <ops2d.h>
  9. #include    <font.h>
  10. #include    <sound.h>
  11.  
  12. /*    Variables   */
  13.  
  14. Byte  ModeNo,GMode;            /* User and Graphic board specific Modes */
  15. int   lines,maxlines;            /* for text display */
  16. int   strtln;                /* text display line */
  17. struct    VP  vp1;            /* viewport corners */
  18. extern    Byte    far Fp[29][8];        /* 29 fill patterns */
  19. int     menuinput;            /* input menu option */
  20.  
  21. /*       function prototpes      */
  22.  
  23. extern    void near initfont(void);   /* local font initialization  */
  24. extern    void    intro(void);        /*    Introduction   */
  25. extern    void near setscreen1(void); /*    Setp Up Screen type 1 */
  26. extern    void    curves(void);        /*    Drawing Curves In Multiple Viewports */
  27.  
  28. extern    void    ellps(void);        /* Ellipses      */
  29. extern    void    arcs(void);        /* Arcs         */
  30.  
  31. extern    void    pttrn1(void);        /* Flood filling with patterns */
  32.  
  33. extern    void dpolyfill(void);        /* Polygon-Filling in Device Co-ordinates*/
  34. extern    void    pttrn2(void);        /* Setting fill pattern reference point */
  35. extern    void    fnts(void);        /* Bit-mapped and stroked fonts */
  36. extern    void    btblt(void);        /* Bit-Block moves and animation */
  37. extern    void    Delay(long);        /* just a loop routine for time delays */
  38.  
  39. extern    void    pan(void);        /* panning        */
  40. extern    void    cpimg(void);        /* Image Copy within video buffer    */
  41. extern    void    trnsfrm(void);        /* 2D transformations   */
  42. extern    void    space(int,int,int,int);     /*    Draw Moon and stars   */
  43.  
  44. extern    void    clrs(void);        /* colurs */
  45. extern    void    sound(void);        /* play notes of various frequencies */
  46. extern    void    menu(void);        /* main menu routine  */
  47.  
  48. int    main(void)
  49. {
  50.     time_t    timenow;
  51.     int     dmd,k,j;
  52.  
  53.     timenow = time(NULL);
  54.     srand((int)timenow);
  55.  
  56.     do
  57.     {
  58.         printf("Enter Mode No between 0 and 6 as one of following");
  59.         dmd = Mode640x350x16;
  60.         printf("\n   0 = 640x350x16  Mode no = %x ",dmd);
  61.         dmd = Mode640x480x16;
  62.         printf("\n   1 = 640x480x16  Mode no = %x ",dmd);
  63.         dmd = Mode320x200x256;
  64.         printf("\n   2 = 320x200x256 Mode no = %x ",dmd);
  65.         dmd = Mode640x400x256;
  66.         printf("\n   3 = 640x400x256 Mode no = %x ",dmd);
  67.         dmd = Mode640x480x256;
  68.         printf("\n   4 = 640x480x256 Mode no = %x ",dmd);
  69.         dmd = Mode800x600x16;
  70.         printf("\n   5 = 800x600x16  Mode no = %x ",dmd);
  71.         dmd = Mode1024x768x16;
  72.         printf("\n   6 = 1024x768x16 Mode no = %x ",dmd);
  73.         printf("\n     ---->");
  74.  
  75.         scanf("%d",&ModeNo);
  76.  
  77.     }
  78.     while ((ModeNo<0) || (ModeNo>6));
  79.  
  80.     switch (ModeNo)
  81.     {
  82.     case 0 : j= Mode640x350x16;break;
  83.     case 1 : j= Mode640x480x16;break;
  84.     case 2 : j= Mode320x200x256;break;
  85.     case 3 : j= Mode640x400x256;break;
  86.     case 4 : j= Mode640x480x256;break;
  87.     case 5 : j= Mode800x600x16;break;
  88.     case 6 : j= Mode1024x768x16;
  89.     }
  90.  
  91.  
  92.     if ((k = OpenGraph(ModeNo,0)) != j)
  93.     {
  94.         CloseGraph();
  95.         printf("Mode set error %d \n",k);
  96.         exit(1);
  97.     }
  98.  
  99.     do
  100.     {
  101.         menu();
  102.  
  103.     }
  104.     while (menuinput != 14);
  105.  
  106.     CloseGraph();
  107.     return(0);
  108. }
  109.  
  110. void    menu(void)
  111. {
  112.  
  113.     int     leftx;
  114.  
  115.     initfont();             /* set font and sizes depending upon mode */
  116.  
  117.     SetClipOff();
  118.     ClearScreen();
  119.  
  120.     FllClr=(Byte)(rand() % 16);     /* random back ground color */
  121.     if (FllClr == 15)            /* must not be same text color */
  122.     FllClr--;
  123.  
  124.     vp1.x1=1;                /* view-port corners */
  125.     vp1.y1=1;
  126.     vp1.x2=XMax-1;
  127.     vp1.y2=YMax-1;
  128.  
  129.     SetFillPattern(FllClr,0,0,Fp[19]);            /* Solid Fill  */
  130.     FillRectangle(vp1.x1,vp1.y1,vp1.x2,vp1.y2);
  131.     Rectangl(vp1.x1-1,vp1.y1-1,vp1.x2+1,vp1.y2+1);
  132.     SetViewPort(vp1);            /* activate viewport */
  133.  
  134.     strtln = 1;
  135.  
  136.     BFntStLctn(((XRes>>1)-15*BFntWdth),strtln);
  137.     BFntDsply("VGA Graphics Demonstration Menu");
  138.  
  139.     strtln += BFntHght;         /* next line of text */
  140.  
  141.     PxlClr = FllClr+1;
  142.     LineD(1,strtln,XRes-1,strtln);  /* just draw a line and then leave one */
  143.     SetClipOn();
  144.     BFntStClr(15);
  145.  
  146.     strtln += BFntHght;
  147.     strtln += BFntHght;         /* more blank line */
  148.     leftx = (XRes>>2)-25;
  149.  
  150.     BFntStLctn(leftx,strtln);
  151.     BFntDsply(" a. Introduction ");
  152.  
  153.     strtln += BFntHght;         /* menu options display */
  154.     BFntStLctn(leftx,strtln);
  155.     BFntDsply(" b. Pixels");
  156.  
  157.     strtln += BFntHght;
  158.     BFntStLctn(leftx,strtln);
  159.     BFntDsply(" c. Ellipses");
  160.  
  161.     strtln += BFntHght;
  162.     BFntStLctn(leftx,strtln);
  163.     BFntDsply(" d. Arcs");
  164.  
  165.     strtln += BFntHght;
  166.     BFntStLctn(leftx,strtln);
  167.     BFntDsply(" e. Polygon Fill");
  168.  
  169.     strtln += BFntHght;
  170.     BFntStLctn(leftx,strtln);
  171.     BFntDsply(" f. Area Fill");
  172.  
  173.     strtln += BFntHght;
  174.     BFntStLctn(leftx,strtln);
  175.     BFntDsply(" g. Fill Patterns");
  176.  
  177.     strtln += BFntHght;
  178.     BFntStLctn(leftx,strtln);
  179.     BFntDsply(" h. Bit-mapped & Stroked Fonts");
  180.  
  181.     strtln += BFntHght;
  182.     BFntStLctn(leftx,strtln);
  183.     BFntDsply(" i. Bit-block moves");
  184.  
  185.     strtln += BFntHght;
  186.     BFntStLctn(leftx,strtln);
  187.     BFntDsply(" j. Image copy / Window scrolling");
  188.  
  189.     strtln += BFntHght;
  190.     BFntStLctn(leftx,strtln);
  191.     BFntDsply(" k. Transformations");
  192.  
  193.     strtln += BFntHght;
  194.     BFntStLctn(leftx,strtln);
  195.     BFntDsply(" l. Smooth Pixel panning");
  196.  
  197.     strtln += BFntHght;
  198.     BFntStLctn(leftx,strtln);
  199.     BFntDsply(" m. Colours");
  200.  
  201.     strtln += BFntHght;
  202.     BFntStLctn(leftx,strtln);
  203.     BFntDsply(" n. Sound Effects");
  204.  
  205.     strtln += BFntHght;
  206.     BFntStLctn(leftx,strtln);
  207.     BFntDsply(" o. Exit");
  208.  
  209.     do                    /* call appropriate routine */
  210.     {
  211.         menuinput = getch();
  212.  
  213.         if (menuinput<97)
  214.         menuinput -= 65;
  215.         else
  216.         menuinput -= 97;
  217.  
  218.         switch(menuinput)
  219.         {
  220.             case 14: break;
  221.  
  222.             case 0 : intro();break;
  223.  
  224.             case 1 : curves();break;
  225.  
  226.             case 2 : ellps();break;
  227.  
  228.             case 3 : arcs();break;
  229.  
  230.             case 4 : dpolyfill();break;
  231.  
  232.             case 5 : pttrn1();break;
  233.  
  234.             case 6 : pttrn2();break;
  235.  
  236.             case 7 : fnts();initfont();break;
  237.  
  238.             case 8 : btblt();break;
  239.  
  240.             case 9 : cpimg();break;
  241.  
  242.             case 10: trnsfrm();break;
  243.  
  244.             case 11: pan();break;
  245.  
  246.             case 12: clrs();break;
  247.  
  248.             case 13: sound();break;
  249.         }
  250.     }
  251.     while ((menuinput<0) || (menuinput>14));
  252. }
  253.  
  254. void    near    initfont()
  255. {
  256.  
  257.     if (ModeNo==2)              /* 320x200  mode, load 8x8 font*/
  258.     BFntInit("v8x8.fnt",8);
  259.     else
  260.     BFntInit("v8x16.fnt",16);     /* others, load 8x16 font*/
  261.  
  262.     if (ModeNo>5)              /* 1024x768 mode, font size = 2x1 */
  263.     BFntStSz(2,1);
  264.     else
  265.     BFntStSz(1,1);              /* others, font size = 1x1 */
  266. }
  267.  
  268. void    intro(void)
  269. {
  270.  
  271.     FILE    *intfl;
  272.     int     sz,maxlines;
  273.     char    flnm[13];
  274.     char    far *s1;
  275.     char    s2[81];
  276.  
  277.     initfont();
  278.  
  279.     memset(s2,(int) '\0',81);
  280.  
  281.     if (ModeNo==6)
  282.     BFntStSz(2,1);
  283.     else
  284.     BFntStSz(1,1);
  285.  
  286.     maxlines = YMax - (BFntHght<<1);
  287.  
  288.     setscreen1();
  289.  
  290.     if (ModeNo==2)
  291.     {
  292.         strcpy(flnm,"intrtxt2.dat\0");    /* intro data file name */
  293.         sz = 41;
  294.     }
  295.     else
  296.     {
  297.         strcpy(flnm,"intrtxt1.dat\0");
  298.         sz = 80;
  299.     }
  300.     if ((s1 = (char far *)malloc(sz)) == NULL)
  301.     {
  302.         BFntDsply("Memory Problem");
  303.         return;
  304.     }
  305.  
  306.     if ((intfl = fopen(flnm,"rb")) == NULL)
  307.     {
  308.         BFntDsply("Intro data File  ");
  309.         BFntDsply(flnm);
  310.         BFntDsply("  Not Found, Press a Key");
  311.         getch();
  312.         free(s1);
  313.         return;
  314.     }
  315.  
  316.     while (!feof(intfl))        /* read a line and display */
  317.     {
  318.         if (fread(s1,sz,1,intfl) == 1)
  319.         {
  320.             if (strtln>=maxlines)     /* when buffer end */
  321.             {
  322.                 while (YOrgn<=(YMax-YRes-7))
  323.                 {
  324.                     getch();
  325.                     SScroll(YRes,2);   /* scroll-up */
  326.                  }               /* by no of lines in */
  327.                  getch();               /* one screen */
  328.                  SetOrigin(0,0);           /* at end */
  329.                  setscreen1();
  330.             }
  331.             strncpy(s2,s1,sz-3);
  332.  
  333.             strtln += BFntHght;
  334.             BFntStLctn(1,strtln);
  335.  
  336.             BFntDsply(s2);
  337.         }
  338.         else if (!feof(intfl))
  339.         {
  340.             BFntDsply("read  error, press any key");
  341.             getch();
  342.             fclose(intfl);
  343.             free(s1);
  344.             return;
  345.         }
  346.     }
  347.  
  348.     while (strtln > (YOrgn+YRes))         /* last frame */
  349.        {
  350.        getch();
  351.        SScroll(YRes,2);
  352.        }
  353.     getch();
  354.  
  355.     SetOrigin(0,0);
  356.  
  357.     fclose(intfl);
  358.     free(s1);
  359.  
  360. }
  361.  
  362. void near setscreen1(void)
  363. {
  364.  
  365.     SetClipOff();
  366.     vp1.x1=1;
  367.     vp1.y1=1;
  368.     vp1.x2=XMax-1;
  369.     vp1.y2=YMax-1;
  370.  
  371.     FllClr = (Byte)(rand() % 6);
  372.  
  373.     SetFillPattern(FllClr,0,0,Fp[19]);            /* Solid Fill  */
  374.     FillRectangle(vp1.x1,vp1.y1,vp1.x2,vp1.y2);
  375.     Rectangl(vp1.x1-1,vp1.y1-1,vp1.x2+1,vp1.y2+1);
  376.     SetViewPort(vp1);
  377.  
  378.     PxlClr=7;
  379.     LineD(1,BFntHght<<1,XRes-1,BFntHght<<1);
  380.     SetClipOn();
  381.     BFntStClr(15);
  382.  
  383.     strtln = 1;
  384.  
  385.     BFntStLctn(((XRes>>1)-10*BFntWdth),strtln);
  386.     BFntDsply("VGA Graphics Routines");
  387.  
  388.     strtln += BFntHght;
  389.     BFntStLctn(((XRes>>1)-17*BFntWdth),strtln);
  390.     BFntDsply("Capabilities Demonstration Program");
  391. }
  392.  
  393. void btblt(void)            /* bit-block moves */
  394. {
  395.  
  396.     Word    j;
  397.     void    far *p1;            /* memory blocks to read images */
  398.     void    far *p2;
  399.     void    far *p3;
  400.     void    far *p4;
  401.     float   x1,x2,y1,y2;
  402.     int     a1,b1,a2,b2;
  403.  
  404.     SetDraw(0);
  405.     SetClipOff();
  406.     ClearScreen();
  407.  
  408.     strtln = 1;
  409.     BFntStClr(15);
  410.     BFntStLctn((XRes>>1)-14*BFntWdth,strtln);
  411.     BFntDsply("Bit-Block Moves and Animation");
  412.     strtln += BFntHght;
  413.     LineD(1,strtln,(XRes-1),strtln);
  414.  
  415.     vp1.x1=0;
  416.     vp1.y1=0;
  417.     vp1.x2=319;
  418.     if (_ZMode==0)            /* view port lower right corner y */
  419.     vp1.y2=479;
  420.     else
  421.     vp1.y2=199;
  422.     SetViewPort(vp1);            /* set view port */
  423.     x2 = (float)((vp1.x2+1));        /* world mapping corners */
  424.     x1 = -x2;
  425.     y1 = 200.0f;
  426.     y2 = -y1;
  427.     MapWorld(x1,y1,x2,y2);        /* map world to device co-ordinates */
  428.  
  429.  
  430.     a1 = WtoDX(-80.0f);         /* must be same as when image was created */
  431.     b1 = WtoDY(-80.0f);         /* the image boundin rectangle */
  432.     a2 = WtoDX(110.0f);
  433.     b2 = WtoDY(105.0f);
  434.  
  435.     j = ImageSize(a1,b1,a2,b2);     /* no of bytes required to store */
  436.                     /* image */
  437.     p1 = (void far *)malloc(j);   /* allocate memory for 4 buffers */
  438.     p2 = (void far *)malloc(j);
  439.     p3 = (void far *)malloc(j);
  440.     p4 = (void far *)malloc(j);
  441.  
  442.     if (_ZMode==0)            /* load images from disk */
  443.     {
  444.         LoadImage("b112",(void far *)p1,j);     /* use file depending */
  445.         LoadImage("b212",(void far *)p2,j);     /* upon mode used */
  446.         LoadImage("b312",(void far *)p3,j);
  447.         LoadImage("b412",(void far *)p4,j);     /* 16 color modes */
  448.     }
  449.     else
  450.     {
  451.         LoadImage("b113",(void far *)p1,j);     /* 256 color modes */
  452.         LoadImage("b213",(void far *)p2,j);     /* because of different */
  453.         LoadImage("b313",(void far *)p3,j);     /* resolutions, same file */
  454.         LoadImage("b413",(void far *)p4,j);     /* makes a picture of */
  455.     }                        /* different sizes */
  456.  
  457.     if (_ZMode==0)
  458.     {                        /* start points */
  459.         a2 = -4;
  460.         b2 = (YRes+1)>>4;
  461.     }
  462.     else
  463.     {
  464.         a2 = XRes;
  465.         b2 = (YRes+1)>>3;
  466.     }
  467.  
  468.     a1=a2;
  469.     b1=b2;
  470.  
  471.     j = 4;                        /* no of pixels to move */
  472.     SetDraw(0);
  473.     do
  474.     {
  475.         PutImage(a1,b1,(void far *)p1);
  476.         Delay(20000L);
  477.         a1 -= j;
  478.  
  479.         PutImage(a1,b1,(void far *)p2);
  480.         Delay(20000L);
  481.         a1 -= j;
  482.  
  483.         PutImage(a1,b1,(void far *)p3);
  484.         Delay(20000L);
  485.         a1 -= j;
  486.  
  487.         PutImage(a1,b1,(void far *)p4);
  488.         Delay(20000L);
  489.         a1 -= j;
  490.  
  491.         PutImage(a1,b1,(void far *)p3);
  492.         Delay(20000L);
  493.         a1 -= j;
  494.  
  495.         PutImage(a1,b1,(void far *)p2);
  496.         Delay(20000L);
  497.         a1 -= j;
  498.  
  499.         if ((a1>=0) && (a1<32))
  500.         {
  501.             SetDraw(3);         /* erase last image using XOR */
  502.             a1 += j;            /* and displaying image at same loc. */
  503.             PutImage(a1,b1,(void far *)p2);
  504.             SetDraw(0);         /* re-set to Replace drawing mode */
  505.             a1 = a2;
  506.             b1 = b2;
  507.         }
  508.     }
  509.     while(!(kbhit()));
  510.     getch();
  511.  
  512.     free(p1);
  513.     free(p2);
  514.     free(p3);
  515.     free(p4);
  516. }
  517.  
  518. void pan()                 /* scrolling */
  519. {
  520.     ClearScreen();
  521.  
  522.     space(0,0,XMax,YMax);         /* draw the space background */
  523.     SetClipOff();
  524.  
  525.     PxlClr=5;
  526.     Rectangl(0,0,XMax,YMax);
  527.     BFntStClr(14);
  528.     BFntStLctn(4,(XRes>>1) - 128);
  529.     BFntStSz(2,2);
  530.     BFntDsply("Smooth Scrolling");
  531.  
  532.  
  533.     SScroll(XMax-XRes,0);        /* scroll left */
  534.  
  535.     SScroll(YMax-YRes,2);        /* scroll up */
  536.  
  537.     getch();
  538.     SScroll(XMax-XRes,1);        /* scroll right */
  539.     getch();
  540.     SScroll(YMax-YRes,3);        /* scroll down */
  541.     getch();
  542.  
  543.     ClearScreen();
  544.     SetXLen(100);            /* re-dimension video buffer */
  545.     space(0,0,XMax,YMax);        /* so that it extends beyond right hand */
  546.     PxlClr=4;            /* screen edge */
  547.     Rectangl(0,0,XMax,YMax);
  548.  
  549.     SScroll(XMax-XRes,0);        /* scroll left */
  550.  
  551.     getch();
  552.  
  553.     SScroll(YMax-YRes,2);        /* scroll up */
  554.  
  555.     getch();
  556.     SScroll(XMax-XRes,1);        /* scroll right */
  557.     getch();
  558.     SScroll(YMax-YRes,3);        /* and down to original position */
  559.     getch();
  560.     if (XRes <600)            /* set video dimensions to original val */
  561.         SetXLen(80);
  562. }
  563.  
  564. void cpimg(void)            /* scrolling windows */
  565.  
  566. {
  567.  
  568.     int     x11,y11,x12,y12;
  569.     int     x21,y21,x22,y22;
  570.     int     x31,y31,x32,y32;
  571.     int     vscrll;
  572.  
  573.     SetClipOff();
  574.     ClearScreen();
  575.  
  576.     PxlClr =9;
  577.     Rectangl(0,0,XRes,YRes);
  578.  
  579.     FllClr =  8;
  580.     FillRectangle(1,1,XRes-1,YRes-1);
  581.  
  582.     strtln = 1;
  583.  
  584.     BFntStClr(15);
  585.  
  586.     BFntStLctn((XRes>>1)-BFntWdth*8,strtln);
  587.     BFntDsply("Window Scrolling");
  588.  
  589.     strtln += BFntHght;
  590.  
  591.     LineD(1,strtln,XRes-1,strtln);
  592.  
  593.     vp1.x1 = 15;
  594.     vp1.y1 = strtln+BFntHght;
  595.     vp1.x2 = ((vp1.x1 + (XRes>>1)-19) & 0xfff8);
  596.     vp1.y2 = vp1.y1 + ((YRes-vp1.y1)>>1)-6;
  597.  
  598.     PxlClr = 15;
  599.     Rectangl(vp1.x1,vp1.y1,vp1.x2,vp1.y2);
  600.     FllClr = 4;
  601.     FillRectangle(vp1.x1+1,vp1.y1+1,vp1.x2-1,vp1.y2-1);
  602.  
  603.     x11 = vp1.x1;            /* make another window using */
  604.     y11 = vp1.y2+5;            /* copyimage */
  605.     x12 = vp1.x2;
  606.     y12 = y11 + vp1.y2-vp1.y1;
  607.  
  608.     x21 = vp1.x2+15;            /* make another window using */
  609.     y21 = vp1.y1;            /* copyimage */
  610.     x22 = x21 + vp1.x2 - vp1.x1;
  611.     y22 = vp1.y2;
  612.  
  613.     x31 = x21;                /* make another window using */
  614.     y31 = y11;                /* copyimage */
  615.     x32 = x22;
  616.     y32 = y12;
  617.  
  618.     CopyImage(vp1.x1,vp1.y1,vp1.x2,vp1.y2,x11,y11);
  619.     CopyImage(vp1.x1,vp1.y1,vp1.x2,vp1.y2,x21,y21);
  620.     CopyImage(vp1.x1,vp1.y1,vp1.x2,vp1.y2,x31,y31);
  621.  
  622.  
  623.     vp1.x1++; x31++; x11++;x21++;
  624.     vp1.y1++; y31++; y11++;y21++;
  625.     vp1.x2--; x32--; x12--;x22--;
  626.     vp1.y2--; y32--; y12--;y22--;
  627.  
  628.     if (_ZMode == 0)
  629.     vscrll=8;
  630.     else
  631.     vscrll = 4;
  632.  
  633.     do
  634.     {
  635.                    /* scroll down by 4 scan lines */
  636.         WindScrollDown(vp1.x1,vp1.y1,vp1.x2,vp1.y2,4);
  637.         PxlClr ++;
  638.         LineD(vp1.x1,vp1.y1,vp1.x2,vp1.y1);
  639.                    /* scroll up by one scan line */
  640.         WindScrollUp(x31,y31,x32,y32,1);
  641.         PxlClr ++;
  642.         LineD(x31,y32,x32,y32);
  643.         WindScrollLeft(x11,y11,x12,y12,vscrll);  /* only multiples of 8 */
  644.         PxlClr ++;                    /* allowed for left right*/
  645.         LineD(x12,y11,x12,y12);            /* scroll */
  646.         WindScrollRight(x21,y21,x22,y22,vscrll);
  647.         PxlClr ++;
  648.         LineD(x21,y21,x21,y22);
  649.  
  650.     }
  651.     while (!(kbhit()));
  652.     getch();
  653.  
  654.  
  655. }
  656.  
  657. void trnsfrm(void)              /* transformations */
  658.  
  659. {
  660.     struct  VP    vp2,vp3,vp4;
  661.  
  662.     Word    n;
  663.     float   svx[51],svy[51];
  664.     float   nwx[51],nwy[51];
  665.     float   m1[9],m2[9];
  666.  
  667.     SetClipOff();
  668.     ClearScreen();
  669.  
  670.     PxlClr =9;
  671.     Rectangl(0,0,XRes,YRes);
  672.  
  673.     FllClr =  8;
  674.     FillRectangle(1,1,XRes-1,YRes-1);
  675.  
  676.     strtln = 1;
  677.  
  678.     BFntStClr(15);
  679.  
  680.     BFntStLctn((XRes>>1)-BFntWdth*8,strtln);
  681.     BFntDsply("2D transformations");
  682.  
  683.     strtln += BFntHght;
  684.  
  685.     LineD(1,strtln,XRes-1,strtln);
  686.  
  687.     vp1.x1 = 15;
  688.     vp1.y1 = strtln+BFntHght;
  689.     vp1.x2 = ((vp1.x1 + (XRes>>1)-19) & 0xfff8);
  690.     vp1.y2 = vp1.y1 + ((YRes-vp1.y1)>>1)-6;
  691.  
  692.     PxlClr = 15;
  693.     Rectangl(vp1.x1,vp1.y1,vp1.x2,vp1.y2);
  694.     FllClr = 5;
  695.     FillRectangle(vp1.x1+1,vp1.y1+1,vp1.x2-1,vp1.y2-1);
  696.  
  697.     vp2.x1 = vp1.x1;               /* make another window using */
  698.     vp2.y1 = vp1.y2+5;               /* copyimage */
  699.     vp2.x2 = vp1.x2;
  700.     vp2.y2 = vp2.y1 + vp1.y2-vp1.y1;
  701.  
  702.     vp3.x1 = vp1.x2+15;            /* make another window using */
  703.     vp3.y1 = vp1.y1;               /* copyimage */
  704.     vp3.x2 = vp3.x1 + vp1.x2 - vp1.x1;
  705.     vp3.y2 = vp1.y2;
  706.  
  707.     vp4.x1 = vp3.x1;              /* make another window using */
  708.     vp4.y1 = vp2.y1;              /* copyimage */
  709.     vp4.x2 = vp3.x2;
  710.     vp4.y2 = vp2.y2;
  711.  
  712.     CopyImage(vp1.x1,vp1.y1,vp1.x2,vp1.y2,vp2.x1,vp2.y1);
  713.     CopyImage(vp1.x1,vp1.y1,vp1.x2,vp1.y2,vp3.x1,vp3.y1);
  714.     CopyImage(vp1.x1,vp1.y1,vp1.x2,vp1.y2,vp4.x1,vp4.y1);
  715.  
  716.     n = Arc(0.0f,0.0f,20.0f,20.0f,0.0f,355.00f,svx,svy,50);
  717.     svx[50] = svx[0]; svy[50]=svy[0];
  718.  
  719.     SetClipOn();
  720.     SetViewPort(vp1);
  721.     MapWorld(-100.0f,-100.0f,100.0f,100.0f);
  722.  
  723.     PolyLine(51,svx,svy);
  724.  
  725.     BFntStLctn(vp1.x1+1,vp1.y1+1);
  726.     BFntStClr(1);
  727.     BFntDsply("Original circle");
  728.  
  729.     SetViewPort(vp2);
  730.     MapWorld(-100.0f,-100.0f,100.0f,100.0f);
  731.     for (n=0; n<51; n++)
  732.     {
  733.         nwx[n] = svx[n];
  734.         nwy[n] = svy[n];
  735.     }
  736.  
  737.     XShr2D(1.5f,m1);
  738.     YShr2D(2.3f,m2);
  739.     CmbnTrnsfrm2D(m1,m2);
  740.     TrnsfrmPnts2D(51,nwx,nwy,m2);
  741.     PolyLine(51,nwx,nwy);
  742.  
  743.     BFntStLctn(vp2.x1+1,vp2.y1+1);
  744.     BFntDsply("Sheared");
  745.  
  746.     SetViewPort(vp3);
  747.     MapWorld(-100.0f,-100.0f,100.0f,100.0f);
  748.     for (n=0; n<51; n++)
  749.     {
  750.         nwx[n] = svx[n];
  751.         nwy[n] = svy[n];
  752.     }
  753.  
  754.     Rotate2D(60.0f,0.0f,0.0f,m1);
  755.     CmbnTrnsfrm2D(m1,m2);
  756.     TrnsfrmPnts2D(51,nwx,nwy,m2);
  757.     PolyLine(51,nwx,nwy);
  758.  
  759.     BFntStLctn(vp3.x1+1,vp3.y1+1);
  760.     BFntDsply("Sheared & Rotated");
  761.  
  762.     SetViewPort(vp4);
  763.     MapWorld(-100.0f,-100.0f,100.0f,100.0f);
  764.     for (n=0; n<51; n++)
  765.     {
  766.         nwx[n] = svx[n];
  767.         nwy[n] = svy[n];
  768.     }
  769.  
  770.     Scale2D(3.5f,2.5f,0.0f,0.0f,m2);
  771.     TrnsfrmPnts2D(51,nwx,nwy,m2);
  772.     PolyLine(51,nwx,nwy);
  773.  
  774.     BFntStLctn(vp4.x1+1,vp4.y1+1);
  775.     BFntDsply("Scaled");
  776.  
  777.     getch();
  778.  
  779. }
  780.  
  781.  
  782. void clrs()
  783. {
  784.     Byte i,j,k;
  785.     int     xl,yl,yl1;
  786.     struct  RGBstruct    RGB[64];        /* RGB variable 3-byte structer */
  787.     Byte    last,current;
  788.     float   a1,b1,a2,b2;
  789.     float   arcx[100],arcy[100];
  790.  
  791.     SetClipOff();
  792.     ClearScreen();
  793.  
  794.     SetDraw(0);
  795.     SetFillPattern(7,0,0,Fp[19]);
  796.  
  797.     PxlClr = 1;
  798.     Rectangl(0,0,XRes,YRes);
  799.  
  800.     strtln = 1;
  801.  
  802.     BFntStClr(13);
  803.     BFntStLctn((XRes>>1)-14*BFntWdth,strtln);
  804.     BFntDsply("Colour Registers Manipulation");
  805.     strtln += BFntHght;
  806.  
  807.     LineD(1,strtln,XRes-1,strtln);
  808.  
  809.     xl = ((XRes-1) >> 4);
  810.     yl = ((YRes-strtln) >> 2);
  811.     yl1 = (yl>>2);
  812.  
  813.     for (i=0;i<4;i++)            /* show all 256 colors */
  814.     {
  815.         for (j=0;j<16;j++)
  816.         {
  817.             FllClr=(Byte)(j+i*64);
  818.             FillRectangle(j*xl+1,i*yl+strtln,(j+1)*xl-1,i*yl+yl1-1+strtln);
  819.         }
  820.  
  821.         for (j=0;j<16;j++)
  822.         {
  823.             FllClr=(Byte)(16+j+i*64);
  824.             FillRectangle(j*xl+1,i*yl+yl1+strtln,(j+1)*xl-1,i*yl+2*yl1-1+strtln);
  825.         }
  826.  
  827.         for (j=0;j<16;j++)
  828.         {
  829.             FllClr=(Byte)(32+j+i*64);
  830.             FillRectangle(j*xl+1,i*yl+2*yl1+strtln,(j+1)*xl-1,i*yl+3*yl1-1+strtln);
  831.         }
  832.  
  833.         for (j=0;j<16;j++)
  834.         {
  835.             FllClr=(Byte)(48+j+i*64);
  836.             FillRectangle(j*xl+1,i*yl+3*yl1+strtln,(j+1)*xl-1,i*yl+4*yl1-1+strtln);
  837.         }
  838.         if (_ZMode == 0)
  839.         getch();
  840.  
  841.     }
  842.  
  843.     for (i=0;i<4;i++)
  844.     {
  845.         getch();                /* grey-scale 4 blocks of */
  846.         GreyScale(i*64,64);         /* 64 registers */
  847.     }
  848.     getch();
  849.     for (i=0;i<4;i++)
  850.     {             /* for 16 color modes, select dac group */
  851.         if    ((ModeNo <2) || (ModeNo > 4))  /* as one of 4 groups each of */
  852.         SelectDAC(i);               /* 64 registers */
  853.         for (k=0;k<64;k++)
  854.         {
  855.             switch(i)           /* Red,Green,Blue and Grey shades */
  856.             {
  857.                 case 0 : RGB[k].Red = k;RGB[k].Green=0;RGB[k].Blue=0;break;
  858.                 case 1 : RGB[k].Red = 0;RGB[k].Green=k;RGB[k].Blue=0;break;
  859.                 case 2 : RGB[k].Red = 0;RGB[k].Green=0;RGB[k].Blue=k;break;
  860.                 case 3 : RGB[k].Red = k;RGB[k].Green=k;RGB[k].Blue=k;break;
  861.             }
  862.         }
  863.  
  864.     /*    set RGB values in 64 registers */
  865.  
  866.  
  867.         SetRGBDAC(i*64,64,(struct RGBstruct far *)RGB);
  868.  
  869.     /* draw these 64 color rectangles */
  870.  
  871.         for (j=0;j<16;j++)
  872.         {
  873.             FllClr=(Byte)(j+i*64);
  874.             FillRectangle(j*xl+1,i*yl+strtln,(j+1)*xl-1,i*yl+yl1-1+strtln);
  875.         }
  876.  
  877.         for (j=0;j<16;j++)
  878.         {
  879.             FllClr=(Byte)(16+j+i*64);
  880.             FillRectangle(j*xl+1,i*yl+yl1+strtln,(j+1)*xl-1,i*yl+2*yl1-1+strtln);
  881.         }
  882.  
  883.         for (j=0;j<16;j++)
  884.         {
  885.             FllClr=(Byte)(32+j+i*64);
  886.             FillRectangle(j*xl+1,i*yl+2*yl1+strtln,(j+1)*xl-1,i*yl+3*yl1-1+strtln);
  887.         }
  888.  
  889.         for (j=0;j<16;j++)
  890.         {
  891.             FllClr=(Byte)(48+j+i*64);
  892.             FillRectangle(j*xl+1,i*yl+3*yl1+strtln,(j+1)*xl-1,i*yl+4*yl1-1+strtln);
  893.         }
  894.     }
  895.     getch();
  896.  
  897.     OpenGraph(ModeNo,1);         /* to set default color register values */
  898.                      /* do a mode set without clearing buffer*/
  899.     SetClipOff();
  900.     ClearScreen();
  901.  
  902.     PxlClr = 12;
  903.     Rectangl(0,0,XRes,YRes);
  904.     strtln = 1;
  905.  
  906.     BFntStClr(15);
  907.     BFntStLctn((XRes>>1)-14*BFntWdth,strtln);
  908.     BFntDsply("Colour Palette Manipulation");
  909.     strtln += BFntHght;
  910.  
  911.     LineD(1,strtln,XRes-1,strtln);
  912.  
  913.     vp1.x1=1;
  914.     vp1.y1=strtln+1;
  915.     vp1.x2=XRes-1;
  916.     vp1.y2=YRes-1;
  917.  
  918.     FllClr = 8;
  919.     FillRectangle(vp1.x1,vp1.y1,vp1.x2,vp1.y2);
  920.  
  921.     SetViewPort(vp1);
  922.  
  923.     a1 = -500.0f;
  924.     b1 = -500.0f;
  925.     a2 =  500.0f;
  926.     b2 =  500.0f;
  927.  
  928.     MapWorld(a1,b1,a2,b2);
  929.  
  930.     PxlClr = 15;
  931.  
  932.     Line(0.0f,b1,0.0f,b2);
  933.  
  934.     a1 = a2 / 8.0f;
  935.  
  936.     for (i=8;i>0;i--)            /* draw 8 ellipses and fill in all */
  937.     {                /* 16 palette colors */
  938.         a2 = (float)(i) * a1;
  939.         Arc(0.0f,0.0f,a2,b2,0.0f,359.99f,arcx,arcy,100);
  940.         PolyLine(100,arcx,arcy);
  941.  
  942.         FllClr = (Byte)8-i;
  943.  
  944.         FillArea(WtoDX(-10.0f),WtoDY(0.0f),PxlClr);
  945.  
  946.         FllClr = (Byte)16 - i;
  947.  
  948.         FillArea(WtoDX(10.0f),WtoDY(0.0f),PxlClr);
  949.     }
  950.     getch();
  951.  
  952.     last = GetPalette(0);        /* rotate palette values */
  953.     do                    /* by putting last palette value into */
  954.     {                /* next palette */
  955.         for (i=1;i<16;i++)
  956.         {
  957.             current = GetPalette(i);
  958.             SetPalette(i,last);
  959.             last=current;
  960.         }
  961.         last = GetPalette(0);
  962.         SetPalette(0,current);
  963.     }
  964.     while (!(kbhit()));
  965.     getch();
  966.  
  967. }
  968.  
  969. void sound(void)            /* sounds of different frequencies */
  970. {                    /* and durations */
  971.  
  972.     unsigned int     i,j;
  973.  
  974.     for (j=1;j<5;j++)
  975.     {
  976.         for (i=1;i<25;i++)
  977.         {
  978.             PlayNote(540,33);
  979.             PlayNote(650,26);
  980.         }
  981.         Delay(30000L);
  982.     }
  983.  
  984.     Delay(32767L);
  985.  
  986.  
  987.     for (i=200;i<1005;i+=4)
  988.     PlayNote(i,40);
  989.     for (i=1000;i>700;i-=4)
  990.     PlayNote(i,40);
  991.     for (i=700;i<1004;i+=4)
  992.     PlayNote(i,40);
  993.     for (i=1000;i>700;i-=4)
  994.     PlayNote(i,40);
  995.     for (i=700;i<1004;i+=4)
  996.     PlayNote(i,40);
  997.  
  998.     Delay(32767L);
  999.  
  1000.     for (i=1;i<21;i++)
  1001.     {
  1002.         PlayNote(11000,20);
  1003.         Delay(300L);
  1004.     }
  1005.  
  1006.     Delay(32767L);
  1007.  
  1008.     for (i=1;i<11;i++)
  1009.     for (j=300;j<1800;j+=40)
  1010.         PlayNote(j,1);
  1011.  
  1012.     Delay(32767L);
  1013.  
  1014.     for (i=1;i<31;i++)
  1015.     for (j=40;j<=80;j++)
  1016.         PlayNote(j,1);
  1017.  
  1018.     Delay(32767L);
  1019.  
  1020.     for (i=1500;i>550;i-=4)
  1021.     PlayNote(i,30);
  1022.     PlayNote(140,100);
  1023.     for (i=1500;i>550;i-=4)
  1024.     PlayNote(i,30);
  1025.     PlayNote(140,100);
  1026.  
  1027.     Delay(32767L);
  1028.  
  1029.     for (i=1;i<9;i++)
  1030.     for (j=600;j<750;j+=8)
  1031.         PlayNote(j,10);
  1032.     for (i=1250;i>600;i-=8)
  1033.     PlayNote(i,10);
  1034.     PlayNote(200,100);
  1035.  
  1036.     Delay(32767L);
  1037.  
  1038.     for (i=1;i<21;i++)
  1039.     PlayNote(40,50);
  1040.  
  1041.     Delay(32767L);
  1042.  
  1043.     for (i=1200;i>350;i-=50)
  1044.     PlayNote(i,30);
  1045.  
  1046.     for (i=1200;i>350;i-=50)
  1047.     PlayNote(i,30);
  1048.  
  1049.     for (i=1200;i>350;i-=50)
  1050.     PlayNote(i,30);
  1051.  
  1052.  
  1053. }
  1054.