Graphics 640,480,0
Repeat
Cls
SetHandle(MouseX(),MouseY())
SetRotation(a)
a:+1
drawbezier(100,100,200,100,300,300,200,300,255,255,255)
Flip
Until KeyHit(key_escape)
Function drawbezier(x1,y1,vx1,vy1,x2,y2,vx2,vy2,r=0,g=0,b=0,drawHandles=False)
SetColor(r,g,b)
If drawHandles=True Then
DrawOval(vx1-2,vy1-2,4,4)
DrawOval(vx2-2,vy2-2,4,4)
DrawLine(x1,y1,vx1,vy1)
DrawLine(x2,y2,vx2,vy2)
End If
Local lastx#=x1
Local lasty#=y1
For t#=0 To 1 Step.01
pointx# = x1*(1-t)^3 + 3*vx1*(1-t)^2*t + 3*vx2*(1-t)*t^2 + x2*t^3
pointy# = y1*(1-t)^3 + 3*vy1*(1-t)^2*t + 3*vy2*(1-t)*t^2 + y2*t^3
DrawLine(pointx#,pointy#,lastx#,lasty#)
lastx#=pointx#
lasty#=pointy#
Next
End Function
Repeat
Cls
SetHandle(MouseX(),MouseY())
SetRotation(a)
a:+1
drawbezier(100,100,200,100,300,300,200,300,255,255,255)
Flip
Until KeyHit(key_escape)
Function drawbezier(x1,y1,vx1,vy1,x2,y2,vx2,vy2,r=0,g=0,b=0,drawHandles=False)
SetColor(r,g,b)
If drawHandles=True Then
DrawOval(vx1-2,vy1-2,4,4)
DrawOval(vx2-2,vy2-2,4,4)
DrawLine(x1,y1,vx1,vy1)
DrawLine(x2,y2,vx2,vy2)
End If
Local lastx#=x1
Local lasty#=y1
For t#=0 To 1 Step.01
pointx# = x1*(1-t)^3 + 3*vx1*(1-t)^2*t + 3*vx2*(1-t)*t^2 + x2*t^3
pointy# = y1*(1-t)^3 + 3*vy1*(1-t)^2*t + 3*vy2*(1-t)*t^2 + y2*t^3
DrawLine(pointx#,pointy#,lastx#,lasty#)
lastx#=pointx#
lasty#=pointy#
Next
End Function