Q(uick)BASIC Statement: PSET

Quick View

PSET

A graphics statement that draws a point on the screen

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • PRESET [STEP] (x!,y!) [,color%]
  • PSET [STEP] (x!,y!) [,color%]
Description/Parameter(s)
STEP Specifies that the x! and y! are expressed relative to the current graphics cursor location.
(x!,y!) The screen coordinates of the pixel to be set.
color% A color attribute that sets the pixel color. If color% is omitted, PRESET uses the current background and PSET uses the current foreground color.

Available color attributes depend on your graphics adapter and screen mode. Coordinate values depend on the graphics adapter, screen mode, and most recent VIEW and WINDOW statements.

Example

This example requires a color graphics adapter.

SCREEN 1 FOR i% = 0 TO 320 PSET (i%, 100) FOR delay% = 1 TO 100: NEXT delay% PRESET (i%, 100) NEXT i%
Syntax
  • PSET [STEP](xcoordinate,ycoordinate) [,color]
Description/Parameter(s)
Argument Description
STEP Indicates that the given xcoordinate and ycoordinate are relative, not absolute. The coordinates are treated as distances from the most recent cursor location, not distances from the (0,0) screen coordinate.
For example, if the most recent point referenced were (10,10) then
  • PSET STEP (10,5)
would reference the point at (20,15).
xcoordinate The x coordinate of the pixel that is to be set.
ycoordinate The y coordinate of the pixel that is to be set.
color The color attribute for the specified point.

If a coordinate is outside the current viewport, no action is taken nor is an error message given.

PSET allows the color to be left off the command line. If it is omitted, the default is the foreground color.

Example

This example draws a line from (0,0) to (100,100), then erases the line by writing over it with the background color.

SCREEN 2 ' Draw a line from (0,0) to (100,100). FOR I = 0 TO 100 PSET (I, I) NEXT I LOCATE 16,2: INPUT "Press any key to erase the line ", Gar$ ' Now erase the line. PSET (I-1, I-1), 0 FOR I = 0 TO 100 PSET STEP (-1, -1), 0 NEXT I LOCATE 16,2: PRINT " "
Syntax
  • PSET [STEP] (x%,y%) [,color&]
Description/Parameter(s)
STEP Specifies that the (x%,y%) values are expressed relative to the current location of the graphics cursor, rather than in absolute screen coordinate values.
(x%,y%) The screen coordinates of the pixel to be set.
color& The color of the pixel (default is the current foreground color).
The valid range of screen coordinate values and color values depends on the screen mode established by the most recently executed SCREEN statement.
  • STEP indicates that the given x and y coordinates are relative, not absolute. The coordinates are treated as distances from the most recent graphics cursor location, not distances from the (0,0) screen coordinate. For example, if the most recent graphics cursor location was (10,10), PSET STEP (10,5) would refer to the point at (20,15).

Usage Notes

  • PSET works exactly like PRESET, except that if the color is not specified for a PSET statement, the foreground color is selected.
  • If a coordinate is outside the current viewport, no action is taken, nor is an error message generated.
Example

This example uses the PSET and PRESET statements to draw a line 20 pixels long, then to move the line across the screen from left to right.

SCREEN 1: COLOR 1, 1: CLS FOR I = 0 TO 299 STEP 3 FOR J = I TO 20 + I PSET (J, 50), 2 'Draw the line in new location. NEXT FOR J = I TO 20 + I PRESET (J, 50) 'Erase the line. NEXT NEXT