Tutorial 015 More Graphics Programs
***In the following, those marked with an asterisk* have been developed
from ideas in Alan Thomas' excellent book Further Programming for the BBC
Micro which I bought in 1983 - I saw a second hand copy at the Book Barn,
White Cross, Somerset, BS39 6EX, UK, Telephone 01761-451777 the other
day for £3-50 (its long been out of print).
Lines
REM Lines by R.G.Weston
MODE8
REPEAT
INPUTTAB(15,12)"How many lines
would you like to draw : "no_lines
CLS : OFF
FOR n=1 TO no_lines
PRINTTAB(0,0);n
GCOL0, RND(15)
x1=RND(1279) :
y1=RND(1024)
x2=RND(1279) :
y2=RND(1024)
LINE x1,y1,x2,y2
delay=INKEY(20)
NEXT n
delay=INKEY(300)
CLS:COLOUR RND(7)
UNTIL FALSE
Exercises : Speed up the display.
Make all lines start at the centre of the screen and radiate out from
there.
Linescope*
Just keep watching - it goes on for ever....
MODE8:OFF
COLOUR 0, 2
COLOUR 8, 1
mx=640:my=512
ORIGIN 640,512
st=RND(100)
x=RND(mx) : y=RND(my)
sw=0
n=0
REPEAT
n=n+1
GCOL0,n MOD 15
delay=INKEY(1)
x1=x: y1=y
IF sw=1 THEN x1=(mx/st)*RND(st)
IF sw=0 THEN y1=(my/st)*RND(st)
MOVE x,y : DRAW x1,y1
MOVE -x,y : DRAW -x1,y1
MOVE -x,-y DRAW -x1,-y1
MOVE x,-y : DRAW x1,-y1
x=x1 : y=y1
sw=(sw+1) MOD 2
G$=INKEY$(10)
UNTIL n=40
delay=INKEY(200)
RUN
Flower*
Play about with some of the parameters to see how this works
MODE8 : OFF
PRINTTAB(30)"Press SPACE"
COLOUR 0, 1
COLOUR 8,5
n=40
dt=PI/n
a=512
k=8
ORIGIN 640,512
MOVE 0,0
IF k MOD 2 =0 THEN dt=2*dt
e=0
FOR i=1 TO k
GCOL0,RND(15)
t=PI/(2*k)
FOR j=1 TO n
PRINTTAB(1,3)"j
= ";j
delay=INKEY(10)
x=a*COS(k*t)*COS(t+e)
y=a*COS(k*t)*SIN(t+e)
DRAW x,y
t=t+dt
PRINTTAB(1,1)"i
= ";i
G=GET
NEXT j
e= e + 0.1
NEXT i
Epicycles*
Run his program lots of times to see the range of possibilities. (Remember
Spirograph?)
A wheel of radius b rolls round the inside of a circle radius
a. The program plots the path of an ant sitting on the inner wheel
at a distance r from the centre of the smaller, inner wheel.
The outer red circle contains a smaller red circle, which follows the
path of the centre of the inner wheel. The green circles show the limits
of travel of the ant! If the inner wheel is almost as big as the outer circle
the results are quite surprising.
REM Epicycles
REM by RG Weston
REM 22 Feb 2003
REM After Alan Thomas
REM Wheels within Wheels 1983
MODE8:OFF
PRINTTAB(25)"Press SPACE to go again"
a=500
b=20+RND(460)
r=RND(b)
d=a-b : e=d/b
t=0
dt=0.1
PRINT" a = ";a
PRINT" b = ";b
PRINT" r = ";r
ORIGIN 640,512
GCOL0,1
PLOT69,0,0
CIRCLE 0,0,a
CIRCLE 0,0,d
GCOL0,2
CIRCLE 0,0,d-r
CIRCLE 0,0,d+r
MOVE d+r, 0
GCOL0,15
REPEAT
x=d*COS(t) + r*COS(e*t)
y=d*SIN(t) - r*SIN(e*t)
DRAW x,y
t=t+dt
UNTIL INKEY$(1)=" "
RUN
Chessboard*
The following program produces a chessboard too quickly, on most machines,
for one to see how it is done.
REM: Chessboard fast
draw
REM: Richard Weston
24th March 2003
REM: after Alan Thomas
MODE8:OFF
a=100
x=250:y=100
s=8*a
RECTANGLE x,y,s,s
FOR i=1 TO 8
FOR j=1 TO 8
IF (i+j) MOD 2 =
0 THEN
p=x+a*(i-1)
q=y+a*(j-1)
RECTANGLE
FILL p,q,a,a
ENDIF
NEXT j
NEXT i
Here I have added a few more lines to show how it works and to slow things
up :
REM: Chessboard Demo
REM: Richard Weston 24th March 2003
REM: after Alan Thomas
MODE8:OFF
a=100
x=250:y=100
s=8*a
RECTANGLE x,y,s,s
FOR i=1 TO 8
FOR j=1 TO 8
PRINTTAB(35,30)("
i = ");i
PRINTTAB(7,15)("
j = ");j
IF (i+j) MOD 2 =
0 THEN
p=x+a*(i-1)
q=y+a*(j-1)
RECTANGLE
FILL p,q,a,a
delay=INKEY(40)
ENDIF
NEXT
NEXT
PRINTTAB(32,2)"Anyone for Chess?"
Next Tutorial
Richard Weston's Homepage