As I mentioned in my previous topic, I was going to mess around with learning verlets. I think I've got it, take a look at this little program I've just written:
It simply simulates gravity around a point and an attempt to put some node stuff in there as well. Have a play around with a values, it's kinda fun. :)
EDIT: Note to self: Use more comment lines. ;)
Graphics 1280, 768, 32, 2 SetBuffer BackBuffer() SeedRnd MilliSecs() Const TIMESTEP# = .995 Type dat Field x#, y# Field h#, v# Field oldx#, oldy# Field fric# Field mass# End Type Global p.dat Global temp.dat Type node_dat Field x1#, y1#, x2#, y2# End Type Global node.node_dat For n=0 To 19 p.dat = New dat p\x = Rand(GraphicsWidth()) p\y = Rand(GraphicsHeight()) p\oldx = p\x p\oldy = p\y p\h = Rnd(-1, 1) p\v = Rnd(-1, 1) p\fric = Rnd(.9, 1) p\mass = Rnd(1, 30) Next ; An extra particle for creating a central 'sun', etc. p.dat = New dat p\x = GraphicsWidth() / 2 p\y = GraphicsHeight() / 2 p\oldx = p\x p\oldy = p\y p\h = 0 p\v = 0 p\fric = 0 p\mass = 100 Repeat Cls For p.dat = Each dat p\v = 0 p\h = 0 ; Calculate pull for each particle interaction For temp.dat = Each dat xdiff# = temp\x - p\x ydiff# = temp\y - p\y dist# = Sqr(xdiff * xdiff + ydiff * ydiff) If Abs(dist#) < 100 Then node.node_dat = New node_dat node\x1 = p\x: node\y1 = p\y node\x2 = temp\x: node\y2 = temp\y End If If Abs(dist#) > 0 Then p\h = p\h + (xdiff / dist) / (dist * p\mass / 10) p\v = p\v + (ydiff / dist) / (dist * p\mass / 10) ;p\h = p\h + (xdiff / dist) / p\mass ;p\v = p\v + (ydiff / dist) / p\mass End If Next ; Verlet temp_x# = p\x temp_y# = p\y p\x = p\x + p\x * p\fric - p\oldx * p\fric + p\h * TIMESTEP p\y = p\y + p\y * p\fric - p\oldy * p\fric + p\v * TIMESTEP If p\x < 0 Then p\x = 0 If p\x > GraphicsWidth() Then p\x = GraphicsWidth() If p\y < 0 Then p\y = 0 If p\y > GraphicsHeight() Then p\y = GraphicsHeight() p\oldx = temp_x# p\oldy = temp_y# Next ; Draw node lines Color 32, 32, 64 For node.node_dat = Each node_dat Line node\x1, node\y1, node\x2, node\y2 Delete node Next ; Draw particles For p.dat = Each dat Color 128, 128, 255 radius# = p\mass * .5 Oval p\x - radius, p\y - radius, p\mass, p\mass Next Flip Until KeyHit(1) End
It simply simulates gravity around a point and an attempt to put some node stuff in there as well. Have a play around with a values, it's kinda fun. :)
EDIT: Note to self: Use more comment lines. ;)