Sure. Its easy. Physics isnt a mess at all. All you need to do this is an integrator and a constraint system. I'm suprised it took as much as 280 lines. Especially since the balls dont even have collisions. and its 2d...
The only time physics is a mess is when you factor in stuff like relativity, quantum mechanics, and string theory.
Started coding this 4:40 PM (now its 5:20 PM) so, a 40 minute job
Graphics 640,480,32,2
ov.verlet=New verlet
ov\x=20
ov\y=20
ov\ox=20+Rnd(-2,2)
ov\oy=20+Rnd(-2,2)
For i=1 To 10
v.verlet=New verlet
v\x=i*40+40
v\y=40
v\ox=i*40+40+Rnd(-2,2)
v\oy=40+Rnd(-2,2)
v\size=20
c.constraint=New constraint
c\Head=ov
c\Tail=v
c\Length=40
ov=v
Next
SetBuffer BackBuffer()
While Not KeyHit(1)
Update
Draw
If MouseDown(1) Then
If selection.verlet<>Null Then
selection\x=(selection\x+MouseX())/2
selection\y=(selection\y+MouseY())/2
Else
For v.verlet=Each verlet
If MouseX()>v\x-v\size Then
If MouseX()<v\x+v\size Then ;optimized bounding box check first
If MouseY()>v\y-v\size Then
If MouseY()<v\y+v\size Then
If Sqr((MouseX()-v\x)*(MouseX()-v\x)+(MouseY()-v\y)*(MouseY()-v\y))<v\size Then
selection=v
Goto skipNull
EndIf
EndIf
EndIf
EndIf
EndIf
Next
selection=Null
.skipnull
EndIf
Else
selection=Null
EndIf
Flip
Cls
Wend
Type Verlet
Field x#, y#, ox#, oy#, size
End Type
Type Constraint
Field Head.Verlet, Tail.Verlet, Length
End Type
Function Update()
For v.Verlet=Each Verlet
tx#=v\x
ty#=v\y
v\x=v\x+.99*(v\x-v\ox)
v\y=v\y+.99*(v\y-v\oy)+.1
If v\x>GraphicsWidth()-v\size Then v\x=GraphicsWidth()-v\size ElseIf v\x<v\size Then v\x=v\size
If v\y>GraphicsHeight()-v\size Then v\y=GraphicsHeight()-v\size ElseIf v\y<v\size Then v\y=v\size
v\ox=tx
v\oy=ty
Next
For i=0 To 10 ;Iterate
For c.Constraint=Each Constraint
dx#=c\Tail\x-c\Head\x
dy#=c\Tail\y-c\Head\y
dl#=Sqr(dx*dx+dy*dy)
d#=(dl-c\length)/Float(dl)
dx#=dx/2
dy#=dy/2
c\Head\x=c\Head\x+d*dx
c\Head\y=c\Head\y+d*dy
c\Tail\x=c\Tail\x-d*dx
c\Tail\y=c\Tail\y-d*dy ;Simple, optimized rigid constraint algo
Next
Next
End Function
Function Draw()
For v.verlet=Each verlet
Oval v\x-v\size,v\y-v\size,v\size Shl 1,v\size Shl 1
Next
End Function
This system can actually mimic any physical structure in 2 dimensions. Just 94 lines. I would add ball-ball collision, but im too lazy, and have only met your challenge. Done this before in 3d, and it was pretty simple. Same stuff actually except for collisions.