home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / EXAMPLES / CIRCTXT.C < prev    next >
C/C++ Source or Header  |  2000-02-11  |  3KB  |  152 lines

  1.  
  2. #include <stdio.h>
  3. #include "vogle.h"
  4.  
  5. #ifdef    TC
  6. #define    poly    _poly
  7. #endif 
  8.  
  9. #include <math.h>
  10.  
  11. #ifdef TC
  12. #undef    poly
  13. #define    poly    poly
  14. #endif
  15.  
  16. #define pi 3.1415926535
  17.  
  18. char *fonts[] = {
  19.     "astrology",
  20.     "cursive",
  21.     "futura.l",
  22.     "futura.m",
  23.     "gothic.eng",
  24.     "gothic.ger",
  25.     "gothic.ita",
  26.     "greek",
  27.     "japanese",
  28.     "markers",
  29.     "math.low",
  30.     "math.upp",
  31.     "meteorology",
  32.     "music",
  33.     "cyrillic",
  34.     "script",
  35.     "symbolic",
  36.     "times.g",
  37.     "times.ib",
  38.     "times.i",
  39.     "times.r",
  40.     "times.rb"
  41. };
  42.  
  43. /*
  44.  * display all the hershey fonts and demonstrate textang
  45.  */
  46. main()
  47. {
  48.     char    buf[50];
  49.     char    *str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
  50.     char    *str2 = "abcdefghijklmnopqrstuvwxyz" ;
  51.     char    *str3 = "1234567890+-=!@#$%^&*(){}[]" ;
  52.     char    *str4 = "<>,./?~`\\|_BONK,blark" ;
  53.     int    i;
  54.  
  55.     fprintf(stderr,"Enter device name: ");
  56.     gets(buf);
  57.  
  58.     vinit(buf);
  59.  
  60.     color(BLACK);
  61.     clear();
  62.  
  63.     ortho2(-14.0, 14.0, -14.0, 14.0);    /* define the world space */
  64.  
  65.     vsetflush(0);
  66.  
  67.     for(i = 0; i < 22; i++) {
  68.  
  69.         /*
  70.          * textang is used to specify the orientation of text. As
  71.          * we want the title to come out straight we make sure it is
  72.          * zero each time we go through this loop.
  73.          */
  74.         textang(0.0);
  75.  
  76.         /*
  77.          * do the title
  78.          */
  79.         color(YELLOW);
  80.         font("futura.m");
  81.         sprintf(buf, "This is hershey font %s", fonts[i]);
  82.         boxtext(-11.0, 12.0, 20.0, 1.0, buf);
  83.  
  84.         /*
  85.          * draw a box around the title
  86.          */
  87.         rect(-11.0, 12.0, 9.0, 13.0);
  88.  
  89.         color(GREEN);
  90.  
  91.         font(fonts[i]);        /* grab a font from the table */
  92.  
  93.         textsize(1.5, 1.5);        /* show the outer ring */
  94.         ShowCircularText(11.0, str1);
  95.  
  96.         textsize(1.3, 1.3);        /* show the second ring */
  97.         ShowCircularText(8.5, str2);
  98.  
  99.         textsize(1.1, 1.1);        /* show the third ring */
  100.         ShowCircularText(7.0, str3);
  101.  
  102.         textsize(0.9, 0.9);        /* show the inside ring */
  103.         ShowCircularText(5.0, str4);
  104.  
  105.         if (getkey() == 'q') {
  106.             vexit();
  107.             exit(0);
  108.         }
  109.  
  110.         color(BLACK);
  111.         clear();
  112.     }
  113.  
  114.     vexit();
  115. }
  116.  
  117. /*
  118.  * ShowCircularText
  119.  *
  120.  *    show a ring of text
  121.  */
  122. ShowCircularText(r, str)
  123.     double    r;
  124.     char    *str;
  125. {
  126.     double    i, inc, x, y;
  127.     double    a;
  128.  
  129.     inc = 360.0 / (double)strlen(str);
  130.  
  131.     for (i = 0; i < 360.0; i += inc) {
  132.         /*
  133.          * calculate the next drawing position
  134.          */
  135.         x = r * cos(i * pi / 180.0);
  136.         y = r * sin(i * pi / 180.0);
  137.         move2(x, y);
  138.         /*
  139.          * calculate angle for next character
  140.          */
  141.         a = (90 + i);
  142.         /*
  143.          * set the orientation of the next character
  144.          */
  145.         textang(a);
  146.         /*
  147.          * draw the character
  148.          */
  149.         drawchar(*str++);
  150.     }
  151. }
  152.