Four times more squares than previous.
This will run a little slower.
restore rainbow
read col
dim R(col)
dim G(col)
dim B(col)
dim rgb$(col)
dim number(col)
for a=1 to col
read R(a)
read G(a)
read B(a)
read rgb$(a)
next a
bar=1280
dim rise(bar)
for a=1 to bar
rise(a)=1
next a
sel=660
s=ran(.2)+.4
y=0
sw=0
open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
d=peek("port1")
if d<>1024 ctrl=1
if ctrl=1 ct=ct+1
if ct>2 ct=2
if ct=2 ctrl=0
if d=1024 ct=0
if ctrl=1 sw=sw+1
if sw>1 sw=0
if and(d,8192)>0 then
for a=1 to bar
rise(a)=1
next a
sel=660
s=ran(.2)+.4
endif
if and(d,16)>0 then
for a=1 to bar
rise(a)=rise(a)+1
next a
endif
if and(d,32)>0 then
for a=1 to bar
if sel=a rise(a)=1
next a
endif
z=c
label restart
t=ran(1)
if t<.26 c=0
if t>.25 and t<s c=1
if t>s and t<.76 c=2
if t>.75 c=3
if c-z=2 goto restart
if c-z=-2 goto restart
if z=0 sel=sel-40
if z=1 sel=sel+1
if z=2 sel=sel+40
if z=3 sel=sel-1
if sel<0 sel=sel+1280
if sel>1280 sel=sel-1280
for a=1 to col
number(a)=0
next a
for a=1 to bar
if sel=a rise(a)=rise(a)+1
if rise(a)>16 rise(a)=1
for b=1 to col
if rise(a)=b number(b)=number(b)+1
next b
next a
y=0
for a=1 to bar
x=x+1
if x>40 then
y=y+1
x=1
endif
for b=1 to col
if rise(a)=b setrgb 1,R(b),G(b),B(b)
next b
fill rectangle x*16-15,y*16-15 to x*16,y*16
'setrgb 1,0,0,0
'if sel=a and sw=1 text x*32-30,y*32-12,str$(sel)
'if sel=a and sw=0 then
'fill circle x*32-21,y*32-21,3
'fill circle x*32-11,y*32-21,3
'text x*32-22,y*32-5,"-"
'endif
next a
for a=1 to col
if sw=0 then
setrgb 1,0,0,0
if number(a)<10 space=20
if number(a)>9 and number(a)<100 space=10
if number(a)>99 space=0
text 20+space,a*16+12,str$(number(a))
text 98,a*16+12,rgb$(a)
setrgb 1,R(a),G(a),B(a)
fill rectangle 96,a*16+16 to 81,a*16+1
endif
next a
if sw=0 then
setrgb 1,0,0,0
for a=1 to len(time$)
text (5-1)*10+500,22,mid$(time$,5,1)
next a
text 500,38,time$
text 410,54,date$
text 570,70,str$(sel)
endif
until (1=0)
label rainbow
data 16
data 256,256,256,"white" rem 768
data 152,256,152,"mint" rem 560
data 181,126,220,"lavender" rem 527
data 256,256,000,"yellow" rem 512
data 256,112,112,"pink" rem 480
data 128,128,128,"grey" rem 384
data 079,105,198,"indigo" rem 382
data 002,164,211,"cerulean" rem 377
data 128,224,000,"olive" rem 352
data 256,064,000,"orange" rem 320
data 220,020,060,"crimson" rem 300
data 256,000,000,"red" rem 256
data 000,000,256,"blue" rem 256
data 000,256,000,"green" rem 256
data 128,064,000,"brown" rem 192
data 036,010,064,"violet" rem 110