QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The LINE statement is used in graphic SCREEN (statement) modes to create lines or boxes.

Syntax

LINE [STEP] [(column1, row1)]-[STEP] ( column2, row2 ), color[, [{B BF}], style%]

Parameter(s)

Description

Example(s)

Following one line with another by omitting the second line’s first coordinate parameter bracket entirely:


SCREEN 12

LINE (100, 100)-(200, 200), 10    'creates a line
LINE -(400, 200), 12              'creates a second line from end of first

END 

Explanation: The full equivalent LINE statement would be: LINE(200, 200)-(400, 200), 12

Creating styled lines and boxes with the LINE statement. Different style values create different dashed line spacing.


SCREEN 12

LINE (100, 100)-(300, 300), 10, , 63    'creates a styled line
LINE (100, 100)-(300, 300), 12, B, 255  'creates styled box shape

END 

Explanation: The first diagonal dashed green line bisects the red dashed square from Top Left to Bottom Right Corners.

The style value sets each 16 pixel line section as the value’s bits are set on or off:


SCREEN 13
_FULLSCREEN 'required in QB64 only
_DELAY 5
FOR i% = 1 TO 2 ^ 15 'use exponential value instead of -32768
    COLOR 15:LOCATE 10, 5: PRINT i%;
    LINE (10, 60)-(300, 60), 0 'erase previous lines
    LINE (10, 60)-(300, 60), 12, , i%
    tmp$ = ""
    FOR b% = 15 TO 0 STEP -1 'create binary text value showing bits on as █, off as space
        IF i% AND 2 ^ b% THEN tmp$ = tmp$ + CHR$(219) ELSE tmp$ = tmp$ + SPACE$(1)
    NEXT
    COLOR 12:LOCATE 10, 20: PRINT tmp$;
    IF INKEY$ <> "" THEN EXIT FOR 'any key exit
    _DELAY .001 'set delay time as required
NEXT 

Explanation: The style value’s Most Significant Bit (MSB) is set to the left with LSB on right as 16 text blocks are set on or off.

Using &B to design a style pattern:


SCREEN 12

LINE (100, 100)-(300, 100), 10, , &B0000111100001111 '16-bits
LINE (100, 110)-(300, 110), 11, , &B0011001100110011
LINE (100, 120)-(300, 120), 12, , &B0101010101010101
LINE (100, 130)-(300, 130), 13, , &B1000100010001000

Explanation: The binary pattern created with 0s and 1s using the &B number prefix define the pattern to draw the colored lines.

See Also