3. Creating Geometric Shapes With PLOT Command

Contents

The previous chapter covers most of the simple graphics that can be generated in BASIC V using special custom designed keywords. Lines, points, triangles, segments and sectors including circles, ellipses and squares and rectangles can also be drawn using the PLOT command of which there are 23. More are listed but have special functions.

Command format... PLOT k,x,y where k is the plot mode (refer to BBC BASIC Reference Manual) and x and y are the co-ordinates of a point required to position the shape. Within each PLOT command there is a block of 8 digits which act as an offset allowing programmer to plot a shape in either relative or absolute co-ordinates. 3 apply different colour to the drawing in relative co-ordinates and 3 apply different colour in absolute co-ordinates (see appendix). The following examples both of which give an identically positioned line will hopefully show the distinction between absolute and relative forms.

Line Plot

Absolute Plot

PLOT a line from X=500, Y=500 to X=2000, Y=2000

MODE 1920,1080,32

PLOT 4,500,500

PLOT 5,2000,2000

Relative Plot

Plot a line from X=500, Y=500 to X=1500 ,Y=1500

MODE 1920,1080,32

PLOT 4,500,500

PLOT 1,1500,1500

The co-ordinates (1500,1500) is relative to the position of the graphics cursor. The absolute value is obtained by adding this offset to the previous position (1500,1500) + (500,500) giving the position (2000,2000).

PLOT 4 is equivalent to a MOVE command.

Triangle

MODE 1920,1080,32

MOVE 1000,400 : REM Left corner

MOVE 3000,400 : REM Right corner

PLOT 85,2000,1500 : REM Top corner

Rectangle - Filled

Example using absolute co-ordinates

MODE 1920,1080,32

MOVE 1000,400 : REM Bottom left corner

PLOT 101,2000,1500 : REM Top right corner

Example using relative co-ordinates

MODE 1920,1080,32

MOVE 1000,400

PLOT 97,1000,1100

Parallelogram - Filled

Defined by 3 points the parallelogram is a rectangle that has been sheered sideways (figure 1)

Fig 1 Parallelogram

MODE 1920,1080,32

MOVE 1000,500

MOVE 2500,500

PLOT 117,3000,1500

To sheer the parallelogram to the left alter the PLOT command to...

PLOT 117,2000,1500

Circle - Outline

Move to circle centre (1920,1080 = centre of screen in this example). For a circle with a radius of 1000 OS units simply add 1000 to the X co-ordinate, 1920 to give 2920.

MODE 1920,1080,32

MOVE 1920,1080 : REM Centre

PLOT 149,2920,1080 : REM Centre(X)+radius, Centre(Y)

An identical circle can be plotted using the relative plotting option...

MODE 1920,1080,32

MOVE 1920,1080 : REM Centre

PLOT 145,1000,0 : REM Radius,0

Ellipse - Outline

As well as a centre point, an ellipse requires the co-ordinates for 2 additional points - a righthand point along the horizontal axis and the highest point. See drawing (figure 2)

Fig 2 Calculating the co-ordinates for an ellipse

1. Assign the ellipse centre (1920,1080) to the first MOVE command (MOVE 1920,1080). All co-ordinates are referenced from this point.

2. Draw horizontal line through the ellipse centre to give 2 co-ordinate points that intersect the circumference. With a horizontal co-ordinate of 500 we get...

MOVE 1920+500, 1080 or MOVE 2420,1080

3. Draw another line through the ellipse centre to give 2 co-ordinate points intersecting with the circumference as shown. With co-ordinates of X= 500 and Y=700 we get...

MOVE 1920+500,1080+700 or MOVE 2420,1780.

This example uses the right side co-ordinates. The ellipse can be drawn using the left side ones bearing in mind that values are subtracted from the centre reference point (1920,1080).

Important

Example shows the horizontal co-ordinates for point B and C to be the same (1920 + 500). This is an approximation - In practice the horizontal co-ordinates for point B and C will be different depending on the angle of rotation of the ellipse.

MODE 1920,1080,32

MOVE 1920,1080 : REM Set centre

MOVE 2420,1080 : REM Define right-hand point

PLOT 197,2420,1780 : REM Define highest point

The same ellipse can be drawn using the left-hand points, D and E

MODE 1920,1080,32

MOVE 1920,1080 : REM Set centre

MOVE 1420,1080 : REM Define left-hand point

PLOT 197,1420,380 : REM Define lowest point

Arc

An arc is part of a circle and figure 3 shows how the co-ordinates are defined...

Fig 3 Plotting a quarter arc

MODE 1920,1080,32

MOVE 1920,1080 : REM Centre

MOVE 920,1080 : REM Start point

PLOT 165,1920,80 : REM End point

Sector

A sector consists of an arc of a circle bound by 2 radii (figure 4)

Fig 4 Plotting a sector

MODE 1920,1080,32

MOVE 1920,1080 : REM centre

MOVE 920,1080 : REM start point

PLOT 181,1200,80 : REM end point - effectively determines sector angle

Segment

Similar to a sector but is the area of a line between 2 points on a circle and its circumference (figure 5). In fact the only difference in the code is the PLOT command 173 instead of 181.

Fig 5 Plotting a segment

MODE 1920,1080,32

MOVE 1920,1080 : REM centre

MOVE 920,1080 : REM start point

PLOT 173,1200,80 : REM end point

There are also some special PLOT commands to colour fill a closed object no matter its complexity and a unique Block copy/move PLOT command that can be used to create unusual animation effects. All these commands are listed in the Appendix:

That concludes the construction of the basic shapes. The next section covers some slightly more complex shapes and patterns to show the versatility of RISC OS BASIC.

Top of page