home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 371_01 / exampl6.c < prev    next >
Text File  |  1991-12-26  |  6KB  |  214 lines

  1. /***************************************************************************
  2. * EXAMPL6.C
  3. * Simple graphics demo
  4. * ****************************************************************************/
  5. #ifdef NOWINDOWS
  6. #include "borgraph.h"
  7. #include <stdio.h>
  8. #include <conio.h>
  9. #else
  10. #include <WinDosIO.h>
  11. #endif
  12. #include <stdlib.h>
  13. #include <memory.h>
  14.  
  15. char userFill[] = {0x18,0x7e,0x42,0xc3,0xc3,0x42,0x7e,0x18};
  16. short currentHandle;
  17. int gdriver = VGA,gmode=VGAMED;
  18. int midx, midy, x, y;
  19. int poly[8];
  20. int i,j;
  21. int size;
  22. char *bitmap;
  23. char msg[80];
  24. int hj, vj;
  25. char *hjust[] = {"LEFT","CENTER","RIGHT"};
  26. char *vjust[] = {"BOTTOM","CENTER","TOP"};
  27. struct arccoordstype ac;
  28.  
  29. main()
  30.   {
  31. #ifndef NOWINDOWS
  32.     WinDosIO(WD_SETTITLE,0,(long)"Graphics Demo");
  33. #endif
  34.     initgraph(&gdriver, &gmode, "");
  35.     if (x = graphresult())
  36.       {
  37.         printf("init graph error %d",x);
  38.         getch();
  39.         exit(1);
  40.          }
  41.     midx = getmaxx()/2;
  42.     midy = getmaxy()/2;
  43.  
  44.     for (i = 0; i < 5; i++)
  45.      {
  46.         for (j = 1; j < 10; j++)
  47.          {
  48.             settextstyle(i,0,j);
  49.             outtextxy(j * 40, i * 40,"A");
  50.          }
  51.      }
  52.     if (getch() < 0) return -1;
  53.     cleardevice();
  54.  
  55.     settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
  56.     moveto(0, midy);
  57.     outtext("Normal ");
  58.     printf("AAA");
  59.     settextstyle(TRIPLEX_FONT,HORIZ_DIR,0);
  60.     setusercharsize(1,3,1,1);
  61.     outtext("Short ");
  62.     setusercharsize(3,1,1,1);
  63.     outtext("Wide ");
  64.     if (getch() < 0) return -1;
  65.     cleardevice();
  66.     outtextxy(80,90,"This text should go over the view port");
  67.     setviewport(90,90,180,180,1);
  68.     setcolor(4);
  69.         outtextxy(0, 0, "This is a test, a test, yes a test.");
  70.     setcolor(1);
  71.     if (getch() < 0) return -1;
  72.     clearviewport();
  73.     if (getch() < 0) return -1;
  74.         outtextxy(0, 0, "This is a test, a test, yes a test.");
  75.     if (getch() < 0) return -1;
  76.     setgraphmode(gmode);
  77.     setactivepage(1);
  78.     setcolor(2);
  79.         outtextxy(midx, midy+40, "This is a test, a test, yes a test.");
  80.     setcolor(3);
  81.         outtextxy(midx, midy+60, "This is a test, a test, yes a test.");
  82.     setactivepage(0);
  83.     outtextxy(10,10,"Hit any key to see page #1");
  84.     if (getch() < 0) return -1;
  85.     setvisualpage(1);
  86.     if (getch() < 0) return -1;
  87.     setactivepage(1);
  88.     /* Place grid in upper corner */
  89.     for (x = 0; x < midx; x+= 10)
  90.      {
  91.         moveto(x,0);
  92.         lineto(x,midy);
  93.      }
  94.     setwritemode(XOR_PUT); /* Cause intersections to show */
  95.     setlinestyle(SOLID_LINE,0,THICK_WIDTH);
  96.     for (y = 0; y < midy; y+= 10)
  97.      {
  98.         moveto(0,y);
  99.         lineto(midx,y);
  100.      }
  101.     size = imagesize(10,10,40,50);
  102.     bitmap = malloc(size);
  103.     getimage(10,10,40,50,bitmap); 
  104.  
  105.     setwritemode(COPY_PUT);
  106.     circle(midx+60,60,10);
  107.     circle(midx+60,60,13);
  108.     circle(midx+60,60,16);
  109.     circle(midx+60,60,19);
  110.     circle(midx+60,60,22);
  111.     rectangle(midx+35,35,midx+85,85);
  112.     if (getch() < 0) return -1;
  113.     restorecrtmode();
  114.     gotoxy(2,2);
  115.     cprintf("Now in text mode");
  116.     if (getch() < 0) return -1;
  117.     setgraphmode(gmode);
  118.     outtextxy(50,50,"Back in graphics mode");
  119.     setviewport(130,130,230,230,1);
  120.     circle(10,10,10);
  121.     if (getch() < 0) return -1;
  122. #ifndef NOWINDOWS
  123.     WinDosIO(WD_DEFERPAINT,1,0);
  124. #endif
  125.     for (i = 0; i < 1000; i++)
  126.      {
  127.         putpixel(random(100), random(100), random(16));
  128.      }
  129. #ifndef NOWINDOWS
  130.     WinDosIO(WD_DEFERPAINT,0,0);
  131. #endif
  132.     if (getch() < 0) return -1;
  133.     setgraphmode(gmode);
  134.     setbkcolor(EGA_YELLOW);
  135.     bar3d(20,midy,40,midy+40,10,1);
  136.     setfillstyle(SOLID_FILL,1);
  137.     bar3d(60,midy,80,midy+40,20,0);
  138.     setfillstyle(LINE_FILL,1);
  139.     bar3d(100,midy,120,midy+40,30,1);
  140.     setfillstyle(LTSLASH_FILL,1);
  141.     bar(140,midy,160,midy+40);
  142.     setfillstyle(SLASH_FILL,1);
  143.     bar(180,midy,200,midy+40);
  144.     setfillstyle(BKSLASH_FILL,1);
  145.     bar(220,midy,240,midy+40);
  146.     setfillstyle(LTBKSLASH_FILL,1);
  147.     bar(260,midy,280,midy+40);
  148.     setfillstyle(HATCH_FILL,1);
  149.     bar(300,midy,320,midy+40);
  150.     setfillstyle(XHATCH_FILL,1);
  151.     bar(340,midy,360,midy+40);
  152.     setfillstyle(INTERLEAVE_FILL,1);
  153.     bar(380,midy,400,midy+40);
  154.     setfillstyle(WIDE_DOT_FILL,1);
  155.     bar(420,midy,440,midy+40);
  156.     setfillstyle(CLOSE_DOT_FILL,1);
  157.     bar(460,midy,480,midy+40);
  158.     setfillpattern(userFill,1);
  159.     bar(500,midy,520,midy+40);
  160.     if (getch() < 0) return -1;
  161.     setbkcolor(2);
  162.     arc(midx-5,midy-5,2,45,10);
  163.     arc(midx-5,midy-5,20,80,20);
  164.     arc(midx-5,midy-5,20,120,30);
  165.     getarccoords(&ac);
  166.     moveto(ac.xstart,ac.ystart);
  167.     lineto(200,200);
  168.     moveto(ac.xend,ac.yend);
  169.     lineto(ac.x, ac.y);
  170.     pieslice(midx+20,midy+50,0,30,50);
  171.     ellipse(midx+100,midy+100,45,135,60,30);
  172.     fillellipse(midx-100,midy-100,80,20);
  173.     sector(midx-100,midy+100,135,200,40,80);
  174.     if (getch() < 0) return -1;
  175.     cleardevice();
  176.     poly[0] = 20;
  177.     poly[1] = getmaxy() / 2;
  178.     poly[2] = getmaxx() - 20;
  179.     poly[3] = 20;
  180.     poly[4] = getmaxx() - 50;
  181.     poly[5] = getmaxy() - 20;
  182.     poly[6] = getmaxx() / 2;
  183.     poly[7] = getmaxy() / 2;
  184.     for (i = EMPTY_FILL; i < USER_FILL; i++)
  185.      {
  186.         setfillstyle(i, getmaxcolor());
  187.         fillpoly(4, poly);
  188.         putimage(200,100,bitmap,COPY_PUT);
  189.         if (getch() < 0) return -1;
  190.      }
  191.     circle(50,50,40);
  192.     setfillstyle(SOLID_FILL,4);
  193.     floodfill(50,50,getmaxcolor());
  194.     outtextxy(300,50,getdrivername());
  195.     outtextxy(350,60,getmodename(0));
  196.     outtextxy(350,80,getmodename(1));
  197.     outtextxy(350,100,getmodename(2));
  198.     if (getch() < 0) return -1;
  199.     cleardevice();
  200.     for (hj = LEFT_TEXT; hj <= RIGHT_TEXT; hj++)
  201.       for (vj = BOTTOM_TEXT; vj <= TOP_TEXT; vj++)
  202.        {
  203.         cleardevice();
  204.         settextjustify(hj, vj);
  205.         sprintf(msg,"%s-%s", hjust[hj], vjust[vj]);
  206.         line(midx-4, midy, midx+4, midy);
  207.         line(midx, midy - 4, midx, midy + 4);
  208.         outtextxy(midx, midy, msg);
  209.         if (getch() < 0) return -1;
  210.        }
  211.     closegraph();
  212.     return 0;
  213.  }
  214.