2008年9月20日土曜日

ベジェ曲線


#module
#deffunc Beziers int x1,int y1,int x2, int y2, int x3 ,int y3,int x4,int y4,double rate
t=0.0
line x1,y1,x1,y1
repeat
x=(1.0-t)*(1.0-t)*(1.0-t)*x1+3.0*(1.0-t)*(1.0-t)*t*x2+3.0*(1.0-t)*t*t*x3+t*t*t*x4
y=(1.0-t)*(1.0-t)*(1.0-t)*y1+3.0*(1.0-t)*(1.0-t)*t*y2+3.0*(1.0-t)*t*t*y3+t*t*t*y4
line x,y
t+=rate
if t>1:break
loop
line x4,y4
line x4,y4,x4,y4
return
#global

k=4
f=4

onclick gosub *click

x(0)=300:y(0)=300
x(1)=300:y(1)=100
x(2)=100:y(2)=300
x(3)=100:y(3)=100

gosub *draw

stop
*click
i=0
repeat 4
if x(i)-k< mousex&&mousex< x(i)+k&&y(i)-k< mousey&&mousey< y(i)+k{
repeat
x(i)=mousex
y(i)=mousey
gosub *draw
getkey key,1
if key=0:break
wait 0
loop
}
i+
loop
return
*draw
redraw 0
color 255,255,255
boxf

color 192,192,255
line x(0),y(0),x(1),y(1)
line x(2),y(2),x(3),y(3)
color 0,0,0

Beziers x(0),y(0),x(1),y(1),x(2),y(2),x(3),y(3),0.01

color 255,,
circle x(0)-f,y(0)-f,x(0)+f,y(0)+f,0
circle x(3)-f,y(3)-f,x(3)+f,y(3)+f,0

color ,,255
circle x(1)-f,y(1)-f,x(1)+f,y(1)+f,0
circle x(2)-f,y(2)-f,x(2)+f,y(2)+f,0
redraw 1
return

0 件のコメント: