P1 Nitemare


This program shows how dramatic effects can be produced fairly easily with the ELECTRON micro. The aim of the program is to have a symmetric shape on the screen, changing colour very quickly accompanied by a set of discordant noises - hence the title.

The mode selected is 5, this allows us to have 4 colours on the screen at any one time. Lines 190-220 select which 4 colours are chosen at any time. Eight radially symmetric triangles are plotted on the screen followed by a random discordant chord. Lines 330-350 (PROCtriangle) is used to plot the triangles onto the screen.


This procedure evaluates the coordinates of the corners of the triangle as from the above figure.

COMMANDS

To play the program, simply key it in and type RUN.

  100 REM Program P1 - Nitemare
  110 MODE 5
  120 REPEAT
  130  
  140 R=RND(511)
  150 T=RND(1)*PI*2
  160 Z=RND(100)
  170 D=RND(1)
  180  
  190 REM change logical colours
  200 FOR I%=0 TO 3
  210 VDU 19,I%,RND(8)-1,0,0,0
  220 NEXT I%
  230  
  240 REM select actual colour
  250 GCOL 0,RND(4)
  260  
  270 REM draw 8 symmetric triangles
  280 FOR I%=0 TO 7
  290 PROCtriangle(R,T+PI/4*I%,Z)
  300 NEXT I%
  310  
  320 REM make random noise
  330  
  340 SOUND 1,-15,RND(64)*4-3,40
  350  
  360  
  370 UNTIL 0:REM do forever
  380 END
  390  
  400 DEF PROCtriangle(R,T,Z)
  410  
  420 X=R*COS(T)+639
  430 X1=(R+Z)*COS(T+D)+639
  440 X2=(R+Z)*COS(T-D)+639
  450 Y=R*SIN(T)+511
  460 Y1=(R+Z)*SIN(T+D)+511
  470 Y2=(R+Z)*SIN(T-D)+511
  480  
  490 PLOT 4,X,Y
  500 PLOT 4,X1,Y1
  510 PLOT 85,X2,Y2
  520 ENDPROC


P2 Musak


This program converts the ELECTRON keyboard into a musical type keyboard. Lines 120-150 identify which keys are to be used. The numeric keys 1-9 select the duration of each note. V1$ selects those keys which are to be used to control channel-1, V2$ controls channel-2 and V3$ controls channel-3.

The sound is generated with "Flush Control" on, that is we use the command SOUND &1n,A,P,D in lines 270 to 290. This ensures that whenever a new note is selected the previous note is flushed from the channel queue and the sound is generated immediately.

COMMANDS

To play the program, key in and then type RUN.
Use numeric key 0 to 9 to select duration of note.
Use keys "Q" to "P" to control channel 1.
Use keys "A" to "L" to control channel 2.
Use keys "Z" to "M" to control channel 3.
Use keys "," and "." to select envelope for next change of duration.


100 REM Program P2 - MUSAK 110 MODE 2 120 VDU 29,640;512; 130 N$="123456789" 140 V1$="QWERTYUIOP" 150 V2$="ASDFGHJKL" 160 V3$="ZXCVBNM,." 170 L=50 180 Y=0 190 REPEAT 200 X$=GET$ 210 X=INSTR(N$+V1$+V2$+V3$,X$) 220 IF X$="," THEN Y=0 230 IF X$="." THEN Y=1 240 IF X<10 AND Y>0 THEN ENVELOPE 1,20*X,0,0,0,0,0,0,126 ,0,0,-126,126,126:L=X*10 250 IF X<10 AND Y=1 THEN ENVELOPE 1,2*X,10,0,-10,100,100 ,100,126,0,0,-126,126,126:L=X*10 260 X=X-9 270 IF X>0 AND X<11 THEN SOUND &11,1,24+4*X,L 280 IF X>10 AND X<20 THEN SOUND &12,1,24+4*X,L 290 IF X>19 AND X<28 THEN SOUND &13,1,24+4*X,L 300 P=RND(1000)-500:C=C+1 MOD 16:GCOL 0,C 310 MOVE RND(100),RND(100):MOVE P,-P*SIN(X) 320 PLOT 85,RND(1000)-500,RND(1000)-500 330 UNTIL 0 340 END


P3 Tunes


The ELECTRON micro can be used to mimic the sound of many instruments. In this program, we have almost a "bagpipe-ish" sound. This is achieved by the 3 envelopes in lines 130-150. Each envelope controls a separate sound channel, and when notes are played they are synchronised in lines 450-470.

The tunes are stored as data statements from line 400 onwards. Notice how the correct tune is selected in line 280. The first two parameters allow you to change the speed at which the tune is played and to change the pitch of the tune.

Note that I have left some suspicious notes in tune number three. I leave it as an exercise to the user to find the bad notes.

Once you have found the bad notes you can alter the pitch to correct them.

COMMANDS

Key in program and tyoe RUN.
Press appropriate key from MENU.

  100 REM Program P3 - Tunes
  110  
  120  
  160 MODE6
  170 PRINT ''"          T U N E S"
  180 PRINT ''
  190 PRINT "   1. Auld Lang Syne"
  200 PRINT '"   2. Charlie is my Darling"
  210 PRINT '"   3. Blow The Man Down"
  220 PRINT ''"   4. end the program"
  230 REPEAT
  240   PRINT TAB(0,18);"Enter choice";
  250   choice=VAL(GET$)
  260   PRINT choice
  270    
  280   IF choice<4 THEN RESTORE choice*100+ 300 ELSE END
  290   READ BEAT,ADJUST
  300   REPEAT
  310     READ P,D
  320     D=D*BEAT:P=P+ADJUST
  330     IF P=0 SOUND 1,0,0,D ELSE SOUND 1,-15,P,D
  360   UNTIL D=0
  370 UNTIL 0
  380 END
  390  
  400 REM Auld Lang Syne
  410 DATA 1.25,0,101,4,121,6,121,2,121,4,137,4,129,6,121,2,
129,4,137,4
  420 DATA 121,6,121,2,137,4,149,4,157,12,169,4,149,6,137,2,
137,4,121,4
  430 DATA 129,6,121,2,129,4,137,2,129,2,121,6,109,2,109,4,1
01,4
  440 DATA 121,12,157,4,149,4,137,4,137,4,121,4,129,6,121,2,
129,4,137,4
  450 DATA 149,2,137,6,137,4,149,4,157,12,169,4,149,6,137,2,
137,4,121,4
  460 DATA 129,6,121,2,129,4,137,2,129,2,121,6,109,2,109,4,1
01,4,121,12
  470 DATA 0,0
  480  
  490  
  500 REM Charlie is my Darling
  510 DATA 1.3,0,109,6,117,2,121,6,129,2,137,8,157,6,165,2,1
69,8,165,6,157,8,137,8
  520 DATA 109,6,117,2,121,6,129,2,137,8,157,4,0,2,137,2,145
,8,157,4,0,2,145,2,137,8,157,4,0,2,137,2
  530 DATA 109,6,129,2,121,6,129,2,137,8,157,6,165,2,169,8,1
65,6,157,2,157,12,157,4
  540 DATA 149,6,137,2,145,6,149,2,157,6,165,2,169,6,157,2,1
49,6,137,2,145,6,149,2,157,8,0,4,165,4
  550 DATA 169,6,165,2,169,6,157,2,149,4,137,4,121,4,129,2,1
37,2,145,6,129,2,137,6,121,2,117,8,121,6,117,2
  560 DATA 109,6,117,2,121,6,129,2,137,8,157,4,0,2,137,2,145
,8,157,4,0,2,145,2,137,8,157,4,0,2,137,2
  570 DATA 109,6,117,2,121,6,129,2,137,8,157,4,0,2,165,2,169
,8,165,6,157,2,157,12
  580 DATA 0,0
  590  
  600 REM Blow the Man Down
  610 DATA 2,-48,121,4,137,4,149,6,157,2,149,4,137,4,121,4,1
37,4,149,6,157,2,149,4,137,4,121,4,137,4
  620 DATA 149,6,157,6,145,6,137,2,145,4,129,8,137,4,145,6,1
37,2,145,4,129,4,117,4,101,4
  630 DATA 145,4,137,4,129,4,157,8,169,4,149,2,149,6,149,4,1
49,8,145,4,137,6,129,2
  640 DATA 137,4,121,4,0,0


P4 Pattern


This program generates patterns of straight lines reminiscent of "pin pictures". As it stands the program draws straight lines from points on two reference lines. It would be interesting to change this program to use curves rather than straight lines.

The end points of the reference lines are given in lines 120 and 130, and the number of points per line in line 140. The equations of the lines in the form y=mx+c are calculated in 220-250, with the step sizes calculated in lines 200,210.

The program then simply steps down each line drawing straight lines to produce a pattern thus:

Notice that as the program stands it cannot handle vertical lines, where the gradient calculation will give a division by zero error. This could of course be amended by the user.

COMMANDS

Key in program and type RUN.
Enter end points of lines when requested, followed by number of points per line.


100 REM Program P4 - Pattern 110 MODE 1 120 INPUT "What are the end points of line 1"'"(enter in t he form X,Y)"X1,Y1,X2,Y2 130 INPUT "What are the end points of line 2"'"(enter in t he form X,Y)"X3,Y3,X4,Y4 140 INPUT''"Enter the number of points per line"K 150 CLS 160 VDU 19,0,6;0;19,3,0;0; 170 180 190 REM The following section calculates the parameters 200 DX1=(X2-X1)/K 210 DX2=(X4-X3)/K 220 M1=(Y2-Y1)/(X2-X1) 230 M2=(Y4-Y3)/(X4-X3) 240 B1=Y1-M1*X1 250 B2=Y3-M2*X3 260 MOVE X1,Y1:DRAW X2,Y2 270 MOVE X3,Y3:DRAW X4,Y4 280 FOR I=1 TO K 290 MOVE X1+I*DX1,M1*(X1+I*DX1)+B1 300 GCOL 3,I 310 DRAW X4-I*DX2,M2*(X4-I*DX2)+B2 320 NEXT I 330 END


P5 Graph Plotting


A slightly mathematical program here - it is used to plot the graph of a mathematical function, in most micros this would have been an awkward program to write, but ELECTRON BASIC provides us with the EVAL function, which allows us to input the function as a simple string and then EVALuate the function at each point to be plotted.

This program also illustrates the use of normal characters to build up a LOGO on the screen. To help you in coding such a screen use a "text planning sheet" as given in the User Guide. Lines 170-300 show what kind of effect can be achieved with the ELECTRON micro.

Lines 350-440 set up the parameters for the function to be plotted. Notice that there has been an attempt to trap errors at this point by using the flag "K".

Lines 460-670 draw and label the axes, with the function being plotted lines 690-740.

Notice that the labelling of the axes is achieved by joining the text and graphics cursors (line 610).

COMMANDS

Key in program and type RUN.
Enter function of X when requested. If Y-range is not specified it is given as -512 to 512.
Note that X must be in upper case, and that only the right hand side of f(X) is entered.

  100 REM Program P5 - Graph Plot
  110 MODE 4
  120 REM change colours
  130 VDU 19,0,4,0,0,0
  140 VDU 19,1,3,0,0,0
  150  
  160 REM display logo
  170 PRINT'''''
  180 PRINT"    ##   ####     #    ####  #   #"
  190 PRINT"   #  #  #   #   # #   #   # #   #"
  200 PRINT"  #      #   #  #   #  #   # #   #"
  210 PRINT"  #  ### ####   #####  ####  #####"
  220 PRINT"  #   #  #  #  #     # #     #   #"
  230 PRINT"   ####  #   # #     # #     #   #"
  240 PRINT''''
  250 PRINT"       ####  #      ####  #####"
  260 PRINT"       #   # #     #    #   #"
  270 PRINT"       #   # #     #    #   #"
  280 PRINT"       ####  #     #    #   #"
  290 PRINT"       #     #     #    #   #"
  300 PRINT"       #     #####  ####    #"
  310  
  320 wait$=INKEY$(200)
  330 CLS
  340 INPUT ''''"Function to be plotted",function$
  350 REPEAT
  360   K=1
  370   INPUT "Max X value ",XMAX
  380   INPUT "Min X value ",XMIN
  390   IF XMIN>XMAX THEN PRINT "XMIN >XMAX":K=0
  400   INPUT "Do you wish to specify Y-range"ANS$
  410   YMIN=-512:YMAX=512
  420   IF LEFT$(ANS$,1)="Y" THEN  INPUT '"Ymax ",YMAX:INPUT
 "Ymin ",YMIN
  430   IF YMIN>YMAX THEN PRINT "YMIN>YMAX":K=0
  440 UNTIL K=1
  450  
  460 REM draw axes
  470 CLS
  480 XRANGE=XMAX-XMIN
  490 YRANGE=YMAX-YMIN
  500 DX=XRANGE/1280
  510 DY=YRANGE/1024
  520  
  530 REM CX,CY coords of centre
  540 IF YMIN<0 THEN CY=ABS(YMIN) ELSE CY=0
  550 CY=CY/DY
  560 MOVE 0,CY:DRAW 1280,CY
  570 IF XMIN<0 THEN CX=ABS(XMIN) ELSE CX=0
  580 CX=CX/DX
  590 MOVE CX,0:DRAW CX,1024
  600  
  610 VDU 5:REM join text and graphics cursor
  620 FOR I=0 TO 7
  630   MOVE 160*I,CY
  640   PRINT STR$(INT(((160*I*DX)+XMIN)*10+.5)/10)
  650   MOVE CX+4,128*I
  660   PRINT STR$(INT(((128*I*DY)+YMIN)*10+.5)/10)
  670 NEXT I
  680  
  690 GCOL 4,1
  700 FOR I=0 TO 1280 STEP 4
  710   X=XMIN+I*DX
  720   Y=(EVAL(function$)-YMIN)/DY
  730   PLOT 69,I,Y
  740 NEXT I
  750  
  760 VDU 4:REM seperate cursors
  770 PRINT "Plot of Y="function$
  780 END


P6 Bouncing Ball 1


This program shows a simple method of achieving animation, in normal text mode. The "ball" is the letter o.

Animation is accomplished by placing the ball on the screen and then placing a space character on top; the ball is then printed one position on.

COMMANDS

Key in program and RUN.

  100 REM Program P6 - Bouncing Ball 1
  110 MODE 6
  120 X=RND(30)+2
  130 Y=RND(18)+2
  140 DX=1
  150 DY=1
  160 VDU 23,1,0;0;0;0; : REM Switch cursor off
  170 PRINT TAB(X,Y);
  180 REPEAT
  190   PRINT TAB(X,Y);"o";
  200   IF X=2 OR X=36 THEN DX=-DX
  210   IF Y=2 OR Y=22 THEN DY=-DY
  220   FOR I=1 TO 15:NEXT I
  230   PRINT TAB(X,Y);" ";
  240   X=X+DX
  250   Y=Y+DY
  260 UNTIL 0


P7 Bouncing Ball 2


This program should be compared with program 6, in that they both give a similar result - a shape bouncing around the screen. However, in graphics mode it is simpler to draw other shapes onto the screen - e.g. the box around the ball.

Change the conditions in line 250,260 to see the effect of bursting a hole in the wall. Other effects which can be experimented with are to draw a snake instead of a ball in lines 210-240, or not to unplot the ball in lines 270-300.

Colour has not been implemeted in this program, but four are available. What about three different coloured balls bouncing around the screen?

COMMANDS

Key in program and type RUN.

  100 REM Program P7 - Bouncing Ball 2
  110 MODE5
  120 VDU 5
  130 MOVE 10,10
  140 DRAW 10,1000
  150 DRAW 1000,1000
  160 DRAW 1000,10
  170 DRAW 10,10
  180 X%=RND(800)+100:Y%=RND(800)+100
  190 DX%=10:DY%=20
  200 REPEAT
  210   PLOT 69,X%,Y%
  220   PLOT 69,X%,Y%+1
  230   PLOT 69,X%+1,Y%
  240   PLOT 69,X%+1,Y%+1
  250   IF (X%+DX%)>999 OR (X%+DX%)<13 THEN DX%=-DX%
  260   IF (Y%+DY%)>999 OR (Y%+DY%)<13 THEN DY%=-DY%
  270   PLOT 71,X%,Y%
  280   PLOT 71,X%,Y%+1
  290   PLOT 71,X%+1,Y%
  300   PLOT 71,X%+1,Y%+1
  310   X%=X%+DX%:Y%=Y%+DY%
  320 UNTIL 0
  330  
  340 END


P8 Jimmy


This is another animation program except that this time we are using the user defined characters to create a cartoon figure, Jimmy.

As an example of the use of Jimmy, lines 190-350 wave his left hand.

To change one of the user defined characcters use a user defined character planning sheet as shown in the User Guide.

It is left to the user to build up the full Jimmy character set. There are seventeen characters available.

COMMANDS

Key in program and RUN.
Key in your own routines between lines 160 and 360, and see how to make Jimmy move.


  100 REM Program P8 - Jimmy
  110 DIM JIMMY$(31)
  120 MODE5
  130 FOR I=224 TO 255
  140   READ B1%,B2%,B3%,B4%,B5%,B6%,B7%,B8%
  150   VDU 23,I,B1%,B2%,B3%,B4%,B5%,B6%,B7%,B8%
  160   JIMMY$(I-224)=CHR$(I)
  170 NEXT I
  180  
  190 REM We can now play with Jimmy, the following code wav
es his left hand
  200  
  210 PRINT TAB(9,8) JIMMY$(0)
  220 PRINT TAB(8,9) JIMMY$(8);JIMMY$(2)
  230 PRINT TAB(8,10) JIMMY$(9);JIMMY$(3)
  240 PRINT TAB(8,11) JIMMY$(18);JIMMY$(16);JIMMY$(17)
  250  
  260 REPEAT
  270   PRINT TAB(10,9) JIMMY$(6)
  280   PRINT TAB(10,10) JIMMY$(7)
  290   FOR I=1 TO 300:NEXT I
  300   PRINT TAB(10,10) " "
  310   PRINT TAB(10,9) JIMMY$(13)
  320   PRINT TAB(10,8) JIMMY$(12)
  330   FOR I=1 TO 300:NEXT I
  340   PRINT TAB(10,8) " "
  350 UNTIL 0
  360 END
  370  
  375 REM Note that I have left some parts of Jimmy for you 
to fill in
  380 DATA 24,60,90,126,126,102,62,24:REM HEAD ON
  390 DATA 0,0,0,0,0,0,0,0:REM HEAD PROFILE
  400 DATA 24,255,255,255,231,126,102,126:REM UPPER TRUNK ON
  410 DATA 102,60,60,60,126,231,231,231:REM LOWER TRUNK ON
  420 DATA 0,0,0,0,0,0,0,0
  430 DATA 0,0,0,0,0,0,0,0
  440 DATA 0,128,192,224,112,48,48,48:REM UPPER LEFT ARM
  450 DATA 48,48,48,0,0,0,0,0:REM LOWER LEFT ARM
  460 DATA 0,1,3,7,14,12,12,12:REM UPPER RIGHT ARM
  470 DATA 12,12,12,0,0,0,0,0:REM LOWER RIGHT ARM
  480 DATA 0,0,0,0,0,0,0,0
  490 DATA 0,0,0,0,0,0,0,0
  500 DATA 0,0,0,48,48,48,48,48:REM UPPER RAISE LEFT
  510 DATA 112,240,192,128,0,0,0,0:REM LOWER RAISE LEFT
  520 DATA 0,0,0,0,0,0,0,0
  530 DATA 0,0,0,0,0,0,0,0
  540 DATA231,231,231,231,231,231,231,231:REM LEGS ATTENTION
  550 DATA 0,0,0,0,0,0,192,192:REM LEFT FOOT
  560 DATA 0,0,0,0,0,0,3,3:REM RIGHT FOOT
  570 DATA 0,0,0,0,0,0,0,0
  580 DATA 0,0,0,0,0,0,0,0
  590 DATA 0,0,0,0,0,0,0,0
  600 DATA 0,0,036,60,60,255,255:REM HAT
  610 DATA 0,24,60,126,126,60,24,0:REM BALL
  620 DATA 60,126,255,126,60,24,24,24:REM BAT
  630 DATA 0,0,0,0,0,0,0,0
  640 DATA 0,0,0,0,0,0,0,0
  650 DATA 0,0,0,0,0,0,0,0
  660 DATA 0,0,0,0,0,0,0,0
  670 DATA 0,0,0,0,0,0,0,0
  680 DATA 0,0,0,0,0,0,0,0
  690 DATA 0,0,0,0,0,0,0,0
  700 DATA 0,0,0,0,0,0,0,0
  710 REM end of program


P9 Clock


This program uses graphics, sound and text to produce a simple analogue clock on the screen.

COMMANDS

Key in programs and type RUN.
Set clock when requested.

  100 REM Program P9 - Clock
  110  
  120 REM Initialize time
  130 MODE 6
  140 PRINT ''"Enter the time as prompted"
  150 INPUT''"What is the hour",H
  160 INPUT ''"What is the minute",M
  170 INPUT ''"What is the second",S
  180 TIME=0
  190 :
  200 REM Draw face and set colours
  210 MODE 5
  220 VDU 19,0,5;0;
  230 R=400:A=0
  240  
  250 REM Draw clock
  260 GCOL 0,2
  270 MOVE 0,0:MOVE 639,511:PLOT 85,1240,0
  280 MOVE R+639,511
  290 GCOL 0,1
  300 REPEAT
  310   MOVE 639,511
  320   PLOT 85,R*COS(A)+639,R*SIN(A)+511
  330   A=A+.1
  340   PLOT 85,R*COS(A)+639,R*SIN(A)+511
  350   A=A+.1
  360 UNTIL A>2*PI+.01
  370  
  380 REM Plot hour markers
  390 GCOL 0,0
  400 FOR I=1 TO 12
  410   P1=350*COS(RAD(30*I))+639
  420   P2=350*SIN(RAD(30*I))+511
  430   Q1=380*COS(RAD(30*I))+639
  440   Q2=380*SIN(RAD(30*I))+511
  450   MOVEP1,P2:DRAW Q1,Q2
  460 NEXT I
  470  
  480  
  490 REM Adjust time settings
  500 S=S+(TIME DIV 100) MOD 60
  510 M=M+(TIME DIV 6000)MOD 60
  520 H=H+(TIME DIV 36000) MOD 12
  530  
  540 REM Scale for clock: -46 is 12 o'clock
  550 H=(92-30*H-M/2)*2
  560 M=-46-M
  570 S=-46-S
  580  
  590  
  600 REM Sweep second hand
  610 VDU 29,639;511;
  620 M=M+1
  630 PROCminute
  640 REPEAT
  650   TIME=0
  660   GCOL 0,1
  670   X=COS(RAD(6*(S+1))):Y=SIN(RAD(6*(S+1)))
  680   MOVE 300*X,300*Y
  690   DRAW 340*X,340*Y
  700   GCOL 0,3
  710   SOUND 1,-10,100,1
  720   X=COS(RAD(6*S)):Y=SIN(RAD(6*S))
  730   MOVE 300*X,300*Y
  740   DRAW 340*X,340*Y
  750   S=(S-1) MOD 60
  760   IF S=-57 THEN PROCminute
  770   PROCwait
  780 UNTIL 0
  790 END
  800  
  810 DEF PROCminute
  820 GCOL 0,1
  830 MOVE 0,0
  840 DRAW 300*COS(RAD(6*(M+1))),300*SIN(RAD(6*(M+1)))
  850 MOVE 0,0
  860 GCOL 0,3
  870 DRAW 300*COS(RAD(6*M)),300*SIN(RAD(6*M))
  880 M=(M-1) MOD 60
  890 GCOL 0,1
  900 MOVE 0,0
  910 DRAW 200*COS(RAD((H+1)/2)),200*SIN(RAD((H+1)/2))
  920 MOVE 0,0
  930 GCOL 0,3
  940 DRAW 200*COS(RAD(H/2)),200*SIN(RAD(H/2))
  950 H=(H-1) MOD 720
  960 ENDPROC
  970  
  980 DEF PROCwait
  990 REPEAT:UNTIL TIME=100
 1000 ENDPROC