SEGMENT

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Special Notice

For a discussion of segments, see Getting to grips with Segments by Rod Bird at the Programmer's Encyclopedia.

Description

In graphics windows and graphic-boxes, SEGMENT retrieves the ID number of the current segment and places it in a named variable. Using names to refer to segment IDs is useful for managing different parts of a drawing.
Some additional commands used with the display of graphics:
delsegment
cls
redraw
discard
flush

Syntax

This command is NOT case sensitive.
To assign the current segment ID to a variable:
  1. #handle "segment segID" - a graphics window
  2. #handle.ext "segment segID" - a graphicbox
The variable name can be used in other parts of your program to refer to this segment ID number.

Hints

Name or number. Segments are automatically numbered starting with #1 as they are created. You can refer to a segment by number, but, often it is useful to give a segment a name that represents what it shows.

Example

An example of the command using a graphics window.

nomainwin

    WindowWidth=400
    WindowHeight=300

    open "Segment Demo" for graphics_nsb_nf as #g
    #g "trapclose [quit]"

    'put the pen down
    #g "down"
    'draw a line
    #g "line 10 50 10 250"
    'change color and draw second line
    #g "color yellow; size 4"
    #g "line 10 50 300 50"
    'save work so far
    #g "segment blackyellow"
    #g "flush"
    'change color add another line
    #g "color red; size 2"
    #g "line 10 250 300 50"

    confirm "Do you want to save this line?"; yn$

  'If the red line will not be saved, discard the current segment;
    'then, redraw the screen to remove the red line and show only
    'the black and yellow line. Finally, flush the graphics.
    if yn$="no" then #g "discard; redraw ";blackyellow;"; flush"

  'If the red line will be saved, flush the graphics to include the red line
    if yn$="yes" then #g "flush blackyellowred"
    wait

[quit]
    close #g
    end

Useful Procedures

' Place a useful function or sub using this keyword here