Page 1 of 1

Bezier

Posted: Tue Aug 27, 2024 10:55 am
by qwws
This is a bezier function where you can get a bezier of any order
https://github.com/qwwshs/lua_bezier
example:
bez = require "bezier"
print(bez:GetBezier(0,1,0,1,0.5,{0,0,1,1,1,1}))

function love.load()

end

function love.draw()
for i=0,1,0.001 do
local int = bez:GetBezier(0,1,0,1,i,{0,0,1,1})
love.graphics.rectangle("fill",i*300,int*300,1,1)
end
end

Re: Bezier

Posted: Tue Aug 27, 2024 3:27 pm
by darkfrei
qwws wrote: Tue Aug 27, 2024 10:55 am This is a bezier function where you can get a bezier of any order
https://github.com/qwwshs/lua_bezier
example:

Code: Select all

bez = require "bezier"
print(bez:GetBezier(0,1,0,1,0.5,{0,0,1,1,1,1}))

function love.draw()
	for i=0,1,0.001 do
		local int = bez:GetBezier(0,1,0,1,i,{0,0,1,1,1,1,1,1,0.5,0.5}) 
		love.graphics.rectangle("fill",i*300,int*300,1,1)
	end
end
Must be:

Code: Select all

local m = 1000
for n = 0, m do -- range n = [0, 1000]
	local k = n/m -- range k = [0, 1]
end
Your code makes range [0, 1): the last number is 0.999, not 1.0.

Why your code is better than https://love2d.org/wiki/BezierCurve:render or https://love2d.org/wiki/BezierCurve:evaluate?

Re: Bezier

Posted: Tue Aug 27, 2024 3:40 pm
by qwws
darkfrei wrote: Tue Aug 27, 2024 3:27 pm
qwws wrote: Tue Aug 27, 2024 10:55 am This is a bezier function where you can get a bezier of any order
https://github.com/qwwshs/lua_bezier
example:

Code: Select all

bez = require "bezier"
print(bez:GetBezier(0,1,0,1,0.5,{0,0,1,1,1,1}))

function love.draw()
	for i=0,1,0.001 do
		local int = bez:GetBezier(0,1,0,1,i,{0,0,1,1,1,1,1,1,0.5,0.5}) 
		love.graphics.rectangle("fill",i*300,int*300,1,1)
	end
end
Must be:

Code: Select all

local m = 1000
for n = 0, m do -- range n = [0, 1000]
	local k = n/m -- range k = [0, 1]
end
Your code makes range [0, 1): the last number is 0.999, not 1.0.

Why your code is better than https://love2d.org/wiki/BezierCurve:render or https://love2d.org/wiki/BezierCurve:evaluate?
Fixed

Re: Bezier

Posted: Tue Aug 27, 2024 3:42 pm
by qwws
darkfrei wrote: Tue Aug 27, 2024 3:27 pm
qwws wrote: Tue Aug 27, 2024 10:55 am This is a bezier function where you can get a bezier of any order
https://github.com/qwwshs/lua_bezier
example:

Code: Select all

bez = require "bezier"
print(bez:GetBezier(0,1,0,1,0.5,{0,0,1,1,1,1}))

function love.draw()
	for i=0,1,0.001 do
		local int = bez:GetBezier(0,1,0,1,i,{0,0,1,1,1,1,1,1,0.5,0.5}) 
		love.graphics.rectangle("fill",i*300,int*300,1,1)
	end
end
Must be:

Code: Select all

local m = 1000
for n = 0, m do -- range n = [0, 1000]
	local k = n/m -- range k = [0, 1]
end
Your code makes range [0, 1): the last number is 0.999, not 1.0.

Why your code is better than https://love2d.org/wiki/BezierCurve:render or https://love2d.org/wiki/BezierCurve:evaluate?
I don't know much about the code for love2d...
but maybe it's the dichotomy that is used