for z as integer=1 to 10 p(z)=type<points>(rnd*799,rnd*599,rnd*799,rnd*599)next z

dim as integer max,min var b1=rnd>.5for y as integer=0 to 599 for x as integer=0 to 799 min=1000:max=-1000 for n as integer=1 to 10 var d=segdist(p(n).x1,p(n).y1,p(n).x2,p(n).y2,x,y) if max<d then max=d if min>d then min=d next n max=max/2 var r=map(0,max,min,0,255),g=map(0,max,r,255,0),b=map(0,max,g,0,255) if b1 then swap r,b pset (x,y),rgb(abs(r),abs(g),abs(b)) next xnext ysleep 500loop until inkey=chr(27)sleep

I've got rid of the operators, included the velocities in V2 (dx,dy), used the 2d segment distance (as posted above), in fact the whole thing is now 2D only, which suffices I think.Same shape as in the other thread.Included ball/ball rebounds.

'optimize detection to save cpu.Function DetectBallCollisions(Byref _that As V2,_this As V2) As Single Dim As Single xdiff = _this.x-_that.x Dim As Single ydiff = _this.y-_that.y If Abs(xdiff) > _this.radius*2 Then Return 0 If Abs(ydiff) > _this.radius*2 Then Return 0 var L=Sqr(xdiff*xdiff+ydiff*ydiff) If L<=_this.radius*2 Then Function=LEnd Function

Dim As V2 B(1 To 4) 'four ballsb(1)=Type<V2>(100,200,3,-3,20,Rgb(200,0,0))b(2)=Type<V2>(100,250,-3,3,20,Rgb(0,100,200))b(3)=Type<V2>(200,250,-3,-3,20,Rgb(0,100,0))b(4)=Type<V2>(400,300,1,-1,5,Rgb(0,0,0))Dim As V2 Tmp(1 To 15)Redim As line3d linesegments(1 To 14)

For n As Integer=1 To 15 Read Tmp(n).xNext n

For n As Integer=1 To 15 Read Tmp(n).yNext n

For n As Integer=1 To 13 linesegments(n)=Type<line3d>(Tmp(n).x,Tmp(n).y,Tmp(n+1).x,Tmp(n+1).y)Next n'joins to enclose the shapelinesegments(14).v1x=linesegments(13).v2xlinesegments(14).v1y=linesegments(13).v2ylinesegments(14).v2x=linesegments(1).v1xlinesegments(14).v2y=linesegments(1).v1y

Function Regulate(Byval MyFps As Long,Byref fps As Long) As Long Static As Double timervalue,_lastsleeptime,t3,frames Var t=Timer frames+=1 If (t-t3)>=1 Then t3=t:fps=frames:frames=0 Var sleeptime=_lastsleeptime+((1/myfps)-T+timervalue)*1000 If sleeptime<1 Then sleeptime=1 _lastsleeptime=sleeptime timervalue=T Return sleeptimeEnd Function'background imageDim As Any Ptr im=imagecreate(800,600)Dim As Integer max,minFor y As Integer=0 To 599 For x As Integer=0 To 799 min=10000:max=0 For n As Integer=1 To 18 var d=segment_distance(Linesegments(n).v1x,Linesegments(n).v1y,Linesegments(n).v2x,Linesegments(n).v2y,x,y) If max<d Then max=d If min>d Then min=d Next n max=max/3 var r=map(0,max,min,0,255),g=map(0,max,r,255,0),b=map(0,max,g,00,255) If r=0 Then g=100:b=0:r=255 Pset (x,y),Rgb(r,g,b) Next xNext yGet(0,0)-(799,599),im