Q(uick)BASIC Function: POINT

Quick View

POINT

A graphics function that reads the color number of a pixel from the screen or returns the pixel's coordinates

Worth knowing

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

Syntax
  • POINT {(n%) | (x%,y%)}
Description/Parameter(s)
(n%) Indicates the type of coordinate to return:
n%Returns
0The current viewport x coordinate
1The current viewport y coordinate
2The current window x coordinate
3The current window y coordinate
(x%,y%) The coordinates of the pixel that POINT checks for color. If the coordinates are outside the current viewport, POINT returns -1.
Example

This example requires a color graphics adapter.

SCREEN 1 LINE (0, 0)-(100, 100), 2 LOCATE 14, 1 FOR y% = 1 TO 10 FOR x% = 1 TO 10 PRINT POINT(x%, y%); NEXT x% PRINT NEXT y%
Syntax
  • POINT (x,y)
  • POINT (number)
Description/Parameter(s)

The coordinates x and y refer to the pixel being evaluated by the POINT function. When called with two coordinates, POINT returns the color number of the indicated pixel. If the specified pixel is out of range, POINT returns the value -1.

POINT with one argument (as explained in the list below) allows the user to retrieve the current graphics-cursor coordinates.

Argument Value Returned
0 The current physical x coordinate.
1 The current physical y coordinate.
2 The current view x coordinate. This returns the same value as the POINT(0) function if the WINDOW statement has not been used.
3 The current view y coordinate. This returns the same value as the POINT(1) function if the WINDOW statement has not been used.
Example

This example redraws an ellipse drawn with the CIRCLE statement, using POINT to find the border of the ellipse by testing for a change in color:

DEFINT X, Y INPUT "Enter angle of tilt in degrees (0 to 90): ",Ang SCREEN 1 'Medium resolution screen. Ang = (3.1415926# / 180) * Ang 'Convert degrees to radians. Cs = COS(Ang) : Sn = SIN(Ang) CIRCLE (45, 70), 50, 2, , , 2 'Draw ellipse. PAINT (45, 70), 2 'Paint interior of ellipse. FOR Y = 20 TO 120 FOR X = 20 TO 70 'Check each point in rectangle enclosing ellipse. IF POINT(X, Y) <> 0 THEN 'If the point is in the ellipse, plot a corresponding 'point in the "tilted" ellipse. Xnew = (X * Cs - Y * Sn) + 200 : Ynew = (X * Sn + Y * Cs) PSET(Xnew, Ynew), 2 END IF NEXT NEXT END
Syntax
  • POINT {(number%) | (x%,y%)}
Description/Parameter(s)
(number%) A numeric expression with an integer value between 0 and 3; specifies the current graphics cursor coordinate that is to be returned:
0 = viewport x coordinate2 = window x coordinate
1 = viewport y coordinate3 = window y coordinate
(x%,y%) The viewport coordinates of pixel being evaluated.

Usage Notes

  • When (x%,y%) are used to specify a pixel, the POINT function returns the color number of the indicated pixel. The expressions x% and y% are viewport coordinates (if no VIEW statement has been executed, or the most recently executed VIEW statement has no arguments, the viewport coordinates are the same as the absolute screen coordinates).
  • The meaning of the color number returned as well as the valid range of values for x% and y% depend on the current screen mode established by the most recently executed SCREEN statement. If the specified pixel is out of range, POINT returns the value -1.
Example

This example uses the POINT function to find the border of the ellipse by testing for a change in color while redrawing an ellipse drawn with the CIRCLE statement.

DEFINT X-Y INPUT "Enter angle of tilt in degrees (0 to 90): ", Ang SCREEN 1 'Medium resolution screen. Ang = (3.1415926# / 180) * Ang 'Convert degrees to radians. Cs = COS(Ang): Sn = SIN(Ang) CIRCLE (45, 70), 50, 2, , , 2 'Draw ellipse. PAINT (45, 70), 2 'Paint interior of ellipse. FOR Y = 20 TO 120 FOR X = 20 TO 70 'Check each point in rectangle enclosing ellipse. IF POINT(X, Y) <> 0 THEN 'If the point is in the ellipse, plot a corresponding 'point in the "tilted" ellipse. Xnew = (X * Cs - Y * Sn) + 200: Ynew = (X * Sn + Y * Cs) PSET (Xnew, Ynew), 2 END IF NEXT NEXT END