top banner
Examples
1: Introduction
2: Simple example
3: Fancy example
4: Running Gri
5: Programming Gri
6: General Issues
7: X-Y Plots
8: Contour Plots
9: Image Plots
10: Examples
11: Handling Data
12: Gri Commands
13: Gri Extras
14: Evolution of Gri
15: Installing Gri
16: Gri Bugs
17: System Tools
18: Acknowledgments
19: License
20: Newsgroup

21: Concept Index
navigate navigate navigate navigate navigate navigate

10.7: Drawing gray polygons

The following example shows how to draw polygons of a graylevel that is read in. It also draws a bullet (within the polygon). See the help lines at the start.
`Draw Polygon And Bullet'
Draw a polygon of a given graylevel, with a bullet
(black dot) at an indicated location.  The polygon
coordinates are read in by this command, as are
the graylevel and the location of the bullet.

Variables used:
  .black.
  .white.

Input data read: 

line   1:
  A code (which is ignored) and a graylevel
  to draw the polygon with. The value for this
  graylevel ranges from .black. (which codes
  to black ink on the paper) to .white.
  (which codes to blank paper).

line   2:
  An (x,y) location for the bullet.

line   3:
  Skipped.

line 4-n:
  Locations of vertices of polygon, ended with a blank line.
{
  read .code. .graylevel. # Read line 1
  read .x. .y.            # Read line 2
  skip                    # Skip line 3
  read columns x y        # Read a polygon
  # Adjust .graylevel. to range between 0
  # (for black ink) and 1 (for white paper),
  # then set graylevel and draw polygon. 
  .graylevel. = {rpn .graylevel. \
      .black. - .white. .black. - /}
  set graylevel .graylevel.
  draw curve filled
  # Draw black bullet
  set graylevel 0
  draw symbol bullet at .x. .y.
  # Clean up local storage.
  delete .code. 
  delete .graylevel.
  delete .x.
  delete .y.
}
bottom banner