Draw Command

Purpose

Draws a point or a line between two points on the screen.

Syntax

Draw [To] [x, y]

Draw [x1, y1] [To x2, y2][To x3, y3]...

Draw exp

Draw(i)

SetDraw

x,y,x1,y1,x2,y2,i:floating-point expression

exp: a mixture of sexp and aexp, whereby the first expression must be a sexp. The individual expressions are separated by a comma, semi-colon o apostrophe.

Description

Draw x, y is equivalent to the Plot command, that is, a point with the coordinates x, y is drawn on the screen. Draw To x, y draws a line between the point with the coordinates x, y and the last set point. It is irrelevant whether this point was set with Plot, Line or Draw.

Draw x1, y1 To x2,y2 is equivalent to the Line command. However, additional coordinates can also be added. It is therefore possible to draw polygons in this manner.

Draw exp enables definition of commands similar to certain LOGO graphic commands (turtle graphics) or HPGL Hewlett-Packard standard plotter language commands. It is possible, in this way, to move an imaginary pencil across the screen, drawing as needed. The parameters for individual commands are floating point numbers which can also be specified using strings. The following commands are available:

FD n moves the 'pencil' n pixels 'forward'.
BK n moves the 'pencil' n pixels 'backwards'.
SX x
SY y
scales the 'pencil movement' for FD
or BK by the factor given in x or y.
The scaling can be turned off with SX 0 or SY 0.
LT w turns the 'pencil' left by the angle w (in degrees).
RT w the same to the right
TT w moves the 'pencil' to an absolute angle (in degrees). The assignment for w is as follows:
w = 0: up or north
w = 90: right or east
w = 180: down or south
w = 270: left or west
MA x, y moves the 'pencil' to absolute coordinates x and y.
DA x, y moves the 'pencil' to absolute coordinates x and y, and then draws a line in current color from the last set position to point (x, y).
MR x, y like MA, except that it moves relative to last position.
DR x, y like MR, except that it moves relative to last position.
CO n defines color n as drawing color.
PU lifts the 'pencil' up.
PD lowers the 'pencil' down.

Draw(i) is a function which, depending on i, returns the following values:

i = 0 x coordinate (floating point number)
i = 1 y coordinate (floating point number)
i = 2 angle in degrees (floating point number)
i = 3 scaling on the x axis (floating point number)
i = 4 scaling on the y axis (floating point number)
i = 5 pen status (-1 for PD and 0 for PU)

SetDraw sets various values in the Draw exp command. For example, SetDraw x, y, w is equivalent to Draw "MA", x, y"TT",w command.

Example

Dim a%, i%

OpenW # 1

Draw 100, 100

// sets a point at 100,100

//

Draw To 10, 10

// draws a line from 100,00 to 10,10

//

Draw 10, 10 To 20, 20 To 30, 30

// draws a line line from 10,10 to 20,20 and from // 20,20 to 30,30

//

Draw "ma 160,200 tt0"

// starts at 160,200 with angle 0

//

Print AT(40, 1); "Press any key"

KeyGet a%

Cls

For i% = 3 To 10

corner(i%, 90) //raws a polygon with i corners

Next i%

Print AT(1, 1); "Press any key"

KeyGet a%

Cls

For i% = 0 To 359

SetDraw 320, 200, i%

Draw "fd 45 rt 90 fd 45 rt 90 fd 45 rt 90 fd 45"

Draw "bk 90 rt 90 bk 90 rt 90 bk 90 rt 90 bk 90"

Draw "fd 45 rt 90 fd 45 rt 90 fd 45 rt 90 fd 45"

Draw "bk 90 rt 90 bk 90 rt 90 bk 90 rt 90 bk 90"

Next

Print AT(1, 1); "Close the Window"

Do : Sleep : Until Me Is Nothing

 

Procedure corner(n%, r%)

Local i%

For i% = 1 To n%

Draw "fd", r%, "rt", 360 / n%

Next i%

Return

Draws a small and a large rectangle which both rotate around their own axis.

Remarks

ScaleMode determines the coordinate units.

See Also

Plot, Line, ScaleMode, QBDraw, Preset, Pset, SetDraw

{Created by Sjouke Hamstra; Last updated: 03/10/2014 by James Gaite}