DRAW
At least three very different ways to show pictures or create polygons on a graphical screen, according to implementation.
Implemented by: ansifull, Applesoft, cbmv7, cbmv3.5, colorext, spectrum, ABasiC, VBDOS, FreeBASIC
With variations: Simons1, Atom (line from current position to X,Y), BBC (line from current position to X,Y), GWBASIC (macro language), MSX (macro language), QBasic (macro language), ugBASIC (coordinates and DRAW TO form)
Also written as:
- dR (cbmv3.5)
Usage
The official ANSI definition for DRAW was somewhat similar to the one which had been already implemented by Applesoft BASIC. As such, DRAW is used to show on screen a predefined shape.
Coordinates: From ... To... To... To...
In such implementations, DRAW is somewhat similar to the LINE statement found in some BASICs.
In Commodore BASIC V3.5, it optionally defines a starting X,Y point with FROM and may have an arbitrary number of TO coordinates thereafter. Before the coordinates a numerical argument may be used for defining a color source:
- 0 for the current screen background color
- 1 for the current screen foreground color (default, can be ommited, but leave the comma there)
- 2 for extra color 1 in multicolor mode
- 3 for extra color 2 in multicolor mode
The following example from Programmer's Reference Guide for the Commodore Plus/4 uses DRAW with the default foreground color:
5 GRAPHIC 1,1 10 DRAW, 30,85 TO 289,150 20 DRAW, 160,85 TO 310,50 TO 840,100 TO 160,100 TO 80,50 30 DRAW, TO 319,50
Microsoft's "graphical macro language"
Later Microsoft BASIC-80-derived implementations, such as GW-BASIC, MSX-BASIC and QuickBASIC, had a radically different implementation of DRAW with a striking resemblance to the "turtle graphics" made famous by the Logo language, which enjoyed a certain popularity in the early 1980s.
In such implementations, DRAW only interprets a string made of commands from a "macro language", like this short example from Linguagem BASIC MSX:
DRAW "U20D10L30R40"
command | meaning | obs |
---|---|---|
Un | Up, n pixels | |
En | Up-right, 45°, n pixels | |
Rn | Right, n pixels | |
Fn | Down-right, 45°, n pixels | |
Dn | Down, n pixels | |
Gn | Down-left, 45°, n pixels | |
Ln | Left, n pixels | |
Hn | Up-left, 45°, n pixels | |
Cn | Change the "pen" color to n | |
Mx,y | From current position to coordinates x,y | |
M±x,±x | From current position to plus/minus x, plus/minus y | |
TAn | Rotates n integer degrees, from -360 to 360 (yes, no radians here) | |
An | Rotates the whole coordinates system in 90° counter-clockwise, from 0 (default) to 4 | |
Pi,o | Paint area with color i up to an area with color o | Not in msx |
=V; | Substitutes numerical variable V within the commands string (don't forget the semicolon) | To confirm support on msqb |
Xv$; | Substitutes string variable v$ within the commands string (don't forget the semicolon) |
Every command can also have a prefix which change its behavior:
B | Only move according to the command, without actually drawing |
N | Return to starting point after execution (in other words: perform without changing the current start location) |
Still about variable substitution, it is possible to join the command string to a numerical string defined elsewhere by using VARPTR$ in msqb and gwbasic. A command that waits a numeric argument is "left waiting" with the use of =
, like the following example:
DRAW "A0C4BM10,10R=" + VARPTR$(s$)
Comments
Related keywords
Similar keywords
In other languages...
References
- MERTEN, Cyndie; MEYER, Sarah. Programmer's Reference Guide for the Commodore Plus/4. Scott, Foresman and Company. USA, 1986. Available at https://archive.org/details/Plus-4_Programmers_Reference_Guide , last check 2023-03-12.
- Linguagem BASIC MSX. Gradiente. Editora ALEPH. Brasil, 1986.
- https://robhagemans.github.io/pcbasic/doc/2.0/#DRAW , last checked 2023-03-12