I fixed up my gravity screen saver and made it into a 20-liner
sync on : sync rate 0 : hide mouse : randomize timer() : NUMBEROFBALLS = rnd(6)+1 : NUMBEROFGRAV = rnd(4)+1 : SCREENWIDTH = Screen Width() : SCREENHEIGHT = Screen Height()
global timer1=0 : global timer2=0 : type balltype
x# as float : y# as float : vx# as float : vy# as float : c1 as integer : c2 as integer : c3 as integer
endtype : type gravtype
x# as float : y# as float : size# as float
endtype : GRAVITY# = 0.1 : FRICTION# = 0.95 : dim ball(NUMBEROFBALLS) as balltype : dim grav(NUMBEROFGRAV) as gravtype : dim dx(NUMBEROFBALLS,40) as float : dim dy(NUMBEROFBALLS,40) as float
for j=1 to NUMBEROFBALLS : ball(j).x# = rnd(SCREENWIDTH-40)+20 : ball(j).y# = rnd(SCREENHEIGHT-40)+20 : ball(j).vx# = 0.0 : ball(j).vy# = 0.0 : ball(j).c1 = 128*rnd(1)+127 : ball(j).c2 = 128*rnd(1)+127
ball(j).c3 = 128*rnd(1)+127 : for i=1 to 40 : dx(j,i) = ball(j).x# : dy(j,i) = ball(j).y# : next i : next j
for j=1 to NUMBEROFGRAV : grav(j).x# = rnd(SCREENWIDTH-100) + 70.0 : grav(j).y# = rnd(SCREENHEIGHT-100) + 70.0 : grav(j).size# = rnd(30) + 10.0 : next j
do : cls : for j=1 to NUMBEROFBALLS : for i=39 to 1 step -1 : dx(j,i+1) = dx(j,i) : dy(j,i+1) = dy(j,i) : next i
for i=1 to NUMBEROFGRAV : dist# = sqrt((ball(j).x#-grav(i).x#)^2 + (ball(j).y#-grav(i).y#)^2) : accel# = (GRAVITY# * grav(i).size#) / dist# : ball(j).vx# = ball(j).vx# + accel#*((grav(i).x#-ball(j).x#)/dist#)
ball(j).vy# = ball(j).vy# + accel#*((grav(i).y#-ball(j).y#)/dist#) : next i : ball(j).vx# = ball(j).vx# * FRICTION# : ball(j).vy# = ball(j).vy# * FRICTION# : ball(j).x# = ball(j).x# + ball(j).vx#
ball(j).y# = ball(j).y# + ball(j).vy# : if ball(j).x#<10.0 : ball(j).x#=10.0 : ball(j).vx# = -ball(j).vx# * FRICTION# : ball(j).vy# = ball(j).vy# * FRICTION# : endif : if ball(j).x#>SCREENWIDTH-10
ball(j).x#=SCREENWIDTH-10 : ball(j).vx# = -ball(j).vx# * FRICTION# : ball(j).vy# = ball(j).vy# * FRICTION# : endif : if ball(j).y#<10.0 : ball(j).y#=10.0 : ball(j).vx# = ball(j).vx# * FRICTION# : ball(j).vy# = -ball(j).vy# * FRICTION# : endif
if ball(j).y#>SCREENHEIGHT-10 : ball(j).y#=SCREENHEIGHT-10 : ball(j).vx# = ball(j).vx# * FRICTION# : ball(j).vy# = -ball(j).vy# * FRICTION# : endif
dx(j,1) = ball(j).x# : dy(j,1) = ball(j).y# : for i=39 to 1 step -1 : ink rgb(pos(ball(j).c1,i*255/40),pos(ball(j).c2, i*255/40),pos(ball(j).c3, i*255/40)),0 : circle dx(j,i+1), dy(j,i+1), 9*(1-(i/40.0)) : next i : ink rgb(ball(j).c1,ball(j).c2,ball(j).c3),0 : circle ball(j).x#, ball(j).y#, 9 : next j
for i=1 to NUMBEROFGRAV : ink rgb(255,255,255),0 : circle grav(i).x#, grav(i).y#, grav(i).size#/2 : next i : sync : loop : end
function pos(value1 as float, value2 as float)
result = value1-value2 : if result<0 then exitfunction 0
endfunction result