# 4. Shapes and Patterns

Important Note: All variables in degrees must be converted to RADians as BASIC can only interpret radians.

## Changing the Geometry

Simply adding additional geometric shapes to the basic shapes discussed previously can make the graphic more dynamic and interesting. One of the simplest to enhance is the circle.

## Circles

The circle is the basis for an elementary graphic. Adding additional circles with their centres equi-spaced around the circumference of a central circle gives a simple but effective graphic and uses BASICs trigonometrical functions, sine and cosine to find the centres of the outside circles (figure 6). Fig 6: Multi-circles

MODE 1920,1080,32

ORIGIN 1920,1080

r = 500

CIRCLE 0,0,r

Now add the other 6 circles:

MODE 1920,1080,32

ORIGIN 1920,1080

r = 500

CIRCLE 0,0,r

FOR circ = 0 TO 300 STEP 60

NEXT

## Ellipse

A simple ellipse pattern can be created to give a pseudo torus. It starts with a basic ellipse drawn in the horizontal position (figure 7). Fig 7 Simple ellipse

Simply adding a FOR-NEXT loop to change the angle from 0 to PI (180°) and a STEP size of 0.15 gives the picture shown (figure 9). The STEP variable is critical to ensure the distance between each ellipse is the same. It gives 20 rotated ellipses + the base ellipse = 21 in total. A STEP size of 0.14 or 0.16 draws an incorrect gap size for the last ellipse. Fig 9 Pseudo torus

REM Create a pseudo torus

MODE 1920,1080,32 : OFF

X=1000 : Y=500

FOR angle=0 TO PI STEP 0.15

ELLIPSE 1920,1080,X,Y,angle

NEXT

## Ellipses at 90 Degrees

Overlapping ellipses as shown in figure 10 can be created with the routine below Fig 10 Ellipses at 90° (only 6 pairs of ellipses are shown)

MODE 1920,1080,32 : OFF

ORIGIN 1920,1080

GCOL ON 255,255,200 : CLG

X=100 : Y=50

REPEAT

ELLIPSE 0,0,X,Y, PI/2 : REM Vertical ellipse

GCOL OF RND(255),RND(255),RND(255)

ELLIPSE 0,0,X,Y : REM Horizontal ellipse

X+=50 : Y+=50

UNTIL X=1050

## Polygons

There are several ways of creating polygons for example to draw a hexagon requires a minimum of code as shown:

MODE 1920,1080,32 : OFF

X = 1920 : Y = 1080 : R = 1000

MOVE X + R, Y : REM Move to first point

FOR theta = 0 TO 360 STEP 60

NEXT theta

Note: Program uses degrees in the FOR-NEXT loop but converted to RADians in the DRAW command.

Just change the STEP size to alter the number of sides (eg. STEP 45 will create an octagon).

An extension to the hexagon program draws many polygons in a concentric pattern, starting with a square and finishing with a dodecagon:

MODE 1920,1080,32 : OFF

X = 1920 : Y = 1080

FOR sides = 4 TO 12

PROCPOLY

NEXT sides

END

DEF PROCPOLY

D_theta = 2 * PI/sides

theta=0

FOR N = 1 TO sides

theta=theta+D_theta

NEXT N

ENDPROC

MODE 1920,1080,32

END

theta=2*PI/NR

DX=R:DY=0

FOR N=1 TO NR

MOVE X,Y

DRAW X+DX,Y+DY

X1=DX*COS(theta)-DY*SIN(theta)

DY=DX*SIN(theta)+DY*COS(theta)

DX=X1

NEXT N

ENDPROC