# 2. Getting Started with Graphics

Users unfamiliar with BASIC should get a copy of the comprehensive BBC BASIC Reference Manual Issue 2 available from RISC OS Open Limited for 25UKP + P&P. There are 2 essential chapters covering "Simple" and "Complex Graphics" which explain in more detail the keywords used to create geometric objects. The next two tutorials cover the basics.

## Geometric Shapes

Lets start with the simple geometric shapes, the line, square/rectangle and circle/ellipse. The triangle and other polygons can be drawn with RISC OS BASIC using its built-in PLOT functions inconjunction with MOVE and DRAW commands. Since the introduction of BASIC V, version 1.04 some excellent commands like LINE, CIRCLE, ELLIPSE, RECTANGLE have been introduced making graphic drawing simpler and more accurate. All these specialised commands are also handled by PLOT functions. These are covered in more detail under the heading Creating Geometric Shapes With PLOT Command

## Line

Using the LINE command...

MODE 1920, 1080, 32

LINE 0, 0, 2000, 2000

Draws a line starting from X=0, Y=0 and finishing at X=2000 and Y=2000

## Square/Rectangle/Rectangle Fill

A square is drawn using the RECTANGLE command

MODE 1920, 1080, 32

RECTANGLE 1500, 600, 1000

MODE 1920, 1080, 32

RECTANGLE FILL 1500, 600, 1000

Draws a square with its bottom right-hand corner at co-ordinates, X = 1500, Y = 600. The last parameter (1000) sets the height and width which for a square is the same.

The RECTANGLE command keyword is much simpler and neater than using the MOVE and DRAW commands as in...

MODE 1920,1080,32

MOVE 1500,600

DRAW 2500,600

DRAW 2500,1600

DRAW 1500,1600

DRAW 1500,600

The RECTANGLE command is used to create a rectangle by adding an extra parameter to specify the height...

MODE 1920, 1080, 32

RECTANGLE 1500, 600, 1000, 1500

To fill a square or rectangle with default colour (white) substitute RECTANGLE FILL for RECTANGLE.

## Circle and Circle Fill

MODE 1920,1080,32

CIRCLE 1920,1080,1000

MODE 1920,1080,32

CIRCLE FILL 1920,1080,1000

## Ellipse/Ellipse Fill

An ellipse requires a centre point co-ordinate and dimensions for its major and minor axes.

MODE 1920,1080,32

ELLIPSE 1920,1080,1000,500

MODE 1920,1080,32

ELLIPSE FILL 1920,1080,1000,500

This creates an axis aligned ellipse by default. A fifth parameter specifies how much the ellipse is rotated away from its default axis. The parameter is given in PI units. The example below shows a filled ellipse rotated by PI/3 or (180/3) = 60°

MODE 1920,1080,32

ELLIPSE FILL 1920,1080,1000,500,PI/3

## Before BASIC 1.04

A circle might be drawn like this...

MODE 1920,1080,32

R = 1000

MOVE 1920+R,1080

DT=PI*2/R

TH=0

FOR N=1 TO R

TH=TH+DT

DRAW 1920+R*COS(TH),1080+R*SIN(TH)

NEXT N

Compare with code under Circle and Circle Fill where only a single command is needed and a more accurate circle is drawn.