Liberty BASIC Help Online

See also:  graphics commands
Liberty BASIC supports drawing operations.  There are two kinds of controls that accept drawing commands; one is a kind of window, and the other is a control called a graphicbox.  They both support the same drawing operations.  Here is an example of a graphics window:
  open "I'm a graphics window!" for graphics as #g
  print #g, "home ; down"
  print #g, "fill green"
  print #g, "circle 100"
And here's the same drawing operation in a graphicbox which has been inserted into a window.
  graphicbox #w.g, 5, 5, 250, 250
  open "I'm a window!" for window as #w
  print #w.g, "home ; down"
  print #w.g, "fill green"
  print #w.g, "circle 100"
The graphics operations are performed by a pen.  The pen can be up or down.  If the pen is up, the drawing operations will not appear.  The pen moves, but does not draw.  The pen defaults to the up position.
Possible drawing operations include:
Turtle Graphics
Turtle graphics are drawn by a pen that moves about the screen from one location to another, drawing if is in the DOWN position.  Turtle graphics are good for drawing graphics and iterative objects.
Drawn Objects
Objects such as boxes, lines and circles may be drawn, and they may be either filled with an opaque color, or they may be drawn as an outline only.
Drawn Text
Graphics commands include the ability to place text on the graphics control at the location desired.
Color and Size
The size (width) of the drawing pen may be set.  The color that covers the control may be set, as well as the outline color of drawn objects, and the color that fills drawn objects.
Drawing Segments and FLUSH
Drawing happens in segments.  Drawing operations are queued up into the current drawing segment.  A FLUSH command closes the current segment and opens a new one.  The segments which have been closed will be used to redraw the drawn graphics when the window needs to be repainted.  Any drawing that does not exist in a closed segment will not be redrawn when the window is repainted. 
Drawing commands can be made to persist, or "stick" when the FLUSH command is used:
  graphicbox #w.g, 5, 5, 250, 250
  open "I'm a window!" for window as #w
  print #w.g, "home ; down"
  print #w.g, "fill green"
  print #w.g, "circle 100"
  print #w.g, "flush"
Deleting Drawing Segments
If a graphics window or graphicbox has received many drawing commands, it is advisable to delete unwanted segments.  If drawing segments are not deleted, the computer's RAM will eventually fill with drawing commands.  There are two ways to delete these unwanted drawing commands.
The simplest way to delete drawing commands is to issue the CLS command before new graphics drawing commands are issued:
  print #w.g, "cls"
When this method is used, the screen goes blank for an instant before new drawn items are displayed, causing a flickering or blinking effect. 
Segment and Delsegment
It is possible to delete any segments that are no longer needed.  This method will not clear the graphics, so no flickering effect will be visible.  Each segment has a number, and each time a segment is closed with a FLUSH command, the next segment has a number that is 1 greater than the last.  The first segment ID is 1, the second flushed segment ID is 2, the third is 3 and so on.
The number of the currently active segment is retrieved with the segment command:
  print #w.g, "segment drawSegment"
This gets the segment number of the current segment and places it into the variable drawSegment.  Subtracting 1 from the current segment number will reference the last segment that has been FLUSHed.  It can then be deleted with the DELSEGMENT command, as in this example:
  print #w.g, "delsegment "; drawSegment - 1
The DISCARD command will remove any unflushed drawing commands.  An example is as follows:
  'demonstrate discard
  open "Sine wave" for graphics as #sine
  print #sine, "home ; down ; posxy x y"
  print #sine, "place 0 "; y
  width = x * 2
  for x = 0 to width
    print #sine, "goto "; x; " "; y + (y * sin(x/40))
  next x
  print #sine, "discard" 'no redraw info kept
The program above draws a sine wave, discarding drawn graphics.  If the graphics window is maximized after the drawing is complete, it is possible to see that the graphics are not redrawn.  This is similar to the effect achieved when FLUSH is not used, but in fact it throws away the graphics instructions so memory does not get filled up.
When a window is closed, all graphics drawing operations are deleted from memory.
See also:  graphics commands

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -