setscreen ("graphics:max;max,offscreenonly;nobuttonbar")
colourback (black)
type Node :
record
x, y, vx, vy : real
col : int
end record
const N := 100
const d := 8
var nodes : array 1 .. N of Node
fcn calcCol (inI : int) : int
result 16 + inI div (N div 12)
end calcCol
for i : 1 .. N
nodes (i).x := Rand.Int (1, maxx)
nodes (i).y := Rand.Int (1, maxy)
nodes (i).vx := 0
nodes (i).vy := 0
nodes (i).col := 30 + (16 - calcCol (i))
end for
var F : real
type mouse :
record
mx, my, mb, mcue : int
motion : string
end record
var _m : mouse
_m.motion := "down"
function whatAngle (dx, dy : real) : real
var ratio, angle : real
if abs (dx) > 0.0000001 then
ratio := dy / dx
else
ratio := dy / 0.000001
end if
angle := arctand (abs (ratio))
if dx < 0 then
angle := 180 - angle
end if
if dy < 0 then
angle := 360 - angle
end if
result angle
end whatAngle
loop
Mouse.Where (_m.mx, _m.my, _m.mb)
if Mouse.ButtonMoved (_m.motion) then
Mouse.ButtonWait (_m.motion, _m.mx, _m.my, _m.mb, _m.mcue)
for i : 1 .. upper (nodes)
nodes (i).x := Rand.Int (1, maxx)
nodes (i).y := Rand.Int (1, maxy)
end for
end if
for decreasing i : N .. 1
if i = 1 then
F := - (Math.Distance (_m.mx, _m.my, nodes (i).x, nodes (i).y) - d)
nodes (i).vx := cosd (whatAngle (nodes (i).x - _m.mx, nodes (i).y - _m.my)) * F
nodes (i).vy := sind (whatAngle (nodes (i).x - _m.mx, nodes (i).y - _m.my)) * F
else
F := - (Math.Distance (nodes (i - 1).x, nodes (i - 1).y, nodes (i).x, nodes (i).y) - d)
nodes (i).vx := cosd (whatAngle (nodes (i).x - nodes (i - 1).x, nodes (i).y - nodes (i - 1).y)) * F
nodes (i).vy := sind (whatAngle (nodes (i).x - nodes (i - 1).x, nodes (i).y - nodes (i - 1).y)) * F
end if
nodes (i).x += nodes (i).vx
nodes (i).y := max (0, nodes (i).y + nodes (i).vy)
if i = 1 then
%Draw.ThickLine (mx, my, nodes (i).x div 1, nodes (i).y div 1, 2, black)
else
%Draw.ThickLine (nodes (i).x div 1, nodes (i).y div 1, nodes (i - 1).x div 1, nodes (i - 1).y div 1, 2, black)
end if
drawoval (nodes (i).x div 1, nodes (i).y div 1, d div 2, d div 2, nodes (i).col)
end for
Time.DelaySinceLast (10)
View.Update
cls
exit when hasch
end loop
|