I played around with it! This version doesn't need a2D and runs on both DBP and DBC:
set window on
set display mode 800,600,32
set window size 840,640
set window position 100,20
set text opaque
hide mouse
sync on
sync rate 0
w = screen width()
h = screen height()
r = 5
a = 500
dim x#(a)
dim y#(a)
dim z#(a)
dim s#(a)
dim xv#(a,a)
dim yv#(a,a)
dim c#(a)
for i = 1 to a
x#(i) = rnd(w)
y#(i) = rnd(h)
c#(i) = 255
next i
grav# = -1.3
rep = 3310
renmode = 0
dim renmode$(2)
renmode$(0) = "Dots"
renmode$(1) = "Boxes"
renmode$(2) = "Circles"
rendmax = 1
rend=1
syncrate = 60
texth = 16
do
rem change draw mode (circles, boxes or dots)
oldmc = newmc
newmc = mouseclick()
inc renmode, (newmc > oldmc)
if renmode > 2 then renmode = 0
rem render manager {
oldfps = fps
fps = screen fps()
if abs(fps-syncrate)>2 then rendset=0
if rendset = 0
if abs(fps-syncrate)<3 then rendset=1
if fps > syncrate and abs(oldfps-fps)<5 then inc rendmax
if fps=oldfps and fps<syncrate then dec rendmax
if rendmax < 1 then rendmax = 1
rend = rendmax * .1
endif
`}
tx# = mousex()
ty# = mousey()
inc rep, (upkey()-downkey())*100
dec grav#, (rightkey()-leftkey())*0.1
for i = 1 to rend
ink 257*c#(i),0
x = int(x#(i))
y = int(y#(i))
select renmode
case 2 : fcircle(x,y,r) : endcase
case 1 : box x-r,y-r,x+r,y+r : endcase
case default : dot x,y : endcase
endselect
z# = atanfull(x#(i)-tx#,y#(i)-ty#)
x#(i) = newxvalue(x#(i),z#,grav#)
y#(i) = newzvalue(y#(i),z#,grav#)
next i
for i = 0 to rend
gosub _room
gosub _closeones
next i
ink -2,0
circle tx#,ty#,10
y=0
text 0,y, "Sync Rate: " + str$(syncrate) + ", " + "FPS: " + str$(fps) + " [Render Fixed = " + str$(rendset) + "]" : inc y,texth
text 0,y, "Particles rendered: " + str$(rendmax/10.0) : inc y,texth
text 0,y, "Render Mode: " + renmode$(renmode) : inc y,texth
inc y,texth
text 0,y, "Press up/down to inc/dec repulsive force. -- force =" +str$(rep) : inc y,texth
text 0,y, "Press left/right to inc/dec mouse gravity. -- gravity = "+str$(0-grav#) : inc y,texth
text 0,y, "Click the mouse to change render mode." : inc y,texth
sync
cls 0
loop
rem +++ subroutines +++
_closeones:
for cl = 0 to rend
v = 0
xv# = 0
yv# = 0
if cl <> i
arg# = ( x#(i) - x#(cl) )^2 + ( y#(i) - y#(cl) )^2
dist# = (arg#>100)*arg# + (arg#<100)*100
if dist# < rep
inc v
tz# = atanfull(x#(i)-x#(cl),y#(i)-y#(cl))
xv#(i,v) = newxvalue(x#(i),tz#,rep/dist#)
yv#(i,v) = newzvalue(y#(i),tz#,rep/dist#)
endif
for cl2 = 1 to v
inc xv#,xv#(i,cl2)
inc yv#,yv#(i,cl2)
next cl2
if v > 0
x#(i) = xv#/v
y#(i) = yv#/v
` c#(i) = arg#
` c#(i) = 255
endif
endif
next cl
return
`//
_room:
if x#(i) < r then x#(i) = r
if x#(i) > w-r then x#(i) = w-r
if y#(i) < r then y#(i) = r
if y#(i) > h-r then y#(i) = h-r
return
`//
rem +++ functions +++
rem obese87's filled circle
function fcircle(x,y,r)
points# = r * 6.28
t# = 360 / points#
quarter = points# / 4
for i = 1 to quarter
u = sin(i * t#) * r
v = cos(i * t#) * r
box x-u, y-v, x+u, y+v
next i
endfunction
`//
Since performance can be wildly different between DBC and DBP (and different computers) I added a crude "render manager" (as I called it) to manage the number of particles drawn and maintain a healthy FPS.
Turn the gravity up and things get
weird. at around 30-50 it looks like an atom, then at about 300 there's a magnetic field effect, then at 1100 everything is pushed to the sides with the odd "bolt" shooting inwards, and it crashed at 1500 with a divide by zero error. I have a feeling that the secret of the universe is at 1500.
Shh... you're pretty.