Code: Select all
Structure metacircle
x.f
y.f
vx.f
vy.f
r.f
EndStructure
Global Dim metacircles.metacircle(0)
Global gNumCircles
Macro RRandom(min,max)
Random((max-min),0) + min
EndMacro
Procedure Init(NumCirles,size)
gNumCircles = NumCirles
ReDim metacircles.metacircle(NumCirles)
For i = 0 To NumCirles-1
metacircles(i)\x = RRandom(0, size)
metacircles(i)\y = RRandom(0, size)
metacircles(i)\r = RRandom(10, 60)
metacircles(i)\vx = RRandom(-2, 2)
metacircles(i)\vy = RRandom(-2, 2)
Next
EndProcedure
Procedure draw(size,width)
Protected *c.metacircle,dx.f,dy.f,sum.f,dd.f
If gNumCircles
For i = 0 To gNumCircles-1 ;move and keep in bounds
*c = @metacircles(i)
*c\x + *c\vx
*c\y + *c\vy
If *c\x - *c\r <= 0
*c\vx = Abs(*c\vx)
EndIf
If *c\x + *c\r >= width
*c\vx = -Abs(*c\vx)
EndIf
If *c\y - *c\r <= 0
*c\vy = Abs(*c\vy)
EndIf
If *c\y + *c\r >= width
*c\vy = -Abs(*c\vy);
EndIf
Next
While x < Width ;plot
y=0
While y < Width
sum = 0
For i = 0 To gNumCircles -1
*c = metacircles(i)
dx = x - *c\x
dy = y - *c\y
dd = dx * dx + dy * dy
sum + (*c\r * *c\r / dd)
Next
If sum > 1
Plot(x,y,RGB(0,255,0))
EndIf
y+size
Wend
x+size
Wend
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 420, 420, "left click for new metacircles", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 400, 400)
AddWindowTimer(0,1,20)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
If EventType() = #PB_EventType_LeftClick
init(Random(10,3),400)
EndIf
EndIf
If Event = #PB_Event_Timer And EventTimer() = 1
If StartDrawing(CanvasOutput(0))
Box(0,0,400,400,0)
Draw(1,400)
StopDrawing()
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf