home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / mgl11 / examples / ffilltst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-10  |  4.0 KB  |  174 lines

  1. /****************************************************************************
  2. *
  3. *                        MegaGraph Graphics Library
  4. *
  5. *                   Copyright (C) 1994 SciTech Software.
  6. *                            All rights reserved.
  7. *
  8. * Filename:     $RCSfile: ffilltst.c $
  9. * Version:      $Revision: 1.2 $
  10. *
  11. * Language:        ANSI C
  12. * Environment:    IBM PC (MS DOS)
  13. *
  14. * Description:    Program to test the flood filling routines.
  15. *
  16. * $Id: ffilltst.c 1.2 1994/03/10 09:25:52 kjb release $
  17. *
  18. ****************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <time.h>
  23. #include <conio.h>
  24. #include <dos.h>
  25. #include <string.h>
  26. #include "mgraph.h"
  27. #include "ztimer.h"
  28.  
  29. /* Routines in main.c */
  30.  
  31. void four_dots(void);
  32. void init_graphics(char *testname,int argc,char *argv[]);
  33. void exit_graphics(void);
  34. void ReportTime(ulong count);
  35.  
  36. /* Function prototypes for the code in 'ffill.c' */
  37.  
  38. void MGL_interiorFill(int x,int y);
  39. void MGL_boundaryFill(int x,int y,color_t bdr);
  40.  
  41. /* We need a rather large stack to fill high resolution displays! */
  42.  
  43. extern unsigned _stklen = 30*1024;
  44.  
  45. #define MaxPts        6        /* Maximum # of pts in polygon    */
  46. #define    NUM            3
  47.  
  48. typedef    struct {
  49.     point    poly[MaxPts];
  50.     int        color;
  51.     } entry;
  52.  
  53. entry    table[NUM];
  54.  
  55. void main(int argc,char *argv[])
  56. {
  57.     color_t    maxcolor,backcolor;
  58.     int        maxx,maxy;
  59.     int     i,j;
  60.     ulong    count1,count2,count3,count4;
  61.  
  62.     init_graphics("Floodfill test",argc,argv);
  63.  
  64.     maxcolor = MGL_maxColor();
  65.     maxx = MGL_maxx();
  66.     maxy = MGL_maxy();
  67.  
  68.     srand(200);
  69.  
  70.     /* Draw a set of polygons */
  71.  
  72.     for (j = 0; j < NUM; j++) {
  73.         table[j].color = random(maxcolor);        /* Keep random in sync    */
  74.         table[j].color = (j == 0) ? BLUE : (j == 1) ? RED : YELLOW;
  75.  
  76.         for (i = 0; i < MaxPts; i++) {
  77.             table[j].poly[i].x = random(maxx);
  78.             table[j].poly[i].y = random(maxy);
  79.             }
  80.         }
  81.  
  82.     backcolor = MGL_getBackColor();
  83.     MGL_setBackColor(MGL_realColor(BLACK));
  84.     MGL_clearDevice();
  85.     MGL_setBackColor(backcolor);
  86.     for (j = 0; j < NUM; j++) {
  87.         MGL_setColor(MGL_realColor(table[j].color));
  88.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  89.         }
  90.  
  91.     MGL_setColor(MGL_realColor(RED));
  92.     MGL_lineCoord(0,0,10,20);
  93.  
  94.     getch();
  95.     MGL_setColor(MGL_realColor(GREEN));
  96.     LZTimerOn();
  97.     MGL_boundaryFill(10,10,MGL_realColor(RED));
  98.     LZTimerOff();
  99.     count1 = LZTimerCount();
  100.  
  101.     getch();
  102.  
  103.     backcolor = MGL_getBackColor();
  104.     MGL_setBackColor(MGL_realColor(BLACK));
  105.     MGL_clearDevice();
  106.     MGL_setBackColor(backcolor);
  107.     for (j = 0; j < NUM; j++) {
  108.         MGL_setColor(MGL_realColor(table[j].color));
  109.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  110.         }
  111.     MGL_setColor(MGL_realColor(WHITE));
  112.     MGL_rectCoord(0,0,maxx+1,maxy+1);
  113.  
  114.     MGL_setColor(MGL_realColor(RED));
  115.     MGL_lineCoord(0,0,10,20);
  116.  
  117.     getch();
  118.     MGL_setColor(MGL_realColor(GREEN));
  119.     LZTimerOn();
  120.     MGL_boundaryFill(10,10,MGL_realColor(RED));
  121.     LZTimerOff();
  122.     count2 = LZTimerCount();
  123.  
  124.     getch();
  125.  
  126.     backcolor = MGL_getBackColor();
  127.     MGL_setBackColor(MGL_realColor(BLACK));
  128.     MGL_clearDevice();
  129.     MGL_setBackColor(backcolor);
  130.     for (j = 0; j < NUM; j++) {
  131.         MGL_setColor(MGL_realColor(table[j].color));
  132.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  133.         }
  134.  
  135.     MGL_setColor(MGL_realColor(RED));
  136.     MGL_lineCoord(0,0,10,20);
  137.  
  138.     getch();
  139.     MGL_setColor(MGL_realColor(GREEN));
  140.     LZTimerOn();
  141.     MGL_interiorFill(10,10);
  142.     LZTimerOff();
  143.     count3 = LZTimerCount();
  144.  
  145.     getch();
  146.  
  147.     backcolor = MGL_getBackColor();
  148.     MGL_setBackColor(MGL_realColor(BLACK));
  149.     MGL_clearDevice();
  150.     MGL_setBackColor(backcolor);
  151.     for (j = 0; j < NUM; j++) {
  152.         MGL_setColor(MGL_realColor(table[j].color));
  153.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  154.         }
  155.     MGL_setColor(MGL_realColor(WHITE));
  156.     MGL_rectCoord(0,0,maxx+1,maxy+1);
  157.  
  158.     MGL_setColor(MGL_realColor(RED));
  159.     MGL_lineCoord(0,0,10,20);
  160.  
  161.     getch();
  162.     MGL_setColor(MGL_realColor(GREEN));
  163.     LZTimerOn();
  164.     MGL_interiorFill(10,10);
  165.     LZTimerOff();
  166.     count4 = LZTimerCount();
  167.  
  168.     exit_graphics();
  169.     ReportTime(count1);
  170.     ReportTime(count2);
  171.     ReportTime(count3);
  172.     ReportTime(count4);
  173. }
  174.