Owl

Computer art or science? A stunning display of the BBC Micro's graphic abilities.

Volume 2

Number 2

April 1984

Pick-up your elliptical paint brush and make like a Van Gogh

If you consider that the BBC Micro's angular graphics are strictly for squares, why not think again ...

By ERIC J. SIMPSON

MOST pictures and diagrams produced by BBC graphics have an angular quality about them, based as they are on triangles, rectangles and squares.

To mimic paintings it is necessary to use an underlying technique to imitate an artist's brush strokes, and the best shape for this is the ellipse, which can be round as a circle or long and thin like a line.

This program produces a screen filling four colour owl by over-painting ellipses just as a painter in oils superimposes his brush strokes.

Most readers by now will have come across programs to draw circles using the parametric form for a circle of radius (RADIUS) and centre (XC, YC):

X=XC+RADIUS*COS(A)
Y=YC+R ADIUS*SIN(A)

with A varying from 0 to 360 degrees to draw a full circle, with GCOL commands to vary its colour and PLOT 85 to infill triangles.

A varies in steps so that the shape produced is not a true circle but a polygon with many sides. If the step size is 15 then the shape is a 24 sided regular polygon indistingushable from a circle on a VDU.

An ellipse has two measurements to describe it, its major semi-axis MAJ and it minor semi-axis MIN. In a circle MAJ equals MIN, but if their ratio is a long way from one the ellipse is very long and thin, so the ellipse is:

X=XC+MAJ*COS(A)
Y=YC+MIN*SIN(A)

The ellipse so far has its axes horizontal and vertical, which is of little use for mimicking painting, and now we need to rotate it anticlockwise about its centre by an angle INC. To rotate a point we use a rotation matrix:

This matrix only applies to rotation about the origin, so we omit XC,YC for the time being, giving:

X=MAJ*COS(A)*COS(INC)-MIN*SIN(A)*SIN(INC)
Y=MAJ*COS(A)*SIN(INC)+MIN*SIN(A)*COS(INC)

Finally we add XC back to X giving XT and YC back to Y giving YT to produce an ellipse where we can alter its shape, size, centre and inclination to the horizontal as we wish.

When the program was first written it had a run time of between six and seven minutes. I looked for ways to shorten this and it occurred to me that a look-up table was the obvious answer.

Each point involves the calculation of eight sines and cosines for INC and A. With 24 points to an ellipse, and more than 100 ellipses in the finished picture, we would need more than 20,000 such steps.

By putting a table of sines and cosines at the start of the program at five degree intervals, less than 150 calculations are needed.

So long as A and INC are always in multiples of five, their sines and cosines as elements of the array T at the start of the program, then:

COS(INC) is replaced by T(INC/5,1)
SIN(INC) is replaced by T(INC/5,2)
COS(A) is replaced by T(A/5,1)
SIN(A) is replaced by T(A/5,2)

To complete the speeding-up, MAJ, MIN, INC, XC and YC are entered as integers. The final expressions for plotting the curves become:

X=MAJ%*T(A%/5,1)
Y=MIN%*T(A%/5,2)
XT=X*T(INC%/5,1)-Y*T( INC%/5,2)+XC%
YT=X*T(INC%/5,2)+Y*T( INC%/5,1)+YC%

With these improvements the run time drops to about two minutes.

The look-up table occupies lines 5 to 30 in the listing. The green and white background is between lines 35 and 115. Line 55 changes red into green from the normal colours in Mode 1.

Lines 120 to 205 contain the routine for drawing an ellipse, drawing data from lines 245-845.

The data is split by REM statements to show which part of the owl is drawn by that section to facilitate modification in the final picture.

Lines 210 to 240 hold a print routine to put spots on the owl's breast.