home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / FC20C.ZIP / ROBOFACE.C < prev    next >
C/C++ Source or Header  |  1990-08-20  |  2KB  |  112 lines

  1. /*
  2.  * This function draws a very crude "robot" face on the PC video
  3.  * screen, using block characters on an 80x25 matrix. In addition
  4.  * to entertaining children, it shows some simple techniques for
  5.  * drawing lines, boxes and circles, which could be applied to
  6.  * higher resolution graphics modes.
  7.  *
  8.  * Copyright 1990 Dave Dunfield
  9.  * All rights reserved.
  10.  */
  11.  
  12. #include \mc\stdio.h        /* Standard I/O definitions */
  13. #include \mc\video.h        /* Video    I/O definitions */
  14.  
  15. #define    PCHR    0xDB
  16.  
  17. /*
  18.  * Main program, draw the face
  19.  */
  20. main()
  21. {
  22.     int i;
  23.  
  24.     vopen();
  25.     vcursor_off();
  26.     box(1, 0, 77, 24);
  27.     for(i=1; i < 5; ++i) {
  28.         circle(17, 8, i);
  29.         circle(60, 8, i); }
  30.     circle(17, 8, 6);
  31.     circle(60, 8, 6);
  32.     line(38, 9, 42, 13);
  33.     line(38, 9, 34, 13);
  34.     line(35, 13, 41, 13);
  35.     box(24, 18, 53, 21);
  36.     vgetc();
  37.     vcursor_line();
  38.     vclscr();
  39. }
  40.  
  41. /*
  42.  * Draw a line from point (x1, y1) to (x2, y2)
  43.  */
  44. line(x1, y1, x2, y2)
  45.     int x1, y1, x2, y2;
  46. {
  47.     int i, w, h;
  48.  
  49.     /* If 'X' is greater, increment through 'X' coordinate */
  50.     if((w = abs(x1 - x2)) >= (h = abs(y1 - y2))) {
  51.         if(x1 > x2) {
  52.             i = x1;
  53.             x1 = x2;
  54.             x2 = i;
  55.             i = y1;
  56.             y1 = y2;
  57.             y2 = i; }
  58.         h = y2 - y1;
  59.  
  60.         for(i=0; i < w; ++i) {
  61.             vgotoxy(x1+i, y1+((i*h) / w));
  62.             vputc(PCHR); } }
  63.     /* If 'Y' is greater, increment through 'Y' coordinate */
  64.     else {
  65.         if(y1 > y2) {
  66.             i = x1;
  67.             x1 = x2;
  68.             x2 = i;
  69.             i = y1;
  70.             y1 = y2;
  71.             y2 = i; }
  72.         w = x2 - x1;
  73.         for(i=0; i < h; ++i) {
  74.             vgotoxy(x1+((i*w)/h), y1+i);
  75.             vputc(PCHR); } }
  76.  
  77.     vgotoxy(x2, y2);
  78.     vputc(PCHR);
  79. }
  80.  
  81. /*
  82.  * Draw a box with opposite corners (x1, y1) to (x2, y2)
  83.  */
  84. box(x1, y1, x2, y2)
  85.     int x1, y1, x2, y2;
  86. {
  87.     line(x1, y1, x2, y1);
  88.     line(x1, y1, x1, y2);
  89.     line(x2, y1, x2, y2);
  90.     line(x1, y2, x2, y2);
  91. }
  92.  
  93. /*
  94.  * Draw a circle about point (x, y) of radus (r)
  95.  */
  96. circle(x, y, r)
  97.     int x, y, r;
  98. {
  99.     int i, j, k, rs, lj;
  100.  
  101.     rs = (lj = r)*r;
  102.     for(i=0; i <= r; ++i) {
  103.         j = k = sqrt(rs - (i*i));
  104.         do {
  105.             vgotoxy(x+i, y+j); vputc(PCHR);
  106.             vgotoxy(x+i, y-j); vputc(PCHR);
  107.             vgotoxy(x-i, y+j); vputc(PCHR);
  108.             vgotoxy(x-i, y-j); vputc(PCHR); }
  109.         while(++j < lj);
  110.         lj = k; }
  111. }
  112.