home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / pcgraphc.zip / G_INTRO.TXT < prev    next >
Text File  |  1989-01-14  |  31KB  |  818 lines

  1.  
  2.  
  3.             Introduction
  4.  
  5. This manual introduces a subset of the powerful graphics 
  6. functions which are part of the BASIC programming language as 
  7. implimented on Hewlett-Packard Series 200/300 Technical 
  8. Computers.  This manual introduces these functions and explains 
  9. their usage.  Also provided are a set of example program which 
  10. illustrate some of the features of these functions.
  11.  
  12. The functions do not in themselves constitute a complete program.  
  13. Rather, they are used to suppliment a program where graphical 
  14. data is to be presented.  These functions are distinct from the 
  15. functions provided in the Microsoft v. 5.1 C compiler in that 
  16. they scale the screen into units defined by the user.  The 
  17. programmer need not know what the screen size is in pixels to use 
  18. these routines, and, in fact, these routine are designed to make 
  19. a program independent of the hardware and screen mode used.
  20.  
  21. It should be pointed out that, like all graphical 
  22. representations, these routines perform best with high resolution 
  23. screens.  They will function with any screen resolution 
  24. available, but line resolution improves as screen resolution 
  25. increases.  Thus, for best results, one would normally use the 
  26. highest resolution screen available.
  27.  
  28.  
  29.  
  30.     Why the Hewlett-Packard Workstation BASIC Graphics?
  31.  
  32. There are three reasons why I chose to impliment this particular 
  33. set of graphics primitives.  First, I was porting some 
  34. applications written in HP workstation BASIC to an IBM PC 
  35. compatible computer.  Since these programs had extensive 
  36. graphical displays and would not be nearly as useful without 
  37. them, it was manditory to develop these graphic primitives.  
  38.  
  39. Second, it is a well thought out and utilitarian set of 
  40. 2-dimensional graphics primitives.  It is well suited to 
  41. presentation of technical information and quite flexible.  The 
  42. functions are intuitive and easily incorporated into the original 
  43. programs, and much of that has carried over into this library.
  44.  
  45. And lastly, the graphics primitives provided with Microsoft's 
  46. verion 5.1 C compiler are difficult to use.  They require the 
  47. user to keep track of his scaling and units.  Although they can 
  48. do quite a bit, that nagging problem of converting from user 
  49. units to pixels is left to the user.  Add to that the inflexible 
  50. labeling demands of the PC text interface (it is not possible to 
  51. place labels arbitrarily because the text interface is imbedded 
  52. in the graphics modes:  you must label in text rows and columns) 
  53. and the lack of any ability to rotate the text or change font 
  54. size without loading completely new fonts made it obvious that 
  55. ignoring most of Microsoft's and the PC's graphics functions 
  56. would be the best way to proceed.
  57.  
  58.  
  59.  
  60.  
  61.             Why Use Graphics?
  62.  
  63. The use of graphics to display information is unsurpassed in 
  64. intuitive clarity.  Trends and patterns are much more readily 
  65. recognized on a graph than in tabular form.
  66.  
  67. For example, examine the following lexical data and try to 
  68. visualize the shape of the data:
  69.  
  70. X          Y
  71.  
  72. 0     0.09
  73. 20     0.42
  74. 40     0.71
  75. 60     0.91
  76. 80     0.99
  77. 100     0.97
  78. 120     0.82
  79. 140     0.57
  80. 160     0.26
  81. 180    -0.09
  82. 200    -0.42
  83. 220    -0.71
  84. 240    -0.91
  85. 260    -1.00
  86. 280    -0.97
  87. 300    -0.82
  88.  
  89. If this were displayed on a graph, it would be immediately 
  90. obvious that this is a sinusoid.
  91.  
  92.  
  93.  
  94.  
  95.             Line Drawing
  96.  
  97. To draw lines, one can simple draw () or plot () the points.  The 
  98. following short program illustrates this.
  99.  
  100. #include <stdio.h>
  101. #include <math.h>
  102. #include "graph.h"
  103.  
  104. double x;
  105.  
  106. main ()
  107.     {
  108.     g_init (EGA_640x350);
  109.     for (x = 0; x < 70; ++x) 
  110.         plot (x, 45 + sin (x/100) + x/10, 1);
  111.     }
  112.  
  113. This program illustrates the most basic program one can write.  
  114. The call to g_init () initializes the graphics routines and sets 
  115. the screen to graphics mode.  This is always the first function 
  116. called before attempting to plot anything.
  117.  
  118. The plot () function does exactly what its name implies.  It
  119. draw a line from the last pen position to the current pen
  120. position using the current pen color.  In this case, a pen
  121. control parameter is included.  The value 1 causes the plotting
  122. program to initially move the pen and then drop the pen.  Once
  123. the pen is down, it remains down and the plot is drawn.  The
  124. constant 45 is used to center the y-values.
  125.  
  126. When the plotting program is initialized, the screen default 
  127. scaling is in Graphics Display Units (GDU's). GDU's have an 
  128. origin in the lower left corner of the CRT and have values from 0 
  129. to 100 for the shorter side of the CRT (usually the y-
  130. direction).  The value for the longer side of the CRT depends on 
  131. the hardware and drawing mode.  This can range from 100 to 150 or 
  132. higher.  In this example, it was assumed that the screen was 100 
  133. GDU's tall and 140 GDU's wide.  Thus, this program will draw a 
  134. sinusoid 2 GDU's tall over 1/2 of the screen.
  135.  
  136.  
  137.  
  138.  
  139.             Scaling A Plot
  140.  
  141. If you were to execute this program as it is written, the results 
  142. would be disappointing.  There would be almost nothing to see.  
  143. However, if the Y scale is changed, the variations would become 
  144. much more visible and would better represent the data.
  145.  
  146. For this problem, we have scaling functions.  These functions 
  147. define values which the computer considers to be the edges of the 
  148. plotting area.  By definition, the left edges is the minimum x-
  149. value and the right edges is the maximum x-value.  Similarly, the 
  150. bottom edges is the minimum y-value and the top edge represents 
  151. the maximum y-value.  Any point plotted within these ranges will 
  152. be visible.  There are three functions which can be used to 
  153. define the edges of the plotting area: show (), scale (), and 
  154. mscale ().
  155.  
  156. The first function, show (), is an isotropic scaling function.  
  157. This type of scaling is most useful when displaying geometric 
  158. data.  show () forces the physical representation of the x-units 
  159. and y-units to be equal.  If the plotting area is square and one 
  160. uses 
  161.  
  162. show (0, 100, 10, 30)
  163.  
  164. to scale that area, the minimum x-value would be zero, the 
  165. maximum x-value would be 100, the minimum y-value would be -30, 
  166. and the maximum y-value would be 70.  The reason for this is that 
  167. the x- and y- units are identical.  The show () function centers  
  168. the specified area in the plotting area and takes whatever extra 
  169. room it requires to make the units equal.  Depending on the shape 
  170. of the plotting area and the scaling values, there will always be 
  171. extra room in either the x- or y-direction, but never both.
  172.  
  173. Once the show () function has been executed, the plotting area is 
  174. defined in User-Defined Units (UDU's).  If we re-write the 
  175. example program,
  176.  
  177. #include <stdio.h>
  178. #include <math.h>
  179. #include "graph.h"
  180.  
  181. double x;
  182.  
  183. main ()
  184.     {
  185.     g_init (EGA_640x350);
  186.     show (0, 70, -1, 8);
  187.     for (x = 0; x < 70; ++x) 
  188.         plot (x, sin (x/100) + x/10, 1 );
  189.     }
  190.  
  191. the resulting display would fill the width of the screen, but the 
  192. vertical scaling would remain unacceptable.
  193.  
  194. To improve the vertical resolution, one must resort to 
  195. anisotropic scaling using the scale () function.  Where the show () 
  196. function forced the scaling to be equal in both directions, 
  197. scale () will not.  Thus, 
  198.  
  199. #include <stdio.h>
  200. #include <math.h>
  201. #include "graph.h"
  202.  
  203. double x;
  204.  
  205. main ()
  206.     {
  207.     g_init (EGA_640x350);
  208.     scale (0, 70, -1, 8);
  209.     for (x = 0; x < 70; ++x) 
  210.         plot (x, sin (x/100) + x/10, 1 );
  211.     }
  212.  
  213. will display the data over the entire screen.  This is rather 
  214. nice, but there is no room for labeling the drawing.  We can see 
  215. the relative variations the plot, but we have no indication as to 
  216. what units are being used and what the magnitude is.  To 
  217. adequately annotate the plot, we would like to put labels outside 
  218. the plotting area so as to leave a clear view of the data.
  219.  
  220.  
  221.  
  222.  
  223.             Defining Viewports
  224.  
  225. A viewport is a subarea of the plotting area.  The borders of 
  226. the viewport are called the soft clip limits, and the subarea is 
  227. called the soft clip area.  The word clip implies that any line 
  228. which is draw to a point outside this border will be cut off at 
  229. the border (clipped).  They are called soft limits because they 
  230. can be overridden. To better understand this concept, imagine a 
  231. piece of paper with a rectangle drawn on it.  We can draw within 
  232. the rectangle at any time.  We can only draw outside the 
  233. rectangle when permission is granted.  Permission can be granted 
  234. by the clip_off () function, and permission can be denied with 
  235. the clip_on () function.  The edges of the paper represent the 
  236. hard clip limits.  These can not be overridden.  We can also 
  237. change the size of the soft clip limits using the clip () 
  238. function.  The clip function units are in UDU's.
  239.  
  240. For a given hardclip limit on the CRT, the GDU's are fixed and 
  241. always predictable.  It is for this reason that they are used by 
  242. the locate () function.  One GDU is defined as "One percent of 
  243. the length of the shorter side of the plotting area."  GDU's are 
  244. always isotropic: one GDU in the x-direction is the same size as
  245. one GDU in the y-direction.  However, because of the rectangular
  246. pixels on most PC graphics screens, the number of pixels/GDU
  247. will not be the same in the x-directions as it is in the
  248. y-direction.
  249.  
  250. At this point, we will define a viewport for our example program.  
  251. At the same time, we will introduce the frame () function.  The 
  252. frame function is used to draw a border around the soft clip 
  253. boundary.  When g_init () is first called, the hard clip and soft 
  254. clip borders are identical.  Hence, calling frame () before a 
  255. viewport is defined will result in a frame about the hard clip 
  256. border.
  257.  
  258. #include <stdio.h>
  259. #include <math.h>
  260. #include "graph.h"
  261.  
  262. double x;
  263.  
  264. main ()
  265.     {
  266.     g_init (EGA_640x350);
  267.     locate (10, 120, 10, 90);
  268.     frame ();
  269.     scale (0, 70, -1, 8);
  270.     for (x = 0; x < 70; ++x) plot (x, sin (x/100) + x/10, 1 );
  271.     }
  272.  
  273. For this example, we are using a 220 mm x 160 mm screen, so there 
  274. are 138 GDU's in the x-direction, and 100 GDU's in the 
  275. y-direction.  Working backwards, we find that the soft clip limit 
  276. is about 16 mm in from the screen edges on the top, and left 
  277. edge.  It is about 29 mm in from the right edge of the screen.  
  278. If we had wanted a symmetric display, we could have set the right 
  279. edge of the viewport at 128 GDU's.
  280.  
  281.  
  282.  
  283.  
  284.             Labeling the Plot
  285.  
  286. With the definition of a viewport, we now have a border in which 
  287. to label the graph.  Typically, the title is centered at the top 
  288. of the page, the y-axis label is along the left edge, and the 
  289. x-axis label is centered along the bottom.
  290.  
  291. The labelf () function allows text labels to be place at random 
  292. on the screen.  This function is distinct from printf () or any 
  293. other built-in text generation program.  All of the MS-DOS text 
  294. programs use raster scan fonts which must be placed in rows and 
  295. columns as ordinary ascii text output.  Furthermore, the text is 
  296. all aligned one-way.  It is not possible to rotate the text 
  297. without using a rotated font.
  298.  
  299. Labels are positioned by moving to the desired starting location 
  300. with the move () function or plot () function.  The lower left 
  301. corner of the label will be at the point to which you moved.  
  302. Thus, to label the graph, 
  303.  
  304.  
  305. #include <stdio.h>
  306. #include <math.h>
  307. #include "graph.h"
  308.  
  309. double x;
  310.  
  311. main ()
  312.     {
  313.     g_init (EGA_640x350);
  314.     locate (10, 120, 10, 90);
  315.     frame ();
  316.     move (40, 95);
  317.     labelf ("Demonstration Plot");
  318.     move (5, 65);
  319.     labelf ("D\ne\nv\ni\na\nt\ni\no\nn\n"); /* Deviation */
  320.     move (45, 5);
  321.     labelf ("Time (seconds)");
  322.     scale (0, 70, -1, 8);
  323.     for (x = 0; x < 70; ++x) plot (x, sin (x/100) + x/10, 1 );
  324.     }
  325.  
  326. This program now labels the plot with a title (Demonstration 
  327. Plot), an x-axis label (Time (seconds) ), and the y-axis label 
  328. (Deviation).  The y-axis label is broken with '\n' characters so 
  329. that the label will be placed vertically.  This type of label is 
  330. the only type of label possible without rotated fonts on a PC, 
  331. but the labelf () function is more versitile than this as will be 
  332. shown later.
  333.  
  334.  
  335.  
  336.  
  337.            Creative Labeling
  338.  
  339. In the previous example, we demonstrated one possible method of 
  340. labeling a plot with a vertical label.  This  resulted in 
  341. characters which were "stacked" over each other.  We also placed 
  342. the title only approximately in the center of the viewport, and 
  343. the title was the same size as all of the other characters.  
  344. These simplification were used because we were discussing 
  345. elementary plotting concepts and additional detail would have 
  346. detracted from these basic ideas.
  347.  
  348. To provide improved labeling, these are three functions which 
  349. modify the performance of the labelf () function.  The first of 
  350. these is csize ( size, a_r, tilt ), and its 3 arguments size, 
  351. a_r, and tilt.  The first argument, size, regulates the size of 
  352. the characters.  The initialization default is 5 GDU's.  The 
  353. size units are always in GDU's.  This is the height of the 
  354. character cell.  The character cell has borders on all sides so 
  355. that they may be drawn side-by-side and top-to-bottom without 
  356. overlapping.  Because all cells are the same size, the amount of 
  357. blank space between characters varies with the characters.  The 
  358. size of a character must always be specified.
  359.  
  360. The second parameter is the aspect ratio.  This is the measure of 
  361. the width to the height of a character cell.  The characters are 
  362. defined on a 9 x 15 grid: hence, the 0.6 default aspect ratio.  
  363. At 0.6, the characters are well defined and quite pleasing to the 
  364. eye.  The aspect ratio may, of course, be increased or decreased 
  365. to add emphasis to the labels.
  366.  
  367. The last parameter is the tilt.  This is an angular measure in 
  368. the current angular units (radians or degrees) of how far from 
  369. vertical the vertical axis of the character cells is tilted.  
  370. Positive angles tilt the characters clockwise, and negative 
  371. angles tilt the characters counter-clockwise.  The effect of 
  372. tilting the characters is to italicize them for additional 
  373. emphasis.
  374.  
  375. To use csize (), simply call the function with the desired 
  376. parameters.  These parameters will remain in effect until csize ()
  377. is called again with different parameters.
  378.  
  379. Note: the accuracy with which a character is represented and is 
  380. visually appealing depends on the screen resolution.  This means 
  381. that there are pratical limits to how small a character may be 
  382. made for a given screen resolution.  It is therefore recommended 
  383. that you use the highest practical screen resolution consistent 
  384. with your other graphics requirements.
  385.  
  386. The second function which is useful in labeling is lorg () which 
  387. selects from 9 label origins.  The illustration below shows the 
  388. function of lorg ().
  389.  
  390. 3                        6                                9
  391.    +                     +                              +  
  392.     Test Text        Test Text                Test Text    
  393.                                                            
  394.                                                            
  395.                          5                                 
  396. 2  +Test Text        Test+Text                Test Text + 8
  397.                                                            
  398.                                                            
  399.                                                            
  400.     Test Text        Test Text                             
  401. 1  +                     +                    Test Text + 7
  402.                          4                                 
  403.  
  404. The label is "Test Text" and the "+" marks the label origin for 
  405. the various origin codes.  Thus, if we wanted to center the title 
  406. on our graph, we could use
  407.  
  408. move (65, 95);
  409. lorg (5);
  410. labelf ("Demonstration Plot");
  411.  
  412. and the label would automatically be centered both vertically and 
  413. horizontally about the point (65, 95).
  414.  
  415. The last of the label enhancement functions is ldir () which 
  416. controls the direction labels are drawn.  At initialization, the 
  417. label direction is at 0 degrees (text is drawn horizontally).  
  418. This angle can be set to any angle.  Thus, if we say 
  419.  
  420.  
  421. ldir (90);
  422.  
  423. the labels will all be drawn vertically upward.  If we say
  424.  
  425. ldir (-90);
  426.  
  427. the labels will still be drawn vertically, but now the labels 
  428. will be drawn vertically downward.  There is complete freedom in 
  429. choosing the angle at which you want a label to be drawn.
  430.  
  431. Now, if we add all of the above to the example program, we have
  432.  
  433. #include <stdio.h>
  434. #include <math.h>
  435. #include "graph.h"
  436.  
  437. double x;
  438.  
  439. main ()
  440.     {
  441.     double x_gdu_max, y_gdu_max;
  442.  
  443.     g_init (EGA_640x350);
  444.  
  445.     /* Determine the screen width and height in GDU's */
  446.     x_gdu_max = 100 * max (1, ratio () );
  447.     y_gdu_max = 100 * max (1, 1 / ratio () );
  448.  
  449.     locate (10, 120, 10, 90);
  450.     frame ();
  451.     csize (7,0,0);
  452.  
  453.     /* set the label origin for centered label, top justified */
  454.     lorg (6);
  455.     move (x_gdu_max / 2, y_gdu_max);    /* move to top, middle of crt */
  456.  
  457.     labelf ("Demonstration Plot");
  458.     move (50, 65);
  459.     lorg (4);
  460.     ldir (90);
  461.     csize (4,0,0);
  462.     labelf ("Deviation"); 
  463.     move (45, 5);
  464.     lorg (6);
  465.     ldir (0);
  466.     labelf ("Time (seconds)");
  467.     scale (0, 70, -1, 8);
  468.     for (x = 0; x < 70; ++x) plot (x, sin (x/100) + x/10, 1 );
  469.     }
  470.  
  471.  
  472. we have a plot with an enlarged title and both axes labels well 
  473. centered along their respective axes.  We could have emboldened 
  474. the title slightly be placing the labeling inside a loop which 
  475. draws the title successively slightly to the right or left of the 
  476. starting point.
  477.  
  478. for (i = 1; i < 5; ++i)
  479.     {
  480.     move (65 + i/10, 95);
  481.     labelf ("Demonstration Plot");
  482.     }
  483.  
  484. Note that this only emboldens the vertical part of the text, but 
  485. the effect is not lost.
  486.  
  487. We have also introduced a new function: ratio (). ratio () returns 
  488. the aspect ratio of the screen.  The use of the max () function 
  489. simply selects which direction is defined as 100 GDU's.  If the 
  490. aspect ratio is greater than one, the y-direction will be 100 
  491. GDU's, and the x-direction will be 100 * ratio ().  If the aspect 
  492. ratio is less than one, the x-direction will be 100 GDU's, and 
  493. the y-direction will be 100 / ratio ().  Thus, we can determine 
  494. the shape of the screen without apriori knowledge thereof.
  495.  
  496.  
  497. If we add
  498.  
  499.     clip_off ();
  500.     move (0, -1);
  501.     lorg (8);    /* vertically centered, right justified */
  502.     labelf ("-1");    /* y-min */
  503.     move (0, 8);
  504.     labelf ("8");    /* y-max */
  505.     move (0, -1);
  506.     lorg (6);    /* horizontally centered, top justified */
  507.     labelf ("0");    /* x-min */
  508.     move (70, -1);
  509.     labelf ("70");    /* x-max */
  510.  
  511. we can place labels at the ends of the coordinate axes.  The
  512. clip_off () function call is necessary if we are to have visible
  513. labels.  This is because the labels are simply a series of
  514. vectors (lines of particular length and direction), and any
  515. portion of a line which lies outside of the soft clip limit will
  516. be cut off when clipping is in effect.  The main title and axes
  517. labels were drawn before the locate () function was called, and
  518. these were within the soft and hard clip limits at
  519. initialization (the screen boundaries).
  520.  
  521.  
  522.  
  523.  
  524.             Clipping
  525.  
  526. Clipping is a hidden function for most graphics applications.  It 
  527. is completely "under cover" because it functions without explicitly 
  528. requesting it.  There are two clipping limits: the soft clip 
  529. border and the hard clip border.  The hard clip limit is 
  530. generally an absolute limit determined by the physical size of 
  531. the plotting surface (although the hard clip limits can be 
  532. changed with the limit () function ).  The soft clip border is 
  533. user defined.  Calling the locate () function automatically 
  534. turns on soft clipping at the borders defined by locate ().
  535.  
  536. The soft clip limits can be set independently of the viewport by 
  537. using the clip () function. Calling 
  538.  
  539. clip (20, x_max, 10, y_max);
  540.  
  541. sets only the soft clip border.  The hard clip border is 
  542. unchanged.  After executing this function, any portion of a line 
  543. outside of the x-limits (20 and x_max) or the y-limits (10 and 
  544. y_max) will be truncated at the offending edge.
  545.  
  546. Note that the clip () function uses only UDU's (user defined 
  547. units).  Thus, it is necessary to call the locate () 
  548. function first to establish a scale for the viewing area.  Also, 
  549. calling locate () after calling clip () will override the 
  550. border set with clip () and set the soft clip limit to the new 
  551. border defined by locate ().
  552.  
  553. We can disable soft clipping with 
  554.  
  555. clip_off ();
  556.  
  557. and turn it back on with
  558.  
  559. clip_on ();
  560.  
  561. and soft clipping will resume at the previous soft clip border.  
  562. If we wish to change the soft clip border, we simply use the 
  563. clip () function to specify an new boundary.  The hard clip 
  564. boundary is always on and cannot be disabled.
  565.  
  566.  
  567.  
  568.  
  569.              Drawing Modes
  570.  
  571. When drawing on the CRT or any erasable device, several drawing 
  572. modes are available.  You can select "pens" dependent on the 
  573. graphics mode selected.  In CGA_640x200, there are two colors: 
  574. background and foreground.  In plotter terminology, you select 
  575. pens to determine the color you want to draw.  Pen # 0 is always 
  576. the background color.  For a monochrome drawing, there is only 
  577. one other pen: pen # 1.  In EGA_640x350, the total number of pens 
  578. is 16, or 15 colors plus background.  Here, the maximum pen 
  579. number is 15.
  580.  
  581. You can also "undraw" lines.  By selecting the negative of the
  582. pen color and drawing over a line, the line is erased.  The IBM
  583. BIOS provides two pixel functions: write and XOR.  Because of
  584. this limitation, it is not possible to erase only the color
  585. which was drawn.  Using the XOR function would do this, but if a
  586. pixel were not illuminated, XOR would make it so.  This would
  587. defeat the intent of erasing a line.  Therefore, selecting a
  588. negative pen number for erasing a line simply turns off all
  589. pixels on the line, irrespective of color, by writing the
  590. background color to those pixels.
  591.  
  592. Hewlett-Packard impliments pen # 0 in a slightly different manner 
  593. on monochrome CRT's as opposed to color CRT's.  On monochrome 
  594. CRT's, pen # 0 XOR's pixels.  Thus, pen # 0 will write white on a 
  595. black pixel, and black on a white pixel.  
  596.  
  597. On a color CRT with a color mapped graphics interface, the
  598. default colors are
  599.  
  600. Pen     Color
  601.  
  602. 0    Black
  603. 1    White
  604. 2    Red
  605. 3    Yellow
  606. 4    Green
  607. 5    Cyan
  608. 6    Blue
  609. 7    Magenta
  610. 8    Black
  611. 9    Olive Green
  612. 10    Aqua
  613. 11    Royal BLue
  614. 12    Maroon
  615. 13    Brick Red
  616. 14    Orange
  617. 15    Brown
  618.  
  619. This is not the same color set used by the PC color map.  On
  620. Hewlett-Packard computers with color mapped displays, it is
  621. possible to change the assigned pen colors.  This is possible
  622. only on IBM PC's with EGA compatible video interfaces (which
  623. contain writable color palettes.  Also, the Hewlett-Packard
  624. graphics interface allows pixels to be selectively erased. 
  625. Thus, a negative pen value will erase only the color values for
  626. that pen.  If you change pens before erasing a line, it is
  627. possible to not erase the line but to merely change its color. 
  628. For this implimentation, any negative pen value will erase a line
  629. of any color.
  630.  
  631. Line Types
  632.  
  633. In order to distinguish between different sets of data drawn in
  634. a single graph, it helps to pattern the lines.  To do that, the
  635. function line_type () is used to select from 10 line patterns. 
  636. line_type () takes two parameters.  The first parameter selects
  637. the pattern, and the second selects the repetition length.  The
  638. patterns will be described here.  To see the patterns, run
  639. linedemo.exe .
  640.  
  641. line type     description
  642.  
  643. 1        solid
  644. 2        dot at endpoint of line
  645. 3        lightly dotted
  646. 4        headily dotted
  647. 5        broken (dashed)
  648. 6        broken (long dash) with dot
  649. 7        broken (long dash) with short dash
  650. 8        broken (long dash) with double dot
  651. 9        solid with short tick (1 GDU total length)
  652. 10        solid with long tick (2 GDU's total length)
  653.  
  654. Line types 9 and 10 are implimented slightly differently than in 
  655. Hewlett-Packard workstation BASIC.  Hewlett-Packard places the
  656. ticks at the endpoint of the line segment.  Here, the ticks are
  657. repeated along the length of the line at the repeat rate of the
  658. line.  The ticks are drawn either vertically or horizontally. 
  659. The orientation depends on the angle of the line.  Lines closer
  660. to vertical will have horizontal ticks, and line closer to
  661. horizontal will have vertical ticks.  When these lines are drawn
  662. on the screen, however, the apparent angle at which the change
  663. from hoizontal to vertical ticks occurs will not be at 45
  664. degrees as one would expect.  This is due to the rectangular
  665. pixels of the PC graphics screen.  An extensive discussion of
  666. this is presented under the discription of the function
  667. line_type ().
  668.  
  669. The second parameter to line_type () is the repetition length.  
  670. At initialization, this is 5 GDU's.  This can be changed at any 
  671. time to any length.  It is up to the user to ensure that the 
  672. pattern is not so compressed that the detail of the pattern is 
  673. lost, or so long that continuity is lost.  Unlike the HP BASIC 
  674. implimentation, the line repetition need not be integer multiples 
  675. of 5 GDU's.
  676.  
  677. For all line types, the computer keep a record of where it is in 
  678. the pattern.  Thus, the pattern continues from one line segment
  679. to another.  The line can change directions and the pattern will
  680. still be continuous.  To start over (as you may want to do if
  681. you are drawing disconnected lines of the same type, simply call
  682. the line_type () function again with the same parameters and the
  683. pattern will start over.
  684.  
  685. Relative and Incremental Plotting
  686.  
  687. Up to now, we have discussed only absolute plotting:  That is, we 
  688. draw and move to specific coordinates.  Relative plotting allows 
  689. drawing relative to some relocatable origin, and incremental 
  690. plotting allows one to draw relative to the last location.  For 
  691. example,
  692.  
  693. move (50,50);
  694. rdraw (10,10);
  695. rdraw (10,-10);
  696. rdraw (0,0);
  697. rmove (0,-10);
  698.  
  699. draws a triangle with verticies at (50,50), (60,60), and (60,40).  
  700. We moved to a point (50,50) and then draw relative to that point.  
  701. Any absolute motion function ( i.e., move, draw, or plot) can be 
  702. used to set this origin.  In this example, we have used the rdraw ()
  703. function.  We could also have used the rplot () function if we 
  704. had required pen control.  The last command simply moves the pen 
  705. position to (50,40).
  706.  
  707. The current relative origin is the last location resulting from 
  708. calling any of the following commands:
  709.  
  710. axes ()        draw ()        frame ()    g_init ()
  711. grid ()        idraw ()    imove ()    iplot ()
  712. labelf ()    move ()        draw ()        plot ()
  713.  
  714. Note that the relative origin is unchanged by any relative motion 
  715. functions.
  716.  
  717. The incremental motion functions (imove, idraw, and iplot) also
  718. change the relative origin.  These also move the relative origin
  719. to the specified point.  To plot the same triangle using
  720. incremental functions,
  721.  
  722. move (50,50);
  723. idraw (10,10);
  724. idraw (0,-20);
  725. idraw (-10,10);
  726. imove (0,-10);
  727.  
  728. Here, the reference position changes to the last location. 
  729. idraw (10,10) draws to (60,60), but the reference position now
  730. becomes (60,60).  Thus, to get to the point (60,40), we must
  731. move down by 20 units: hence idraw (0,-20).  We are now at
  732. (60,40).  To get back to (50,50), we move up to and to the left
  733. 10, or idraw (-10,10).  We used an imove () to move to (50,40). 
  734. It looks exactly like the rmove () command from the previous
  735. example because the last drawing command moved us back to our
  736. starting point.  If we were not at our starting point, the
  737. commands would not look the same.  Again, we could have used
  738. iplot () if we had required control of the pen state (up or
  739. down).
  740.  
  741.  
  742. Rotation and Translation of Drawings
  743.  
  744. In many types of drawings, a single feature or structure is 
  745. replicated several times at different locations in the drawing.  
  746. We have seen how relative and incremental motion commands can be 
  747. used to plot the same figure at any location.  We can impart 
  748. rotation to lines drawn with these functions by using the pivot ()
  749. and pdir () functions.  Each of these functions take a single 
  750. argument which is the angle of rotation in the current angular 
  751. units (degrees or radians).  The function of these two functions 
  752. is greatly different, however.
  753.  
  754. The pdir () function specifies a relative plotting angle.  If we 
  755. write
  756.  
  757. move (10,10);
  758. pdir (0);
  759. iplot (1,0);
  760. pdir (-90);
  761. iplot (1,0);
  762.  
  763. the first line is drawn horizontally, and the second line is 
  764. drawn vertically down.  This is because we have introduced a 
  765. relative rotation of -90 degrees.  
  766.  
  767. We now introduced another element of confusion: logical pen
  768. position and physical pen position.  If we assume initialization
  769. values for pivot () and pdir (), the first iplot () moves the
  770. logical and physical pen position to (11,10), and the second 
  771. iplot () move the logical and physical pen position to (11,9).
  772. So far, logical and physical pen position move in lock-step.
  773.  
  774. The following code fragment illustrates the use of the pivot () 
  775. function:
  776.  
  777. move (10,10);
  778. pivot (90);
  779. iplot (1,0);
  780.  
  781. We moved to (10,10) and now, instead of changing the relative 
  782. plotting direction, we will pivot everything about this point.  
  783. Thus, the iplot () function draw a line to (10,11), but it draws 
  784. a line vertically up as if we drew to (11,10).  Now, the logical 
  785. pen position is at (11,10), but the physical pen position is at 
  786. (10,11).  In effect, we have rotated the coordinate axes 90 
  787. degrees about the point (10,10).  We have assumed isotropic 
  788. scaling in this discussion.  If we have anisotropic scaling 
  789. (i.e., we used scale () instead of show () ), the apparent line 
  790. length would stretch or shrink according to the scales of the x- 
  791. and y-axes.
  792.  
  793. Because pivot works in a logical coordinate system, if we move to 
  794. a new location (such as (5,5) ), pivot () will have the effect of 
  795. pivoting about those points; it will not pivot about the physical 
  796. location of (5,5).
  797.  
  798. Although the iplot () function was used in this example, pivot 
  799. will affect the direction of all lines drawn except labels, 
  800. grids, and axes.
  801.  
  802. At initialization, the pivot point is (0,0) and the pivot angle 
  803. is zero.
  804.  
  805.  
  806. Miscellaneous Utilities
  807.  
  808. A graphics dumping utility is also available.  It is called 
  809. dgraph () and can be used to dump entire screens or partial 
  810. screen.  It presently is configured for the EPSON FX-80 and 100 
  811. type of printers.  Unlike the MS-DOS program GRAPHICS.COM or 
  812. GRAPHICS.EXE, this program dumps all graphics at the same 
  813. orientation to the page.  It is somewhat slower than the MS-DOS 
  814. version principly because of the way Microsoft C executes calls 
  815. to the BIOS.
  816.  
  817.  
  818.