10-07-2024, 08:13 PM
Code: (Select All)
dim shared as integer sw, sh, mx, my, mb, mw
sw = 800
sh = 600
screen _newimage(sw, sh, 32)
img = _newimage(sw, sh, 32)
if _resize then
sw = _resizewidth - 20
sh = _resizeheight - 20
screen _newimage(sw, sh, 32)
img = _newimage(sw, sh, 32)
end if
_dest img
for y=0 to sh
for x=0 to sw
c = 100+10*rnd
pset (x, y), _rgb(c,c,c)
next
next
_dest 0
n = 14
dim x(n), y(n)
for i=0 to n-1
x(i) = sw/2
y(i) = i*sh/n
next
r = 14
mw = r
do
_putimage , img
getmouse
r = mw
x(0) = mx
y(0) = my
for i=1 to n-1
if ((x(i - 1) - x(i))^2 + (y(i - 1) - y(i))^2) > r*r then
a = _atan2(y(i - 1) - y(i), x(i - 1) - x(i)) - pi
x(i) = x(i - 1) + r*cos(a)
y(i) = y(i - 1) + r*sin(a)
end if
next
'preset (x(0), y(0))
'for i=0 to n - 1
' line -(x(i), y(i)), _rgb(55,55,0)
' circle (x(i), y(i)), 3, _rgb(255,255,0)
'next
preset (x(0), y(0))
ox = x(0)
oy = y(0)
dt = 0.001
for t=0 to 1 step dt
bx = 0
by = 0
'dx = 0
'dy = 0
for i=0 to n - 1
bin = 1
for j=1 to i
bin = bin*(n - j)/j
next
p = bin*((1 - t)^(n - 1 - i))*(t^i)
bx = bx + p*x(i)
by = by + p*y(i)
'q = bin*((1 - t)^(n - 2 - i))*(t^(i - 1))*(i - n*t + t)
'dx = dx + q*x(i)
'dy = dy + q*y(i)
next
if abs(bx - ox)>1 and abs(by - oy)>1 then
line -(bx, by), _rgb(255,0,0)
ox = bx
oy = by
end if
'm = sqr(dx*dx + dy*dy)
'line -step(10*dx/m, 10*dy/m), _rgb(0,255,0)
next
line -(bx, by), _rgb(255,0,0)
if _mousebutton(1) then
_dest img
'do while mb = 1
'getmouse
dt = 0.01
for t=0 to 1 step dt
bx = 0
by = 0
'dx = 0
'dy = 0
for i=0 to n - 1
bin = 1
for j=1 to i
bin = bin*(n - j)/j
next
p = bin*((1 - t)^(n - 1 - i))*(t^i)
bx = bx + p*x(i)
by = by + p*y(i)
'q = bin*((1 - t)^(n - 2 - i))*(t^(i - 1))*(i - n*t + t)
'dx = dx + q*x(i)
'dy = dy + q*y(i)
next
rr = 2*exp(-10*t*t)
circle (bx, by), rr, _rgba(155,0,35,70)
next
'loop
_dest 0
end if
_display
_limit 60
loop until _keyhit = 27
system
sub getmouse()
do
mx = _mousex
my = _mousey
mb = _mousebutton(1)
'mw = mw - _mousewheel
loop while _mouseinput
end sub