home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / animutil / anim13 / testpic.c < prev   
Text File  |  1990-05-07  |  5KB  |  144 lines

  1. /* testpic.c
  2. Program to generate a test "picture" coded for Tektronix 4010 graphics,
  3. especially for testing animation program ANIMATE.
  4.  
  5. Tek4010 coordinates have 0 <= x <= 1023 and 0 <= y <= 779
  6. with (x,y)=(0,0) lying in the lower left corner of the screen.
  7. ASCII character GS = 29 (base 10) = 1d (base 16) turns on graphics mode.
  8. Each coordinate pair (x,y) is coded as 4 bytes;
  9. see xy_to_Tek4010() below for details.
  10.  
  11. With Tek4010 graphics, a curve is drawn by sending GS to signal the beginning
  12. of a curve followed by 4-bytes for each (x,y) coordinate pair
  13. that defines the curve.
  14.  
  15. ANIMATE assumes that a graph is done when ANIMATE encounters ESCape FormFeed
  16. (ESC FF) or is switched into alphanumeric mode by receiving
  17. either ASCII character CR = 0d (base 16) or US = 1f (base 16).
  18. The interpretation of US will be changed in the next edition of
  19. ANIMATE so that it will behave according to the Tektronix standard.
  20.  
  21. Jon Ahlquist, 3 April 1990.
  22. Dept of Meteorology B-161
  23. Florida State University
  24. Tallahassee, FL 32306-3034
  25. Telephone: (904) 644-1558
  26. Internet:  ahlquist@metsat.met.fsu.edu (ahlquist@128.186.5.2)
  27. */
  28.  
  29. /* Declare function prototypes. */
  30. #include <process.h> /* exit()  */
  31. #include <stdio.h>   /* fopen(), fputc(), fputs(), fclose(). */
  32. void fput4b(char *byte, FILE *fp);
  33. int xy_to_Tek4010(int ix, int iy, char *byte);
  34.  
  35. /* Define a few ASCII constants.       */
  36. #define  GS 0x1d /* Graphics Shift     */
  37. #define  CR 0x0d /* Carriage Return    */
  38. #define  LF 0x0a /* Line Feed          */
  39. #define  US 0x1f /* control Underscore */
  40. #define ESC 0x1b /* ESCape             */
  41. #define  FF 0x0c /* Form Feed          */
  42.  
  43. /* Meaning of the ASCII constants for Tek 4010 operation,
  44. especially with ANIMATE.
  45.  
  46. GS     turn on graphics mode (if not already invoked) and start
  47.        drawing a curve (as a set of connected line segments).
  48. CR     turn on alphanumeric mode.
  49.        For ANIMATE, this signals the end of a plot.  See exception below.
  50. CR LF  should be ignored by ANIMATE.
  51.        A commercial Tek4010 translator I encountered inserted CR LF
  52.        every so often even when alphanumeric mode was not being invoked.
  53.        Therefore, ANIMATE is written to ignore CR LF.
  54. US     turn on alphanumeric mode without changing the current position
  55.        of the spot of light on the screen.
  56.        This can be used to label graphs.
  57.        For the current version of ANIMATE, this signals the end of a plot.
  58. ESC FF clear the graphics screen.
  59.        For ANIMATE, this signals the end of a plot.
  60. */
  61.  
  62. void main(void)
  63. {
  64.  
  65. FILE *fp;
  66. char  byte[4];
  67.  
  68. if ((fp = fopen("testpic.tek", "wb")) == NULL)
  69.    {
  70.    printf("Could not open output file.\n");
  71.    exit(1);
  72.    }
  73.  
  74. /* Draw a right angle on the screen, but include some extraneous
  75. junk to test ANIMATE's ability to handle it. */
  76.  
  77. /* Start the file with junk consisting of alphanumeric information,
  78. including CR LF. ANIMATE should ignore everything before it encounters
  79. ASCII character GS, which turns on the graphics mode. */
  80. fputs("abc", fp);
  81. fputc(CR,   fp);
  82. fputc(LF,   fp);
  83.  
  84. /* Turn on graphics mode and signal the start of a "curve." */
  85. fputc(GS, fp);
  86.  
  87. /* Draw a horizontal line segment. */
  88. xy_to_Tek4010(  0, 100, byte);
  89. fput4b(byte, fp);
  90. xy_to_Tek4010(500, 100, byte);
  91. fput4b(byte, fp);
  92.  
  93. /* Insert an extraneous carriage return and line feed. */
  94. fputc(CR, fp);
  95. fputc(LF, fp);
  96.  
  97. /* Draw a vertical line segment by moving upward from the previous point. */
  98. xy_to_Tek4010(500, 700, byte);
  99. fput4b(byte, fp);
  100.  
  101. fclose(fp);
  102. }
  103. /*************************************************************/
  104. void fput4b(char *byte, FILE *fp)
  105. /* Write 4 bytes to a file stream. */
  106. {
  107. int i;
  108. for (i=0; i<4; i++) fputc(*(byte+i), fp);
  109. }
  110.  
  111. /*************************************************************/
  112. int xy_to_Tek4010(int ix, int iy, char *byte)
  113. /* This function converts an (ix,iy) coordinate on a Tektronix 4010
  114. graphics screen into the 4 byte sequence that is used in the Tek4010
  115. graphics language to code that coordinate pair.
  116. If either ix or iy lies out of range (0 through 1023 for ix,
  117. 0 through 779 for iy), control returns to the calling
  118. program without altering the values in the character array "byte,"
  119. and the integer return value for xy_to_Tek4010 is set equal to 1.
  120. If both ix and iy lie in range, the integer return value for
  121. xy_to_Tek4010 is set equal to 0 and the four byte sequence representing
  122. ix and iy in Tek4010 graphics language is loaded into character array "byte."
  123. This sequence has the form and order: 001YYYYY 011yyyyy 001XXXXX 010xxxxx,
  124. where upper case letters denote the leftmost  5 bits of a coordinate,
  125. and   lower case letters denote the rightmost 5 bits of a coordinate.
  126.  
  127. Jon Ahlquist, 28 Feb 1990.
  128. */
  129. {
  130. /* Return if ix or iy lies out of range. */
  131. if ((ix<0) || (ix>1023)) return(1);
  132. if ((iy<0) || (iy> 779)) return(1);
  133.  
  134. /* Store Tek4010 coordinates ix and iy as an ordered 4 byte string.
  135. The first 3 bits of each byte are a prefix that tells what kind
  136. of a coordinate is represented by the final 5 bits.
  137. The same prefix is used for the high 5 bits of x and y. */
  138. *byte     = 32 + (iy >> 5); /* Bits 001 followed by high 5 bits of iy. */
  139. *(byte+1) = 96 + (iy % 32); /* Bits 011 followed by low  5 bits of iy. */
  140. *(byte+2) = 32 + (ix >> 5); /* Bits 001 followed by high 5 bits of ix. */
  141. *(byte+3) = 64 + (ix % 32); /* Bits 010 followed by low  5 bits of ix. */
  142. return(0);
  143. }
  144.