Bezier

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
qwws
Prole
Posts: 10
Joined: Fri Aug 25, 2023 11:40 am
Location: Guangdong Province,China

Bezier

Post 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
Attachments
bezier-0.1-2.lua
(2.51 KiB) Downloaded 1789 times
Last edited by qwws on Thu Aug 29, 2024 2:36 pm, edited 3 times in total.
::Hello::
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Bezier

Post 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?
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
qwws
Prole
Posts: 10
Joined: Fri Aug 25, 2023 11:40 am
Location: Guangdong Province,China

Re: Bezier

Post 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
Attachments
bezier-0.1-2.lua
(2.51 KiB) Downloaded 1763 times
Last edited by qwws on Thu Aug 29, 2024 2:36 pm, edited 1 time in total.
::Hello::
User avatar
qwws
Prole
Posts: 10
Joined: Fri Aug 25, 2023 11:40 am
Location: Guangdong Province,China

Re: Bezier

Post 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
::Hello::
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests