home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 14 / CD_ASCQ_14_0694.iso / maj / 4524 / svgadem1.c < prev    next >
C/C++ Source or Header  |  1994-05-09  |  26KB  |  1,168 lines

  1. /****************************************************************************
  2.      
  3.       'SVGACC' A Super Vga Graphics Library for use with Microsoft and
  4.       Borland C/C++
  5.       Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill
  6.  
  7.       GIF and 'Graphics Intechange Format' are trademarks (tm) of
  8.       Compuserve, Incorporated, an H&R Block Company.
  9.  
  10.     **************** UNREGISTERD SHAREWARE VERSION ***********************
  11.     * FOR EVUALATION ONLY. NOT FOR RESALE IN ANY FORM. SOFTWARE WRITTEN  *
  12.     * USING THIS UNREGISTERED SHAREWARE GRAPHICS LIBRARY MAY NOT BY SOLD *
  13.     * OR USED FOR ANY PURPOSE OTHER THAN THE EVUALTION OF THIS LIBRARY.  *
  14.     **********************************************************************
  15.  
  16.     **************** NO WARRANTIES AND NO LIABILITY **********************
  17.     * Stephen L. Balkum and Daniel A. Sill provide no warranties, either *
  18.     * expressed or implied, of merchantability, or fitness, for a        *
  19.     * particular use or purpose of this SOFTWARE and documentation.      *
  20.     * In no event shall Stephen L. Balkum or Daniel A. Sill be held      *
  21.     * liable for any damages resulting from the use or misuse of the     * 
  22.     * SOFTWARE and documentation.                                        *
  23.     **********************************************************************
  24.  
  25.     ************** U.S. GOVERNMENT RESTRICTED RIGHTS *********************
  26.     * Use, duplication, or disclosure of the SOFTWARE and documentation  *
  27.     * by the U.S. Government is subject to the restictions as set forth  *
  28.     * in subparagraph (c)(1)(ii) of the Rights in Technical Data and     *
  29.     * Computer Software cluse at DFARS 252.227-7013.                     *
  30.     * Contractor/manufacturer is Stephen L. Balkum and Daniel A. Sill,   *
  31.     * P.O. Box 7704, Austin, Texas 78713-7704                            *
  32.     **********************************************************************
  33.  
  34.     **********************************************************************
  35.     * By using this SOFTWARE or documentation, you agree to the above    *
  36.     * terms and conditions.                                              *
  37.     **********************************************************************
  38.  
  39.  ***************************************************************************/
  40.  
  41. #define MODULE
  42.  
  43. #include <stdio.h>
  44. #include <conio.h>
  45. #include <stdlib.h>
  46. #include <malloc.h>
  47. #include <string.h>
  48. #include <math.h>
  49.  
  50. #include "svgacc.h"
  51.  
  52. #include "svgademo.h"
  53.  
  54. #define randnum(size) (rand() % (int)(size))
  55.  
  56. /***********
  57.  * DOBLOCK *
  58.  ***********/
  59.  
  60. char doblock(void)
  61. {
  62.     int i, colr;
  63.     int xinc, yinc, x1, y1, x2, y2;
  64.     int cntx, cnty;
  65.     char ret;
  66.     char title[TITLEN];
  67.     char buf[TITLEN];
  68.     RasterBlock far *gfxblk;
  69.     RasterBlock far *gfxblk2;
  70.     RasterBlock far *spritebkgnd;
  71.  
  72.     /*
  73.      * Set up the Title
  74.      */
  75.     sprintf(title,"DEMO 5: Block function and Sprites");
  76.     palset(pal,0,255);
  77.  
  78.     /*
  79.      * Show Block Get (draw some circles and "get a chunk of them")
  80.      */
  81.  
  82.     fillscreen(0);
  83.     setview(0,0,maxx,maxy);
  84.     drwstring(1,7,0,title,10,0);
  85.     sprintf(buf,"blkget(x1,y1,x2,y2,GfxBlock);");
  86.     drwstring(1,7,0,buf,10,16);
  87.     colr = 16;
  88.     for(i=0;i<=maxx/2;i++) {
  89.         drwcircle(1,colr,maxx/4+i,maxy/2,maxy/5);
  90.         colr+=2;
  91.         if(colr>255)
  92.             colr = 16;
  93.     }
  94.     
  95.     xinc = maxx/20;
  96.     yinc = maxy/20;
  97.     x1 = maxx/2-xinc;
  98.     y1 = maxy/2-yinc;
  99.     x2 = maxx/2+xinc;
  100.     y2 = maxy/2+yinc;
  101.     i = (x2-x1+1)*(y2-y1+1)+4;
  102.     gfxblk = _fmalloc(i);
  103.     if (!gfxblk) {
  104.         restext();
  105.         printf("ERROR: Allocating memory for gfxblk: %d bytes\n",i);
  106.         exit(1);
  107.     }
  108.     drwbox(1,0,x1,y1,x2,y2);
  109.     blkget(x1,y1,x2,y2,gfxblk);
  110.     
  111.     ret = getkey();
  112.     if ((ret == 's') || (ret == 'q')) {
  113.         fillscreen(0);
  114.         _ffree(gfxblk);
  115.         return(ret);
  116.     }
  117.  
  118.     /*
  119.      * Show Block Rotate and Sprite Stuff
  120.      */
  121.     drwstring(1,7,0,title,10,0);
  122.     sprintf(buf,"blkrotate(angle,backfill,GfxBlockSrc,GfxBlockDst);");
  123.     drwstring(1,7,0,buf,10,16);
  124.     sprintf(buf,"spritegap(transcolor,x,y,SpriteArray,BkGndArray);");
  125.     drwstring(1,7,0,buf,10,32);
  126.     sprintf(buf,"spriteput(transcolor,x,y,SpriteArray);");
  127.     drwstring(1,7,0,buf,10,48);
  128.     cntx = (x2-x1) / 2 + x1;
  129.     cnty = (y2-y1) / 2 + y1;
  130.     fillarea(x1+2,y1+2,0,0);
  131.     i = blkrotatesize(45,gfxblk);
  132.     spritebkgnd = _fmalloc(i);
  133.     if (!spritebkgnd) {
  134.         restext();
  135.         printf("ERROR: Allocating memory for spritebkgnd: %d bytes\n",i);
  136.         exit(1);
  137.     }
  138.     gfxblk2 = _fmalloc(i);
  139.     if (!gfxblk2) {
  140.         restext();
  141.         printf("ERROR: Allocating memory for gfxblk2: %d bytes\n",i);
  142.         exit(1);
  143.     }
  144.     blkget(x1,y1,x2,y2,spritebkgnd);
  145.     setview(0,64,maxx,maxy);
  146.  
  147.     for(i=0;i<=360;i+=4) {
  148.         blkrotate(i,1,gfxblk,gfxblk2);
  149.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  150.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  151.         sdelay(4);
  152.     }
  153.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  154.     blkput(SET,x1,y1,gfxblk);
  155.  
  156.     setview(0,0,maxx,maxy);
  157.     ret = getkey();
  158.     if ((ret == 's') || (ret == 'q')) {
  159.         fillscreen(0);
  160.         palset(pal,16,255);
  161.         _ffree(gfxblk);
  162.         _ffree(gfxblk2);
  163.         _ffree(spritebkgnd);
  164.         return(ret);
  165.     }
  166.  
  167.     /*
  168.      * Show Block Resize and Sprite Stuff
  169.      */
  170.     drwstring(1,7,0,title,10,0);
  171.     sprintf(buf,"blkresize(Width,Height,GfxBlockSrc,GfxBlockDst);");
  172.     drwstring(1,7,0,buf,10,16);
  173.     sprintf(buf,"spritegap(transcolor,x,y,SpriteArray,BkGndArray);");
  174.     drwstring(1,7,0,buf,10,32);
  175.     sprintf(buf,"spriteput(transcolor,x,y,SpriteArray);");
  176.     drwstring(1,7,0,buf,10,48);
  177.     fillarea(x1+2,y1+2,0,0);
  178.     blkget(x1,y1,x2,y2,spritebkgnd);
  179.     setview(0,64,maxx,maxy);
  180.  
  181.     i = (x2-x1+1+xinc)*(y2-y1+1+xinc)+4;
  182.  
  183.     spritebkgnd = _frealloc(spritebkgnd,i);
  184.     if (!spritebkgnd) {
  185.         restext();
  186.         printf("ERROR: reallocating memory for spritebkgnd: %d bytes\n",i);
  187.         exit(1);
  188.     }
  189.  
  190.     gfxblk2 = _frealloc(gfxblk2,i);
  191.     if (!gfxblk2) {
  192.         restext();
  193.         printf("ERROR: reallocating memory for gfxblk2: %d bytes\n",i);
  194.         exit(1);
  195.     }
  196.  
  197.     for(i=0;i<=xinc;i++) {
  198.         blkresize((gfxblk->width)-i,(gfxblk->height)-i,gfxblk,gfxblk2);
  199.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  200.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  201.         sdelay(3);
  202.     }
  203.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  204.  
  205.     for(i=xinc;i>=0;i--) {
  206.         blkresize((gfxblk->width)-i,(gfxblk->height)-i,gfxblk,gfxblk2);
  207.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  208.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  209.         sdelay(3);
  210.     }
  211.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  212.     blkput(SET,x1,y1,gfxblk);
  213.  
  214.     ret = getkey();
  215.     if ((ret == 's') || (ret == 'q')) {
  216.         fillscreen(0);
  217.         palset(pal,16,255);
  218.         setview(0,0,maxx,maxy);
  219.         _ffree(gfxblk);
  220.         _ffree(gfxblk2);
  221.         _ffree(spritebkgnd);
  222.         return(ret);
  223.     }
  224.  
  225.  
  226.     /*
  227.      * Show Block Put (put the "chunks" randomly around the screen)
  228.      */
  229.     setview(0,16,maxx,32);
  230.     fillview(0);
  231.     sprintf(buf,"blkput(mode,x,y,GfxBlock);");
  232.     drwstring(1,7,0,buf,10,16);
  233.     xinc = maxx/10;
  234.     yinc = maxy/10;
  235.     setview(0,32,maxx,maxy);
  236.     for(i=0;i<=maxx/2;i++) {
  237.         x1 = randnum(maxx + xinc) - xinc;
  238.         y1 = randnum(maxy + yinc) - yinc;
  239.         blkput(1,x1,y1,gfxblk);
  240.     }
  241.  
  242.     _ffree(gfxblk);
  243.     _ffree(gfxblk2);
  244.     _ffree(spritebkgnd);
  245.     setview(0,0,maxx,maxy);
  246.     ret = getkey();
  247.     if ((ret == 's') || (ret == 'q')) {
  248.         fillscreen(0);
  249.         return(ret);
  250.     }
  251.  
  252.     return(ret);
  253.     
  254. }
  255.  
  256.  
  257.  
  258. /**********
  259.  * DOCLIP *
  260.  **********/
  261.  
  262. char doclip(void)
  263. {
  264.     struct dcoord {
  265.         int x1;
  266.         int x2;
  267.         int y1;
  268.         int y2;
  269.     };
  270.     
  271.     int i, j, k;
  272.     int xinc, x, y, x1, y1, x2, y2;
  273.     int xsub, radx, rady;
  274.     int wdth, hgth, spcingx, spcingy;
  275.     struct dcoord b[4];
  276.     char ret;
  277.     char title[TITLEN];
  278.     char buf[TITLEN];
  279.     
  280.     /*
  281.      * Set up the Title
  282.      */
  283.     sprintf(title,"DEMO 2: Clipping capability");
  284.     palset(pal,0,255);
  285.  
  286.     /*
  287.      * Set up the windows
  288.      */
  289.  
  290.     fillscreen(0);
  291.     setview(0,0,maxx,maxy);
  292.     drwstring(1,7,0,title,10,0);
  293.     sprintf(buf,"All pimitives automatically clip");
  294.     drwstring(1,7,0,buf,10,16);
  295.  
  296.     wdth = (maxx + 1) * 4 / 9;
  297.     spcingx = ((maxx + 1) - wdth * 2) / 3;
  298.     hgth = (maxy + 1 - 35) * 4 / 9;
  299.     spcingy = ((maxy + 1 - 35) - hgth * 2) / 3;
  300.     xinc = wdth * 3 / 2;
  301.     xsub = wdth / 4;
  302.     
  303.     b[0].x1 = spcingx;
  304.     b[0].x2 = b[0].x1 + wdth;
  305.     b[0].y1 = spcingy + 35;
  306.     b[0].y2 = b[0].y1 + hgth;
  307.  
  308.     b[1].x2 = maxx - spcingx;
  309.     b[1].x1 = b[1].x2 - wdth;
  310.     b[1].y1 = spcingy + 35;
  311.     b[1].y2 = b[1].y1 + hgth;
  312.  
  313.     b[2].x2 = maxx - spcingx;
  314.     b[2].x1 = b[2].x2 - wdth;
  315.     b[2].y2 = maxy - spcingy;
  316.     b[2].y1 = b[2].y2 - hgth;
  317.  
  318.     b[3].x1 = spcingx;
  319.     b[3].x2 = b[3].x1 + wdth;
  320.     b[3].y2 = maxy - spcingy;
  321.     b[3].y1 = b[3].y2 - hgth;
  322.  
  323.     for(i=0;i<4;i++)
  324.         drwbox(1,15,b[i].x1++,b[i].y1++,b[i].x2--,b[i].y2--);
  325.  
  326.     /*
  327.      * Show the clipping
  328.      */
  329.     for(i=0;i<=maxx/6;i++)
  330.         for(j=0;j<4;j++) {
  331.             setview(b[j].x1,b[j].y1,b[j].x2,b[j].y2);
  332.             switch (j) {
  333.                 case 0:
  334.                     for(k=0;k<6;k++) {
  335.                         x = b[j].x1 + randnum(xinc) - xsub;
  336.                         y = b[j].y1 + randnum(xinc) - xsub;
  337.                         drwpoint(1,randnum(16),x,y);
  338.                     }
  339.                     break;
  340.                 case 1:
  341.                     x1 = b[j].x1 + randnum(xinc) - xsub;
  342.                     y1 = b[j].y1 + randnum(xinc) - xsub;
  343.                     x2 = b[j].x1 + randnum(xinc) - xsub;
  344.                     y2 = b[j].y1 + randnum(xinc) - xsub;
  345.                     drwline(1,randnum(16),x1,y1,x2,y2);
  346.                     break;
  347.                 case 2:
  348.                     x = b[j].x1 + randnum(xinc) - xsub;
  349.                     y = b[j].y1 + randnum(xinc) - xsub;
  350.                     radx = randnum(wdth) / 2;
  351.                     drwcircle(1,randnum(16),x,y,radx);
  352.                     break;
  353.                 case 3:
  354.                     x = b[j].x1 + randnum(xinc) - xsub;
  355.                     y = b[j].y1 + randnum(xinc) - xsub;
  356.                     radx = randnum(wdth) / 2;
  357.                     rady = randnum(wdth) / 2;
  358.                     drwellipse(1,randnum(16),x,y,radx,rady);
  359.                     break;
  360.             }
  361.         }
  362.  
  363.     setview(0,0,maxx,maxy);
  364.  
  365.     ret = getkey();
  366.  
  367.     return(ret);
  368.     
  369. }
  370.  
  371. /**********
  372.  * DOFILL *
  373.  **********/
  374.  
  375. char dofill(void)
  376. {
  377.     struct dcoord {
  378.         int x1;
  379.         int x2;
  380.         int y1;
  381.         int y2;
  382.     };
  383.     
  384.     int i, colr;
  385.     int x, y;
  386.     int radx, rady;
  387.     int wdth, hgth, spcingx, spcingy;
  388.     struct dcoord b[4];
  389.     char ret;
  390.     char title[TITLEN];
  391.     char buf[TITLEN];
  392.     
  393.     /*
  394.      * Set up the Title
  395.      */
  396.     sprintf(title,"DEMO 3: Filling functions");
  397.     palset(pal,0,255);
  398.  
  399.     /*
  400.      * Set up the windows
  401.      */
  402.  
  403.     fillscreen(10);
  404.     setview(0,0,maxx,maxy);
  405.     drwstring(1,7,0,title,10,0);
  406.     sprintf(buf,"fillscreen(color);");
  407.     drwstring(1,7,0,buf,10,16);
  408.  
  409.     ret = getkey();
  410.     if ((ret == 's') || (ret == 'q'))
  411.         return(ret);
  412.     
  413.     /*
  414.      * Set up windows and show viewport fill
  415.      */
  416.     fillscreen(0);
  417.     drwstring(1,7,0,title,10,0);
  418.     sprintf(buf,"fillview(color);");
  419.     drwstring(1,7,0,buf,10,16);
  420.     
  421.     wdth = (maxx + 1) * 4 / 9;
  422.     spcingx = ((maxx + 1) - wdth * 2) / 3;
  423.     hgth = (maxy + 1 - 35) * 4 / 9;
  424.     spcingy = ((maxy + 1 - 35) - hgth * 2) / 3;
  425.  
  426.     b[0].x1 = spcingx;
  427.     b[0].x2 = b[0].x1 + wdth;
  428.     b[0].y1 = spcingy + 35;
  429.     b[0].y2 = b[0].y1 + hgth;
  430.  
  431.     b[1].x2 = maxx - spcingx;
  432.     b[1].x1 = b[1].x2 - wdth;
  433.     b[1].y1 = spcingy + 35;
  434.     b[1].y2 = b[1].y1 + hgth;
  435.  
  436.     b[2].x2 = maxx - spcingx;
  437.     b[2].x1 = b[2].x2 - wdth;
  438.     b[2].y2 = maxy - spcingy;
  439.     b[2].y1 = b[2].y2 - hgth;
  440.  
  441.     b[3].x1 = spcingx;
  442.     b[3].x2 = b[3].x1 + wdth;
  443.     b[3].y2 = maxy - spcingy;
  444.     b[3].y1 = b[3].y2 - hgth;
  445.  
  446.     for(i=0;i<4;i++)
  447.         drwbox(1,15,b[i].x1++,b[i].y1++,b[i].x2--,b[i].y2--);
  448.  
  449.     ret = getkey();
  450.     if ((ret == 's') || (ret == 'q')) {
  451.         setview(0,0,maxx,maxy);
  452.         return(ret);
  453.     }
  454.     
  455.     /*
  456.      * Show the clipping
  457.      */
  458.     for(i=0;i<4;i++) {
  459.         setview(b[i].x1,b[i].y1,b[i].x2,b[i].y2);
  460.         fillview(i+10);
  461.     }
  462.  
  463.     setview(0,0,maxx,maxy);
  464.     ret = getkey();
  465.     if ((ret == 's') || (ret == 'q'))
  466.         return(ret);
  467.     
  468.     /*
  469.      * Set up windows and show area fill
  470.      */
  471.     fillscreen(0);
  472.     drwstring(1,7,0,title,10,0);
  473.     sprintf(buf,"fillarea(xseed,yseed,bordercolor,fillcolor);");
  474.     drwstring(1,7,0,buf,10,16);
  475.  
  476.     drwbox(1,15,5,35,maxx-4,maxy-4);
  477.     setview(6,36,maxx-5,maxy-5);
  478.  
  479.     colr=1;
  480.     for(i=0;i<=maxx/10;i++) {
  481.         x = 50 + randnum(maxx-50);
  482.         y = 50 + randnum(maxy-50);
  483.         radx = 2 + randnum(maxx/20);
  484.         rady = 2 + randnum(maxy/20);
  485.         drwellipse(1,colr++,x,y,radx,rady);
  486.         if (colr>10)
  487.             colr = 1;
  488.     }
  489.  
  490.     for(i=0;i<=maxx/15;i++) {
  491.         x = 50 + randnum(maxx-50);
  492.         y = 50 + randnum(maxy-50);
  493.         radx = 2 + randnum(maxx/20);
  494.         rady = 2 + randnum(maxy/20);
  495.         drwellipse(1,12,x,y,radx,rady);
  496.     }
  497.     
  498.     ret = getkey();
  499.     if ((ret == 's') || (ret == 'q')) {
  500.         setview(0,0,maxx,maxy);
  501.         return(ret);
  502.     }
  503.  
  504.     fillarea(7,37,12,10);
  505.     
  506.     setview(0,0,maxx,maxy);
  507.     ret = getkey();
  508.     if ((ret == 's') || (ret == 'q'))
  509.         return(ret);
  510.     
  511.     /*    
  512.      * Setup windows and show color fill
  513.      */
  514.     fillscreen(0);
  515.     drwstring(1,7,0,title,10,0);
  516.     sprintf(buf,"fillcolor(xseed,yseed,oldcolor,fillcolor);");
  517.     drwstring(1,7,0,buf,10,16);
  518.  
  519.     drwbox(1,15,5,35,maxx-4,maxy-4);
  520.     setview(6,36,maxx-5,maxy-5);
  521.  
  522.     colr=1;
  523.     for(i=0;i<=maxx/10;i++) {
  524.         x = 50 + randnum(maxx-50);
  525.         y = 50 + randnum(maxy-50);
  526.         radx = 2 + randnum(maxx/20);
  527.         rady = 2 + randnum(maxy/20);
  528.         drwellipse(1,colr++,x,y,radx,rady);
  529.         if (colr>10)
  530.             colr = 1;
  531.     }
  532.  
  533.     for(i=0;i<=maxx/15;i++) {
  534.         x = 50 + randnum(maxx-50);
  535.         y = 50 + randnum(maxy-50);
  536.         radx = 2 + randnum(maxx/20);
  537.         rady = 2 + randnum(maxy/20);
  538.         drwellipse(1,12,x,y,radx,rady);
  539.     }
  540.     
  541.     ret = getkey();
  542.     if ((ret == 's') || (ret == 'q')) {
  543.         setview(0,0,maxx,maxy);
  544.         return(ret);
  545.     }
  546.  
  547.     fillcolor(7,37,0,10);
  548.  
  549.     setview(0,0,maxx,maxy);
  550.  
  551.     ret = getkey();
  552.  
  553.     return(ret);
  554.     
  555. }
  556.  
  557.  
  558. /*********
  559.  * DOPAL *
  560.  *********/
  561.  
  562. char dopal(void)
  563. {
  564.     int x1, x2, y1, y2;
  565.     int i, colr;
  566.     char ret;
  567.     char title[TITLEN];
  568.     char buf[TITLEN];
  569.     
  570.     /*
  571.      * Set up the Title
  572.      */
  573.     sprintf(title,"DEMO 4: Palette functions");
  574.     palset(orgpal,0,255);
  575.  
  576.     /*
  577.      * Show palette set/get
  578.      */
  579.  
  580.     fillscreen(0);
  581.     setview(0,0,maxx,maxy);
  582.     drwstring(1,7,0,title,10,0);
  583.     sprintf(buf,"palget(pal,beg,end),palset(pal,beg,end)");
  584.     drwstring(1,7,0,buf,10,16);
  585.  
  586.     colr = 16;
  587.     x1 = 10;
  588.     x2 = maxx - 9;
  589.     y1 = 35;
  590.     y2 = maxy - 9;
  591.     i = 0;
  592.     while (y1+i < y2-i) {
  593.         drwbox(1,colr++,x1+i,y1+i,x2-i,y2-i);
  594.         if (colr>255)
  595.             colr = 16;
  596.         i++;
  597.     }
  598.     ret = getkey();
  599.     if ((ret == 's') || (ret == 'q')) {
  600.         fillscreen(0);
  601.         setview(0,0,maxx,maxy);
  602.         return(ret);
  603.     }
  604.     palset(pal,16,255);
  605.     ret = getkey();
  606.     if ((ret == 's') || (ret == 'q')) {
  607.         setview(0,0,maxx,maxy);
  608.         fillscreen(0);
  609.         return(ret);
  610.     }
  611.  
  612.     /*
  613.      * Show palette auto fade out/in
  614.      */
  615.     setview(0,16,maxx,32);
  616.     fillview(0);
  617.     sprintf(buf,"palioauto(pal,beg,end,speed);");
  618.     drwstring(1,7,0,buf,10,16);
  619.     palioauto(pal,16,255,-2);
  620.     palioauto(pal,16,255,2);
  621.     ret = getkey();
  622.     if ((ret == 's') || (ret == 'q')) {
  623.         setview(0,0,maxx,maxy);
  624.         return(ret);
  625.     }
  626.  
  627.     /*
  628.      * Show palette auto fade to
  629.      */
  630.     setview(0,16,maxx,32);
  631.     fillview(0);
  632.     sprintf(buf,"palchgauto(pal,newpal,beg,end,speed);");
  633.     drwstring(1,7,0,buf,10,16);
  634.     palchgauto(pal,pal2,16,255,2);
  635.     palchgauto(pal2,pal,16,255,2);
  636.     ret = getkey();
  637.     if ((ret == 's') || (ret == 'q')) {
  638.         setview(0,0,maxx,maxy);
  639.         return(ret);
  640.     }
  641.  
  642.     /*
  643.      * Show palette rotate
  644.      */
  645.     setview(0,16,maxx,32);
  646.     fillview(0);
  647.     sprintf(buf,"palrotate(pal,beg,end,shift);");
  648.     drwstring(1,7,0,buf,10,16);
  649.     for(i=0;i<=240;i++) {
  650.         palrotate(pal,16,255,2);
  651.         palget(pal,16,255);
  652.     }
  653.     for(i=0;i<=120;i++) {
  654.         palrotate(pal,16,255,-8);
  655.         palget(pal,16,255);
  656.     }
  657.     ret = getkey();
  658.     if ((ret == 's') || (ret == 'q'))
  659.         setview(0,0,maxx,maxy);
  660.  
  661.     return(ret);
  662.  
  663. }
  664.  
  665.  
  666. /***********
  667.  * DOPRIMS *
  668.  ***********/
  669.  
  670. char doprims(void)
  671. {
  672.     int x1, x2, y1, y2;
  673.     int maxrad, radx, rady;
  674.     int i, colr, num;
  675.     char ret;
  676.     char title[TITLEN];
  677.     char buf[TITLEN];
  678.     
  679.     /*
  680.      * Set up the Title
  681.      */
  682.     sprintf(title,"DEMO 1: Primitives");
  683.     palset(orgpal,0,255);
  684.  
  685.     /*
  686.      * Draw some points
  687.      */
  688.  
  689.     fillscreen(0);
  690.     setview(0,0,maxx,maxy);
  691.     drwstring(1,7,0,title,10,0);
  692.     sprintf(buf,"drwpoint(mode,color,x,y);");
  693.     drwstring(1,7,0,buf,10,16);
  694.     setview(0,32,maxx,maxy);
  695.     colr = 1;
  696.     num = maxx * 2;
  697.     for(i=0;i<num;i++) {
  698.         x1 = randnum(maxx);
  699.         y1 = randnum(maxy);
  700.         drwpoint(1,colr++,x1,y1);
  701.         if (colr>15)
  702.             colr = 1;
  703.     }   
  704.     setview(0,0,maxx,maxy);
  705.     ret = getkey();
  706.     if ((ret=='s') || (ret=='q'))
  707.         return(ret);
  708.     
  709.     /*
  710.      * Draw some lines
  711.      */
  712.     fillscreen(0);
  713.     setview(0,0,maxx,maxy);
  714.     drwstring(1,7,0,title,10,0);
  715.     sprintf(buf,"drwline(mode,color,x1,y1,x2,y2);");
  716.     drwstring(1,7,0,buf,10,16);
  717.     setview(0,32,maxx,maxy);
  718.     colr = 1;
  719.     num = maxx / 6;
  720.     for(i=0;i<num;i++) {
  721.         x1 = randnum(maxx);
  722.         y1 = randnum(maxy);
  723.         x2 = randnum(maxx);
  724.         y2 = randnum(maxy);
  725.         drwline(1,colr++,x1,y1,x2,y2);
  726.         if (colr>15)
  727.             colr = 1;
  728.     }   
  729.     setview(0,0,maxx,maxy);
  730.     ret = getkey();
  731.     if ((ret=='s') || (ret=='q'))
  732.         return(ret);
  733.  
  734.     /*
  735.      * Draw some boxes
  736.      */
  737.     fillscreen(0);
  738.     setview(0,0,maxx,maxy);
  739.     drwstring(1,7,0,title,10,0);
  740.     sprintf(buf,"drwbox(mode,color,x1,y1,x2,y2);");
  741.     drwstring(1,7,0,buf,10,16);
  742.     setview(0,32,maxx,maxy);
  743.     colr = 1;
  744.     num = maxx / 10;
  745.     for(i=0;i<num;i++) {
  746.         x1 = randnum(maxx);
  747.         y1 = randnum(maxy);
  748.         x2 = randnum(maxx);
  749.         y2 = randnum(maxy);
  750.         drwbox(1,colr++,x1,y1,x2,y2);
  751.         if (colr>15)
  752.             colr = 1;
  753.     }   
  754.     setview(0,0,maxx,maxy);
  755.     ret = getkey();
  756.     if ((ret=='s') || (ret=='q'))
  757.         return(ret);
  758.  
  759.     /*
  760.      * Draw some filled boxes
  761.      */
  762.     fillscreen(0);
  763.     setview(0,0,maxx,maxy);
  764.     drwstring(1,7,0,title,10,0);
  765.     sprintf(buf,"drwfillbox(mode,color,x1,y1,x2,y2);");
  766.     drwstring(1,7,0,buf,10,16);
  767.     setview(0,32,maxx,maxy);
  768.     colr = 1;
  769.     num = maxx / 15;
  770.     for(i=0;i<num;i++) {
  771.         x1 = randnum(maxx);
  772.         y1 = randnum(maxy);
  773.         x2 = randnum(maxx);
  774.         y2 = randnum(maxy);
  775.         drwfillbox(1,colr++,x1,y1,x2,y2);
  776.         if (colr>15)
  777.             colr = 1;
  778.     }
  779.     setview(0,0,maxx,maxy);
  780.     ret = getkey();
  781.     if ((ret=='s') || (ret=='q'))
  782.         return(ret);
  783.  
  784.     /*
  785.      * Draw some circles
  786.      */
  787.     fillscreen(0);
  788.     setview(0,0,maxx,maxy);
  789.     drwstring(1,7,0,title,10,0);
  790.     sprintf(buf,"drwcircle(mode,color,cx,cy,radius);");
  791.     drwstring(1,7,0,buf,10,16);
  792.     setview(0,32,maxx,maxy);
  793.     colr = 1;
  794.     num = maxx / 20;
  795.     maxrad = maxx / 2;
  796.     for(i=0;i<num;i++) {
  797.         x1 = randnum(maxx);
  798.         y1 = randnum(maxy);
  799.         radx = randnum(maxrad);
  800.         drwcircle(1,colr++,x1,y1,radx);
  801.         if (colr>15)
  802.             colr = 1;
  803.     }
  804.     setview(0,0,maxx,maxy);
  805.     ret = getkey();
  806.     if ((ret=='s') || (ret=='q'))
  807.         return(ret);
  808.  
  809.     /*
  810.      * Draw some filled circles
  811.      */
  812.     fillscreen(0);
  813.     setview(0,0,maxx,maxy);
  814.     drwstring(1,7,0,title,10,0);
  815.     sprintf(buf,"drwfillcircle(mode,color,cx,cy,radius);");
  816.     drwstring(1,7,0,buf,10,16);
  817.     setview(0,32,maxx,maxy);
  818.     colr = 1;
  819.     num = maxx / 25;
  820.     maxrad = maxx / 2;
  821.     for(i=0;i<num;i++) {
  822.         x1 = randnum(maxx);
  823.         y1 = randnum(maxy);
  824.         radx = randnum(maxrad);
  825.         drwfillcircle(1,colr++,x1,y1,radx);
  826.         if (colr>15)
  827.             colr = 1;
  828.     }
  829.     setview(0,0,maxx,maxy);
  830.     ret = getkey();
  831.     if ((ret=='s') || (ret=='q'))
  832.         return(ret);
  833.  
  834.     /*
  835.      * Draw some ellipses
  836.      */
  837.     fillscreen(0);
  838.     setview(0,0,maxx,maxy);
  839.     drwstring(1,7,0,title,10,0);
  840.     sprintf(buf,"drwellipse(mode,color,cx,cy,radiusx,radiusy);");
  841.     drwstring(1,7,0,buf,10,16);
  842.     setview(0,32,maxx,maxy);
  843.     colr = 1;
  844.     num = maxx / 20;
  845.     maxrad = maxx / 2;
  846.     for(i=0;i<num;i++) {
  847.         x1 = randnum(maxx);
  848.         y1 = randnum(maxy);
  849.         radx = randnum(maxrad);
  850.         rady = randnum(maxrad);
  851.         drwellipse(1,colr++,x1,y1,radx,rady);
  852.         if (colr>15)
  853.             colr = 1;
  854.     }   
  855.     setview(0,0,maxx,maxy);
  856.     ret = getkey();
  857.  
  858.     /*
  859.      * Draw some filled ellipses
  860.      */
  861.     fillscreen(0);
  862.     setview(0,0,maxx,maxy);
  863.     drwstring(1,7,0,title,10,0);
  864.     sprintf(buf,"drwfillellipse(mode,color,cx,cy,radiusx,radiusy);");
  865.     drwstring(1,7,0,buf,10,16);
  866.     setview(0,32,maxx,maxy);
  867.     colr = 1;
  868.     num = maxx / 25;
  869.     maxrad = maxx / 2;
  870.     for(i=0;i<num;i++) {
  871.         x1 = randnum(maxx);
  872.         y1 = randnum(maxy);
  873.         radx = randnum(maxrad);
  874.         rady = randnum(maxrad);
  875.         drwfillellipse(1,colr++,x1,y1,radx,rady);
  876.         if (colr>15)
  877.             colr = 1;
  878.     }
  879.     setview(0,0,maxx,maxy);
  880.     ret = getkey();
  881.  
  882.  
  883.     return(ret);
  884.  
  885. }
  886.  
  887.  
  888. /************
  889.  * DOSCROLL *
  890.  ************/
  891.  
  892. char doscroll(void)
  893. {
  894.     int i, colr, num, totnum;
  895.     int a, b, c, d;
  896.     int x1, x2, y1, y2;
  897.     int spcing, skip;
  898.     char ret;
  899.     char title[TITLEN];
  900.     char buf[TITLEN];
  901.     char buf2[TITLEN];
  902.     
  903.     /*
  904.      * Set up the Title
  905.      */
  906.     sprintf(title,"DEMO 7: Scroll functions");
  907.     palset(pal,0,255);
  908.     fillscreen(0);
  909.     setview(0,0,maxx,maxy);
  910.     drwstring(1,7,0,title,10,0);
  911.     
  912.     spcing = (maxy - 32) / 5;
  913.     skip = (int)(((float)maxx + 1.) / 320. + .9) * 2 - 1;
  914.     num = spcing / 2 / skip;
  915.     if (spcing / 2 != (float)spcing / 2.)
  916.         spcing++;
  917.     x1 = (maxx + 1) / 2 - spcing;
  918.     y1 = (maxy + 1 - 32) / 2 + 32 - spcing;
  919.     x2 = (maxx + 1) / 2 + spcing;
  920.     y2 = (maxy + 1 - 32) / 2 + 32 + spcing;
  921.  
  922.     drwbox(1,12,x1++,y1++,x2--,y2--);
  923.     colr = 16;
  924.     sprintf(buf2,"TEXT text TEXT");
  925.  
  926.     /*
  927.      * Show scrollup
  928.      */
  929.     setview(0,16,maxx,maxy);
  930.     sprintf(buf,"scrollup(x1,y1,x2,y2,numlines,fillcolor);");
  931.     drwstring(1,7,0,buf,10,16);
  932.     setview(x1,y1,x2,y2);
  933.     fillview(0);
  934.     totnum = maxx / 10;
  935.     for(i=0;i<totnum;i++) {
  936.         a = randnum(maxx);
  937.         b = randnum(maxy);
  938.         c = randnum(maxx);
  939.         d = randnum(maxy);
  940.         drwline(1,colr,a,b,c,d);
  941.         colr += 3;
  942.         if (colr > 255)
  943.             colr = 16;
  944.     }
  945.     drwstring(1,7,0,buf2,x1+spcing,y1+spcing);
  946.     drwstringlt(1,7,0,buf2,x1+spcing,y1+spcing);
  947.     drwstringrt(1,7,0,buf2,x1+spcing,y1+spcing);
  948.     drwstringdn(1,7,0,buf2,x1+spcing,y1+spcing);
  949.  
  950.     ret = getkey();
  951.     if ((ret=='s') || (ret=='q'))
  952.         return(ret);
  953.  
  954.     for(i=0;i<num;i++)
  955.         scrollup(x1,y1,x2,y2,skip,0);
  956.  
  957.     ret = getkey();
  958.     if ((ret=='s') || (ret=='q'))
  959.         return(ret);
  960.  
  961.     /*
  962.      * Show scrolllt
  963.      */
  964.     setview(0,16,maxx,maxy);
  965.     sprintf(buf,"scrolllt(x1,y1,x2,y2,numlines,fillcolor);");
  966.     drwstring(1,7,0,buf,10,16);
  967.     setview(x1,y1,x2,y2);
  968.     fillview(0);
  969.     totnum = maxx / 10;
  970.     for(i=0;i<totnum;i++) {
  971.         a = randnum(maxx);
  972.         b = randnum(maxy);
  973.         c = randnum(maxx);
  974.         d = randnum(maxy);
  975.         drwline(1,colr,a,b,c,d);
  976.         colr += 3;
  977.         if (colr > 255)
  978.             colr = 16;
  979.     }
  980.     drwstring(1,7,0,buf2,x1+spcing,y1+spcing);
  981.     drwstringlt(1,7,0,buf2,x1+spcing,y1+spcing);
  982.     drwstringrt(1,7,0,buf2,x1+spcing,y1+spcing);
  983.     drwstringdn(1,7,0,buf2,x1+spcing,y1+spcing);
  984.  
  985.     ret = getkey();
  986.     if ((ret=='s') || (ret=='q'))
  987.         return(ret);
  988.  
  989.     for(i=0;i<num;i++)
  990.         scrolllt(x1,y1,x2,y2,skip,0);
  991.  
  992.     ret = getkey();
  993.     if ((ret=='s') || (ret=='q'))
  994.         return(ret);
  995.  
  996.     /*
  997.      * Show scrolldn
  998.      */
  999.     setview(0,16,maxx,maxy);
  1000.     sprintf(buf,"scrolldn(x1,y1,x2,y2,numlines,fillcolor);");
  1001.     drwstring(1,7,0,buf,10,16);
  1002.     setview(x1,y1,x2,y2);
  1003.     fillview(0);
  1004.     totnum = maxx / 10;
  1005.     for(i=0;i<totnum;i++) {
  1006.         a = randnum(maxx);
  1007.         b = randnum(maxy);
  1008.         c = randnum(maxx);
  1009.         d = randnum(maxy);
  1010.         drwline(1,colr,a,b,c,d);
  1011.         colr += 3;
  1012.         if (colr > 255)
  1013.             colr = 16;
  1014.     }
  1015.     drwstring(1,7,0,buf2,x1+spcing,y1+spcing);
  1016.     drwstringlt(1,7,0,buf2,x1+spcing,y1+spcing);
  1017.     drwstringrt(1,7,0,buf2,x1+spcing,y1+spcing);
  1018.     drwstringdn(1,7,0,buf2,x1+spcing,y1+spcing);
  1019.  
  1020.     ret = getkey();
  1021.     if ((ret=='s') || (ret=='q'))
  1022.         return(ret);
  1023.  
  1024.     for(i=0;i<num;i++)
  1025.         scrolldn(x1,y1,x2,y2,skip,0);
  1026.  
  1027.     ret = getkey();
  1028.     if ((ret=='s') || (ret=='q'))
  1029.         return(ret);
  1030.  
  1031.     /*
  1032.      * Show scrollrt
  1033.      */
  1034.     setview(0,16,maxx,maxy);
  1035.     sprintf(buf,"scrollrt(x1,y1,x2,y2,numlines,fillcolor);");
  1036.     drwstring(1,7,0,buf,10,16);
  1037.     setview(x1,y1,x2,y2);
  1038.     fillview(0);
  1039.     totnum = maxx / 10;
  1040.     for(i=0;i<totnum;i++) {
  1041.         a = randnum(maxx);
  1042.         b = randnum(maxy);
  1043.         c = randnum(maxx);
  1044.         d = randnum(maxy);
  1045.         drwline(1,colr,a,b,c,d);
  1046.         colr += 3;
  1047.         if (colr > 255)
  1048.             colr = 16;
  1049.     }
  1050.     drwstring(1,7,0,buf2,x1+spcing,y1+spcing);
  1051.     drwstringlt(1,7,0,buf2,x1+spcing,y1+spcing);
  1052.     drwstringrt(1,7,0,buf2,x1+spcing,y1+spcing);
  1053.     drwstringdn(1,7,0,buf2,x1+spcing,y1+spcing);
  1054.  
  1055.     ret = getkey();
  1056.     if ((ret=='s') || (ret=='q'))
  1057.         return(ret);
  1058.  
  1059.     for(i=0;i<num;i++)
  1060.         scrollrt(x1,y1,x2,y2,skip,0);
  1061.  
  1062.     ret = getkey();
  1063.  
  1064.     return(ret);
  1065.  
  1066. }
  1067.  
  1068.  
  1069. /**********
  1070.  * DOTEXT *
  1071.  **********/
  1072.  
  1073. char dotext(void)
  1074. {
  1075.     int i, colr;
  1076.     char ret;
  1077.     char title[TITLEN];
  1078.     char buf[TITLEN];
  1079.     char buf2[TITLEN];
  1080.  
  1081.     /*
  1082.      * Set up the Title
  1083.      */
  1084.     sprintf(title,"DEMO 6: Text functions");
  1085.     palset(pal,0,255);
  1086.  
  1087.     /*
  1088.      * Show alternate print directions
  1089.      */
  1090.     fillscreen(0);
  1091.     setview(0,0,maxx,maxy);
  1092.     drwstring(1,7,0,title,10,0);
  1093.     sprintf(buf,"drwstring(mode,foregnd,bkgnd,string,x,y);");
  1094.     drwstring(1,7,0,buf,10,16);
  1095.     setview(0,32,maxx,maxy);
  1096.     sprintf(buf2,"The Quick Brown Fox Jumped Over The Lazy Dog's Back! 0123456789");
  1097.     colr = 16;
  1098.     for(i=32;i<=maxy;i+=20) {
  1099.         drwstring(1,colr,0,buf2,0,i);
  1100.         colr+=5;
  1101.         if (colr>255)
  1102.             colr = 16;
  1103.     }
  1104.     ret = getkey();
  1105.     if ((ret=='s') || (ret=='q')) {
  1106.         setview(0,0,maxx,maxy);
  1107.         fillscreen(0);
  1108.         return(ret);
  1109.     }
  1110.  
  1111.     fillview(0);
  1112.     setview(0,16,maxx,32);
  1113.     sprintf(buf,"drwstringlt(mode,foregnd,bkgnd,string,x,y);");
  1114.     drwstring(1,7,0,buf,10,16);
  1115.     setview(0,32,maxx,maxy);
  1116.     colr = 16;
  1117.     for(i=0;i<=maxx;i+=20) {
  1118.         drwstringlt(1,colr,0,buf2,i,maxy);
  1119.         colr+=5;
  1120.         if (colr>255)
  1121.             colr = 16;
  1122.     }
  1123.     ret = getkey();
  1124.     if ((ret=='s') || (ret=='q')) {
  1125.         setview(0,0,maxx,maxy);
  1126.         fillscreen(0);
  1127.         return(ret);
  1128.     }
  1129.  
  1130.     fillview(0);
  1131.     setview(0,16,maxx,32);
  1132.     sprintf(buf,"drwstringdn(mode,foregnd,bkgnd,string,x,y);");
  1133.     drwstring(1,7,0,buf,10,16);
  1134.     setview(0,32,maxx,maxy);
  1135.     colr = 16;
  1136.     for(i=maxy;i>=32;i-=20) {
  1137.         drwstringdn(1,colr,0,buf2,maxx,i);
  1138.         colr+=5;
  1139.         if (colr>255)
  1140.             colr = 16;
  1141.     }
  1142.     ret = getkey();
  1143.     if ((ret=='s') || (ret=='q')) {
  1144.         setview(0,0,maxx,maxy);
  1145.         fillscreen(0);
  1146.         return(ret);
  1147.     }
  1148.  
  1149.     fillview(0);
  1150.     setview(0,16,maxx,32);
  1151.     sprintf(buf,"drwstringrt(mode,foregnd,bkgnd,string,x,y);");
  1152.     drwstring(1,7,0,buf,10,16);
  1153.     setview(0,32,maxx,maxy);
  1154.     colr = 16;
  1155.     for(i=maxx;i>=0;i-=20) {
  1156.         drwstringrt(1,colr,0,buf2,i,32);
  1157.         colr+=5;
  1158.         if (colr>255)
  1159.             colr = 16;
  1160.     }
  1161.     ret = getkey();
  1162.     setview(0,0,maxx,maxy);
  1163.     fillscreen(0);
  1164.  
  1165.     return(ret);
  1166.  
  1167. }
  1168.