10-07-2024, 08:11 AM
hair
Code: (Select All)
defdbl a-z
dim shared as integer sw, sh, mx, my, mb, mw
pi = 4*atn(1)
sw = 800
sh = 600
screen _newimage(sw, sh, 32)
n = 15
dim x(n), y(n)
for i=0 to n-1
x(i) = sw/2
y(i) = i*sh/n
next
r = 35
mw = r
do
cls
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))
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)
_display
_limit 30
loop until _keyhit = 27
system
sub getmouse()
do
mx = _mousex
my = _mousey
mb = _mousebutton(1)
mw = mw - _mousewheel
loop while _mouseinput
end sub