In the previous program, the instruction plot 50*cos(a),50*sin(a) was repeated 4 times. This
instruction can be typed in as a sub-routine; and called into action each time it is needed by using
the word gosub. Type in the following:
new
5 cls
10 for a=1 to 360
15 deg
20 origin 196,282
30 gosub 120
40 origin 442,282
50 gosub 120
60 origin 196,116
70 gosub 120
80 origin 442,116
90 gosub 120
100 next
110 end
120 plot 50*cos(a),50*sin(a)
130 return
run
Note that the instruction end is used in line 110; otherwise the program would naturally continue
after instruction 100, and carry out instruction 120, which is only required when called by gosub.
To conclude this section, try the following program which incorporates a lot of the programming
commands and keywords that you should now understand. Type in:
new
10 mode 0:border 6:paper 0:ink 0,0
20 gosub 160:for x=1 to 19:locate x,3
30 pen 15:print" ";chr$(238)
40 for t=1 to 50:next t:sound 2,(x+100)
50 next x:gosub 50 for b=3 b=3 to 22
60 locate 20,b:pen 7:print chr$(252)
70 cls:gosub 160:next b
80 sound 2,0,100,15,0,0,1
90 gosub 160:border 160:border 16,24:locate 20,25
100 pen 14:print chr$(253);
110 for t = 1 to 1000:next t
120 border 6:gosub 160:for f=3 to 24
130 locate 10,(25-f):pen 2
140 print chr$(l44):cls:gosub 160
150 sound 7,(100-f),5:next f:goto 10
160 locate 10,25: pen 12
170 print chrS(239):return
run