Don't worry too much about optimizing the code; even if you go out of your way to do all of the usual CBM BASIC optimizations, you'll only get a small boost at the cost of making the code unreadable:
(I was having a bit of fun with the code after I posted my initial fixes, and this was one of the things I tried

)
Code: Select all
10 SCREEN 128
20 RECT 0,0,319,239,16
30 NB = 2: REM NUMBER OF SHAPES ON SCREEN
35 NC = 4: REM NUMBER OF CORNERS FOR THE SHAPES
40 BD = 8: REM DEPTH TO DRAW BEFORE STARTING ERASURE
45 YL = 238
50 XL = 318
110 P1 = 1 : REM CURRENT BOX
120 P2 = 1 : REM PREVIOUS BUFFER POSITION
130 P3 = 2 : REM CURRENT BUFFER POSITION
140 P4 = 0 : REM CURRENT COLOR
150 X1 = 0: X2 = 0: X3 = 0
160 Y1 = 0: Y2 = 0: Y3 = 0
170 DIM BX(NB,BD, NC) : REM CORNER X COORDINATES
180 DIM BY(NB,BD, NC) : REM CORNER Y COORDINATES
190 DIM XI(NB, NC) : REM X INCREMENT
200 DIM YI(NB, NC) : REM Y INCREMENT
210 DIM BC(NB) : REM COLOR OF THE BOX
300 GOSUB 6000
400 FOR P1=1 TO NB
410 X2=BX(P1,P3,NC):Y2=BY(P1,P3,NC)
420 FOR C=1 TO NC
430 X1=X2:X2=BX(P1,P3,C):Y1=Y2:Y2=BY(P1,P3,C)
440 LINE X1,Y1,X2,Y2,16
450 X3=BX(P1,P2,C)+XI(P1,C):Y3=BY(P1,P2,C)+YI(P1,C)
460 IF X3>XL THEN XI(P1,C)=-INT((RND(1)*5)+1):X3=XL
470 IF X3<0 THEN XI(P1,C)=INT(RND(1)*5)+1:X3=0
480 IF Y3>YL THEN YI(P1,C)=-INT((RND(1)*5)+1):Y3=YL
490 IF Y3<0 THEN YI(P1,C)=INT(RND(1)*5)+1:Y3=0
500 BX(P1,P3,C)=X3:BY(P1,P3,C)=Y3
510 NEXT
520 X2=X3:Y2=Y3:P4=BC(P1)
530 FOR C=1 TO NC
540 X1=X2:X2=BX(P1,P3,C):Y1=Y2:Y2=BY(P1,P3,C)
550 LINE X1,Y1,X2,Y2,P4
560 NEXT:NEXT
570 P2=P3:P3=P3+1:IF P3>BD THEN P3=1
580 GOTO 400
5999 REM SETUP VARIABLES
6000 X = INT(RND(-TI))
6005 FOR B = 1 TO NB
6010 BC(B) = INT(RND(1)*255)+1
6020 IF BC(B)=0 OR BC(B)=16 THEN GOTO 6010
6040 FOR C = 1 TO NC
6050 XI(B,C) = INT(RND(1)*5)+1
6060 IF (INT(RND(1)*20)+1) > 10 THEN XI(B,C)= -XI(B,C)
6070 YI(B,C) = INT(RND(1)*5)+1
6080 IF (INT(RND(1)*20)+1) > 10 THEN YI(B,C)= -XI(B,C)
6090 BX(B,1,C) = INT(RND(1)*319) + 1
6100 BY(B,1,C) = INT(RND(1)*239) + 1
6110 NEXT C
6120 NEXT B
6130 RETURN
...so I don't think it's worthwhile.
