- The DRAW graphics statement uses a STRING value to draw lines on the screen.
- Syntax: DRAW draw_string$
- The draw string can be a draw value in quotation marks or a STRING variable using DRAW function letters.
- DRAW starting coordinates can be set using PSET, PRESET or other graphic objects.
- Other graphic objects can be located at or relative to the last DRAW position.
- DRAW can adopt colors from other graphics objects such as PSET, LINE and CIRCLE statements.
- Draw strings use letters followed by the number of pixels to move, an angle, coordinate or a color value.
- Draw strings are flexible with spacing. Spacing is not required! DRAW will look for a number value when needed.
- DRAW statements are not Case sensitive. Use upper or lower case.
- "C n" designates the color n to be used in the draw statement string following use. PSET colors work too.
- "B" before a line move designates that the line move will be hidden. (Blind)
- "M x, y" can move to another coordinate area of the screen. When a + or - sign is used before a coordinate,
- it is a relative coordinate move similar to using the STEP graphics keyword.
- "N" before a line move designates that the drawn line will return to the line start position. Saves moves!
- "P f [, b]" is used to paint enclosed objects. f denotes the fill color and b the border color if needed.
- "S n" changes the move size of the lines. Default is 4(1 pixel) minimum. "S8" would double the pixel line moves.
- Certain letter designations create line moves on the SCREEN. Each move is followed by the number of pixels:
- "U n" draws a line UP n pixels.
- "D n" draws a line DOWN n pixels.
- "L n" draws a line LEFT n pixels.
- "R n" draws a line RIGHT n pixels.
- "E n" draws a diagonal / line going UP and RIGHT n pixels each.
- "F n" draws a diagonal \ line going DOWN and RIGHT n pixels each.
- "G n" draws a diagonal / LINE going DOWN and LEFT n pixels each.
- "H n" draws a diagonal \ LINE going UP and LEFT n pixels each.
- Angles are used to rotate the draw moves following their use. U could become a down move.
- "A n" can use values of 1 to 3 to rotate up to n 90 degree angles.
- TA n" can use any n angle from -360 to 0 to 360 to rotate a DRAW (Turn Angle). "TA0" resets to normal.
- When VARPTR$ is used to create TA angle values use an equal sign: "TA=" + angle$
Example 1: Placing an octagon shape DRAW across the the screen using PSET.
- SCREEN 12
- FOR i% = 1 TO 11
- NEXT i%
Example 2: Creating an analog clock's hour markers using Turn Angle.
- SCREEN 12
- FOR i = 0 TO 360 STEP 30 ' 360/12 hour circles = 30 degrees apart
Explanation: To place 12 circles in a circle each move is 30 degrees. PSET sets the center of the circular path every loop. TA moves counter-clockwise with positive degree angles. Once TA sets the angle a blind Up move is at that angle. The hour circles use the end point of the blind line as centers using the STEP relative coordinates of 0. After the circles are drawn, a draw "P" string paints the circle centers. DRAW paint strings use the last coordinate position also.
Example 3: Creating a moving second hand for the clock above (SCREEN 12).
- DO: sec$ = RIGHT$(TIME$, 2) ' get actual seconds from TIME$ function
- degree$ = STR$(VAL(sec$) * -6) ' 60 second moves. TA uses negative angles for clockwise moves
- PSET (175, 250), 9 ' stay at clock center
- DRAW "TA" + degree$ + "U90" ' up becomes TA directional line
- DO: LOOP UNTIL RIGHT$(TIME$, 2) <> sec$ ' wait for a new second value
- IF INKEY$ <> "" THEN EXIT DO ' any key exit
- PSET (175, 250), 0 ' set at clock center to erase line
- DRAW "TA" + degree$ + "U90" ' erases old second hand line using color 0 from PSET
Explanation: The degrees to move from the original UP line move is calculated by dividing 360/60 seconds in a full rotation. That value of 6 is made negative to use TA correctly and multiplied by the VALue of seconds from the TIME$ function. The degree angle is converted by STR$ to a string and added to the DRAW string using the STRING concatenation + operator. DO NOT USE SEMICOLONS to create DRAW strings! Once the second hand is placed on the screen, a loop waits for the second value to change. It then erases the hand and it repeats the process again.