simply adapted quick and dirty from one Python (I guess) sample from that excellent page: https://pomax.github.io/bezierinfo/
Code: Select all
type XY
as single _x
as single _y
end type
'the last point of the array will be totally ignored
dim as XY points(7)
points(0)._x = 10 : points(0)._y = 10
points(1)._x = 80 : points(1)._y = 40
points(2)._x = 40 : points(2)._y = 190
points(3)._x = 190 : points(3)._y = 50
points(4)._x = 100 : points(4)._y = 170
points(5)._x = 180 : points(5)._y = 170
points(6)._x = 100 : points(6)._y = 0
points(7)._x = 0 : points(7)._y = 0
function drawCurve(points() as XY, byval t as single) as integer
dim as XY newpoints(lBound(points) to uBound(points))
for index as integer = lBound(points) to uBound(points)
newpoints(index) = points(index)
next index
'
if (uBound(points) - lBound(points) + 1)=1 then
circle (points(0)._x, points(0)._y), 4
else
redim preserve newpoints(lBound(points) to uBound(points) - 1)
for index as integer = lBound(newpoints) to uBound(newpoints) - 1
var x = (1-t) * points(index)._x + t * points(index + 1)._x
var y = (1-t) * points(index)._y + t * points(index + 1)._y
newpoints(index) = type(x,y)
next
drawCurve(newpoints(), t)
end if
end function
screenRes 400,400,32
line (points(0)._x, points(0)._y)-(points(1)._x, points(1)._y), rgb(255,0,0)
draw string (points(0)._x, points(0)._y), "0"
line (points(1)._x, points(1)._y)-(points(2)._x, points(2)._y), rgb(255,0,0)
draw string (points(1)._x, points(1)._y), "1"
line (points(2)._x, points(2)._y)-(points(3)._x, points(3)._y), rgb(255,0,0)
draw string (points(2)._x, points(2)._y), "2"
line (points(3)._x, points(3)._y)-(points(4)._x, points(4)._y), rgb(255,0,0)
draw string (points(3)._x, points(3)._y), "3"
line (points(4)._x, points(4)._y)-(points(5)._x, points(5)._y), rgb(255,0,0)
draw string (points(4)._x, points(4)._y), "4"
line (points(5)._x, points(5)._y)-(points(6)._x, points(6)._y), rgb(255,0,0)
draw string (points(5)._x, points(5)._y), "5"
line (points(6)._x, points(6)._y)-(points(7)._x, points(7)._y), rgb(255,0,0)
draw string (points(6)._x, points(6)._y), "6"
for t as single = 0 to 1 step .01
drawCurve(points(), t)
next t
getKey()
'(eof)