Log In  

@stefvdw

Follow
Follow

Cart [#bezzy-0#] | Code | 2019-07-18 | No License | Embed

Hi guys,

I was working on a train game when it hit me that i have no idea how to make a smooth curve.
So I came across bezier curves and after reading some math articles I managed to write a function myself.
Even though many other people have shared thier version here is my bezier curve, with only a single control point sadly (I will figure out the rest later).

Here is the code i have tried to make it very eazy to implement into other projects (since I was gonna use it for my train haha).


function lv(v1,v2,t)
    return (1-t)*v1+t*v2
end

--Quadratic Bezier Curve Vector
function qbcvector(v1,v2,v3,t) 
    return  lv(lv(v1,v3,t), lv(v3,v2,t),t)
end

--draw Quadratic Bezier Curve
--x1,y1 = starting point 
--x2,y2 = end point
--x3,y3 = 3rd manipulating point 
--n = "amount of pixels in curve"(just put it higher than you expect)
--c = color
function drawqbc(x1,y1,x2,y2,x3,y3,n,c)
    for i = 1,n do 
        local t = i/n
       pset(qbcvector(x1,x2,x3,t),qbcvector(y1,y2,y3,t),c)
    end
end

Cart [#bezzy_cubic-0#] | Code | 2019-07-19 | No License | Embed

update: ive added cubic aswell here is the code:

function lv(v1,v2,t)
    return (1-t)*v1+t*v2
end

--Quadratic Bezier Curve Vector
function qbcvector(v1,v2,v3,t) 
    return  lv(lv(v1,v3,t), lv(v3,v2,t),t)
end

-- cubic bezier curve vector
function cbcvector(v1,v2,v3,v4,t) 
    return  lv(qbcvector(v1,v2,v3,t), qbcvector(v1,v2,v4,t),t)
end
--draw cubic bezier curve
function drawcbc(x1,y1,x2,y2,x3,y3,x4,y4,n,c)
    for i = 1,n do 
        local t = i/n
        pset(cbcvector(x1,x2,x3,x4,t),cbcvector(y1,y2,y3,y4,t),c)
    end
end
P#65926 2019-07-18 20:21 ( Edited 2019-07-19 11:14)

Cart [#boaty-2#] | Code | 2019-06-21 | License: CC4-BY-NC-SA | Embed
1

Hi, I wanted to make a pirate game and I thought it would be cool if there were actual sailing mechanics.
So I decided that I would start with that.
I'm quite happy with the results so far but would no like to add land, birds and also make a bigger ship with some cannons or something.But i think the basics are here.

--controls
left and right - sailing
Z - sail up or down

If you have any suggestions feel free to give them.

P#65326 2019-06-21 16:26 ( Edited 2019-06-21 18:02)

Cart [#space_race-3#] | Code | 2019-02-17 | No License | Embed
2

its gonna be a race

update:I added more sattelites and a cow (very productive I know).
Still thinking about the gameplay, I think I am going to make them be able to bump into eachother and collide with astroids and maybe sattelites aswell. and when they eventually get to the moon. maybe do a moonlander mini-game or something.

P#61474 2019-02-03 00:35 ( Edited 2019-02-17 23:07)

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-11-22 07:01 | 0.075s | 4194k | Q:60