• Aucun résultat trouvé

Purpose: Draws an object as specified by string.

Versions: Cassette Disk Advanced

***

Compiler (**) Graphics mode only.

Format: DRA W string

Remarks: The DRAW statement draws objects using a graphics definition language. The language commands are contained in the string expression string. The string defines an object, which is drawn when BASIC executes the DRAW statement. During execution, BASI C examines the value of string and interprets single-letter commands from the contents of the string. When a movement command is given, a line is drawn from the last point referenced.

n in the following movement commands indicates the distance to move. The number of points moved is n times the scaling factor (set by the S command).

The movement commands are detailed on the next page.

Un

Move diagonally up and right.

Move diagonally down and right.

Move diagonally down and left.

Move diagonally up and left.

Move absolute or relative. If x has a plus sign ( +) or a minus sign (-) in front of it, it is relative. Otherwise, it is absolute.

The following two prefix commands can precede any of these movement

commands:

B Move, but don't plot any points.

N Move, but return to the original position when finished.

The following commands are also available:

A n Set angle n. The value of n can range from .0 to 3, where .0 is .0 degrees, 1 is 9.0,

DRAW Statement

TAn Turn angle n. The value of n can range from -36.0 to +36.0. If n is positive (+), the angle turns counterclockwise. If n is negative (-), the angle turns clockwise.

Values entered that are outside of the range -36.0 to +36.0 cause an Illegal function call error. This command is valid for BASIC version 2 . .0 and later releases.

C n Set color n. The value of n can range from .0 to 3 in medium resolution, and .0 to 1 in high resolution. In medium

resolution, n selects the color attribute from the current palette as defined by the COLOR statement. Zero (.0) is always the attribute for the background. The default foreground color attribute is always the maximum attribute for that screen mode: 3 in medium resolution; 1 in multiplied by the distances given with the U, D, L, R, E, F, G, H, and relative M commands gives the actual distance

moved. The default value is 4, so the scale factor is 1.

X variable;

Execute substring. This allows you to execute a second string from within a string.

P paint, boundary

DRAW Statement

Set figure color to paint and border color to boundary. The paint parameter is an integer expression. It chooses an attribute from the attribute range for the current screen mode. In medium resolution, this color is one from the current palette as defined for that attribute by the COLOR statement. Four color attributes (0-3) are available in medium resolution. In high resolution, two color attributes (0-1) are available:

.0

indicates black and 1 indicates white. The boundary parameter is the border color of the figure to be filled in, in the attribute range for the current screen mode. You must specify both paint and boundary, or an error occurs. This command does not support paint tiling, and it is valid for BASIC 2 .

.0

and later releases.

In all these commands, the n, x, or y argument can be a constant such as 123 or it can be = variable; where variable is the name of a numeric variable. The semicolon (;) is required when you use a variable this way, or in the X command. Otherwise, a semicolon is optional between commands. Spaces are ignored in string. For example, you can use variables in a move command this way:

M+=Xl; -=X2;

You can also specify variables in the form

VARPTR$(variable), instead of

=

variable;. This is the only form that can be used in compiled programs.

DRAW Statement

One Method Alternative Method

DRAW "XA$;" DRAW "X" + VARPTR$(A$) DRAW"S=SC;" DRAW "S="+VARPTR$(SC) The X command can be a very useful part of DRAW.

It allows you to define segments of a picture in different X variables and to combine these X

variables into a single DRAW statement. In this way you are able to create DRAW strings longer than 255 characters. For example, if you are creating a scene of a house with a chimney and a tree, each of these objects can be defined in an X variable so your DRAW statement can look like this:

DRAW "XHOUSE$;XCHIM$;XTREE$; II

The aspect ratio of your screen determines the spacing of the horizontal, vertical, and diagonal points. The DRAW statement does not take into account the aspect ratio of the current screen mode;

that is, DRAW "R5,0 U5,0" plots exactly 5,0 points to the right and then 5.0 up, but the two lines will not appear to be equal in length.

The aspect ratio is used to correct the shape of objects drawn on a nonlinear surface. The idea is to be able to draw a square, for example, that indeed looks square.

DRAW Statement

If there are 64.0 by 64,0 dots on a screen evenly spaced along the x and y axes, the aspect ratio is "1 to 1" or 1 / 1. This is an ideal surface. If you execute the statement:

DRAW "R100 0100 L100 U100"

then the box appears square.

However, this is not the case in BASIC, which supports two screen resolutions, each with its own aspect ratio. These are:

Resolution

Medium resolution High resolution

Aspect Ratio 32,0 by 2.0,0 dots 64,0 by 2.0,0 dots

5/6 5/12 To draw a box that appears square in either resolution, scale the y axis by the corresponding aspect ratio; or scale the x axis by 1/ aspect ratio.

For example, to draw a square box 1.0,0 high, scale the x axis as follows:

10 ~100"'6/5 is 120

20 DRAW "U100 R120 0100 L120"

DRAW

Statement

Example: To draw a box using variables:

HJ SCREEN 1

20 A=2030 DRAW "U=A;R=A;D=A;L=A;"

To draw a box and paint the interior:

10 DRAW "U50R50D50L5011 'Draw a box

20 DRAW IBEI0" I Move up and ri ght into box 30 0 RAW II PI, 3 II I P a i n tin t e rio r

To draw a triangle:

10 SCREEN 1

20 DRAW "E15 F15 L30"

To create a "shooting star":

10 SCREEN 1,0: COLOR 0,0: CLS 20 DRAW "BM300,25" I initial point

30 STAR$= "M+7,17 M-17,--12 M+20,0 M-17,12 M+7,-'1711 40 FOR SCALE=1 TO 40 STEP 2

50 DRAW "Cl;S=SCALE; BM-2,0;XSTAR$;"

60 NEXT

To draw some spokes:

10 SCREEN 1,0:CLS

20 FOR 0=0 TO 360 STEP 10 30 DRAW "TA=D; NU50"

40 NEXT 0

EDIT

Documents relatifs