DRAW Statement ---------------------------------------------------------------------------- Action Draws an object described by a string of drawing commands. Syntax DRAW stringexpression$ Remarks The argument stringexpression$ contains one or more drawing commands. The drawing commands combine many of the capabilities of the other graphics statements (such as LINE and COLOR) into a graphics macro language, as described below. There are three types of drawing commands. - Line-drawing and cursor-movement commands. - Rotation, color, and scale-factor commands. - The substring command. Cursor-Movement Commands The following prefix commands can precede any of the movement commands. ----------------------------------------------------------------------------- Prefix Description ---------------------------------------------------------------------------- B Move, but do not plot any points. N Plot, but return to original position when done. The following commands specify movement in terms of units. The default unit size is one pixel. Unit size can be modified by the S command, which sets the scale factor (see "Rotation, Color, and Scale-Factor Commands" later in this entry). If no unit argument is supplied, the graphics cursor is moved one unit. Each of the cursor-movement commands initiate movement from the current graphics position, which is usually the coordinate of the last graphics point plotted with a DRAW macro-language command or another graphics command (such as LINE or PSET). The current position defaults to the center of the screen when a program begins execution. The cursor-movement commands have the following effects. ----------------------------------------------------------------------------- Command Effects ---------------------------------------------------------------------------- U - n- Move up n units. D - n- Move down n units. L - n- Move left n units. R - n- Move right n units. E - n- Move diagonally up and right n units. F - n- Move diagonally down and right n units. G - n- Move diagonally down and left n units. H - n- Move diagonally up and left n Command Effects ---------------------------------------------------------------------------- H - n- Move diagonally up and left n units. . M -{ +| -}- x, y Move absolute or relative. If x is preceded by a plus ( +) or minus ( -), the movement is relative to the current point; that is, x and y are added to (or subtracted from) the coordinates of the current graphics position and movement is to that point. If no sign precedes x, the movement is absolute. Movement is from the current cursor position to the point with coordinates x, y. Command Effects ---------------------------------------------------------------------------- y. Rotation, Color, and Scale-Factor Commands The following commands let you change the appearance of a drawing by rotating it, changing colors, or scaling it. ----------------------------------------------------------------------------- Command Description ---------------------------------------------------------------------------- A n Set angle rotation. The value of n may range from 0 to 3, where 0 is 0, 1 is 90, 2 is 180, and 3 is 270. Figures rotated 90 or 270 are scaled so they appear the same size on a monitor screen with a 4.3 aspect ratio. TA n Turn an angle of n degrees. The Command Description ---------------------------------------------------------------------------- TA n Turn an angle of n degrees. The value of n must be between -360 and 360. If n is positive, rotation is counterclockwise; if n is negative, rotation is clockwise. The following example uses TA to draw spokes. SCREEN 1 FOR D = 0 TO 360 STEP 10 DRAW "TA=" + VARPTR$(D) + "NU50" NEXT D C n Set the drawing (foreground) color to n. See the COLOR, PALETTE, and SCREEN statements for discussion of valid colors, numbers, and attributes. Command Description ---------------------------------------------------------------------------- P p, b The value p is the paint color for the figure's interior, while b is the paint color for the figure's border. See the PAINT statement for more information about painting an area with a graphic pattern. S n Set scale factor n, which can range from 0 to 255, inclusive. Increase or decrease length of moves. The default for n is 4, which causes no scaling. The scale factor multiplied by movement-command arguments (divided by 4) gives the actual distance moved. Command Description ---------------------------------------------------------------------------- X stringexpression$ Execute substring. This command allows you to execute a second substring from a DRAW command string. You can have one string expression execute another, which executes a third, and so on. Numeric arguments to macro commands within stringexpression$ can be constants or variable names. BASIC requires the following syntax. "X" + VARPTR$(stringexpression) BASICA Some DRAW statements that are allowable in BASICA programs require modification when used with the BASIC compiler. Specifically, the compiler requires the VARPTR$ form for variables. One example is this BASICA statement (in which ANGLE is a variable). DRAW "TA = Angle" For the BASIC compiler, you would change that to. DRAW "TA =" + VARPTR$(Angle) The compiler does not support the BASICA X stringexpression$ command. However, you can execute a substring by appending the character form of the address to X. For example, the following two statements are equivalent. The first statement works when within the environment and when using the compiler, while the second works only within the QBX environment. DRAW "X" + VARPTR$(A$) DRAW "XA$" See Also PALETTE, SCREEN Statement, VARPTR$ Examples The first example draws the outline of a triangle in magenta and paints the interior cyan. SCREEN 1 DRAW "C2" ' Set color to magenta. DRAW "F60 L120 E60" ' Draw a triangle. DRAW "BD30" ' Move down into the triangle. DRAW "P1,2" ' Paint interior. The next example shows how to use the M macro command with absolute and relative movement, and with string- and numeric-variable arguments. SCREEN 2 PRINT "Press any key to continue..." ' Absolute movement. DRAW "M 50,80" DRAW "M 80,50" LOCATE 2, 30. PRINT "Absolute movement" DO . LOOP WHILE INKEY$ = "" ' Relative movement. DRAW "M+40,-20" DRAW "M-40,-20" DRAW "M-40,+20" DRAW "M+40,+20" LOCATE 3, 30. PRINT "Relative movement" DO . LOOP WHILE INKEY$ = "" ' Using a string variable. X$ = "400". Y$ = "190" DRAW "M" + X$ + "," + Y$ LOCATE 4, 30. PRINT "String variable" DO . LOOP WHILE INKEY$ = "" ' Using numeric variables (note the two "=" signs). A = 300. B = 120 DRAW "M=" + VARPTR$(A) + ",=" + VARPTR$(B) LOCATE 5, 30. PRINT "Numeric variables" This program draws a clock on the screen using the TIME$ unction. @AS@%' Declare procedure. DECLARE SUB Face (Min$) ' Select 640 x 200 pixel high-resolution graphics screen. SCREEN 2 DO CLS Min$ = MID$(TIME$, 4, 2)' Get string containing minutes value. Face Min$' Draw clock face. ' Wait until minute changes or a key is pressed. DO ' Print time at top of screen. LOCATE 2, 37 PRINT TIME$ Test$ = INKEY$' Test for a key press. LOOP WHILE Min$ = MID$(TIME$, 4, 2) AND Test$ = "" LOOP WHILE Test$ = ""' End program when a key is pressed. END SUB Face (Min$) STATIC' Draw the clock face. LOCATE 23, 30 PRINT "Press any key to end" CIRCLE (320, 100), 175 ' Convert strings to numbers. Hr = VAL(TIME$) Min = VAL(Min$) ' Convert numbers to angles. Little = 360 - (30 * Hr + Min - 2) Big = 360 - (6 * Min) ' Draw the hands. DRAW "TA=" + VARPTR$(Little) + "NU40" DRAW "TA=" + VARPTR$(Big) + "NU70" END SUB