AMSTRAD CPC464 User Manual page 47

Cpc464 colour personal computer 64k
Hide thumbs Also See for CPC464:
Table of Contents

Advertisement

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
1 0 f o r a = 1 t o 3 6 0
15 deg
2 0 o r i g i n 1 9 6 , 2 8 2
3 0 g o s u b 1 2 0
4 0 o r i g i n 4 4 2 , 2 8 2
5 0 g o s u b 1 2 0
6 0 o r i g i n 1 9 6 , 1 1 6
7 0 g o s u b 1 2 0
8 0 o r i g i n 4 4 2 , 1 1 6
9 0 g o s u b 1 2 0
1 0 0 n e x t
110 end
1 2 0 p l o t 5 0 * c o s ( a ) , 5 0 * s i n ( a )
1 3 0 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
1 0 m o d e 0 : b o r d e r 6 : p a p e r 0 : i n k 0 , 0
2 0 g o s u b 1 6 0 : f o r x = 1 t o 1 9 : l o c a t e x , 3
3 0 p e n 1 5 : p r i n t " " ; c h r $ ( 2 3 8 )
4 0 f o r t = 1 t o 5 0 : n e x t t : s o u n d 2 , ( x + 1 0 0 )
5 0 n e x t x : g o s u b 5 0 f o r b = 3 b = 3 t o 2 2
6 0 l o c a t e 2 0 , b : p e n 7 : p r i n t c h r $ ( 2 5 2 )
7 0 c l s : g o s u b 1 6 0 : n e x t b
8 0 s o u n d 2 , 0 , 1 0 0 , 1 5 , 0 , 0 , 1
9 0 g o s u b 1 6 0 : b o r d e r 1 6 0 : b o r d e r 1 6 , 2 4 : l o c a t e 2 0 , 2 5
1 0 0 p e n 1 4 : p r i n t c h r $ ( 2 5 3 ) ;
1 1 0 f o r t = 1 t o 1 0 0 0 : n e x t t
1 2 0 b o r d e r 6 : g o s u b 1 6 0 : f o r f = 3 t o 2 4
1 3 0 l o c a t e 1 0 , ( 2 5-f ) : p e n 2
1 4 0 p r i n t c h r $ ( l 4 4 ) : c l s : g o s u b 1 6 0
1 5 0 s o u n d 7 , ( 1 0 0-f ) , 5 : n e x t f : g o t o 1 0
1 6 0 l o c a t e 1 0 , 2 5 : p e n 1 2
1 7 0 p r i n t c h r S ( 2 3 9 ) : r e t u r n
run

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents