Bezier Curves in Corona ** SOURCE CODE

Finally !

Bezier segment manipulation using Corona SDK. This is a sample of how to manipulate a cubic bezier segment. Touch the screen to draw the four points (anchor1,handle1,handle2,anchor2) then manipulate the curve.

I cleaned up the code as much as I could. It is not optimized. Feel free to make changes, amplifications and updates and share with the rest of us.

You can download the code at Bezier Code

I tried it on iOS and Android devices.

Let me know what you think.

You can also find the code on the Code Exchange

Enjoy.

Carlos
[import]uid: 24 topic_id: 4409 reply_id: 304409[/import]

Fixed a performance issue. Download the latest.

Carlos [import]uid: 24 topic_id: 4409 reply_id: 13768[/import]

hi im using the latest version of corona sdk, i have downloaded the code but im getting a blank black screen when i try to open,
[import]uid: 10239 topic_id: 4409 reply_id: 13778[/import]

of course you get a blank screen :smiley: just tap the screen and play the red dot :smiley: [import]uid: 7427 topic_id: 4409 reply_id: 13780[/import]

This is excellent! (code and timing)
I’ve got a character in an animation flying a kite (with accelerometer) now I’ve got the kiteString too.
Now, if we can just talk Jonathan Beebe into making an OpenSource “Cut the Rope” clone :^)

Andy [import]uid: 5339 topic_id: 4409 reply_id: 13787[/import]

well, that sounds great :smiley: [import]uid: 7427 topic_id: 4409 reply_id: 13788[/import]

Faster version uploaded !

c. [import]uid: 24 topic_id: 4409 reply_id: 14065[/import]

OK. Sorry but this is pretty mind blowing to me. Are you telling me that I can somehow manipulate your code to create curves with body and have say a ball slide down that awesome bezier curve? [import]uid: 8192 topic_id: 4409 reply_id: 14639[/import]

Yes

Have you seen a video where I have a tank following the curve?

http://www.youtube.com/watch?v=722su8kVYW4&feature=related

c [import]uid: 24 topic_id: 4409 reply_id: 14699[/import]

Hi Carlos,

I’m really impressed by your bezier code, but I’d like to know how you got the tank to smoothly follow the curve. Obviously, you’re not using the physics engine, but I’m having a little trouble getting the same effect.

Thanks,

Matt. [import]uid: 8271 topic_id: 4409 reply_id: 14869[/import]

Pseudo code would be something like this

Set the tolerance to an acceptable level
Get the points to the curve
Walk the points and as you walk them get the angle between the points
move the object along the points and rotate it given the angle

C [import]uid: 24 topic_id: 4409 reply_id: 15070[/import]

Yep, I got that much, however the flip between, say, 5 degrees and 355 degrees causes the tank to spin a full circle on the spot. I was wondering how you got round this? I did myself, but was wondering about other approaches…

Matt [import]uid: 8271 topic_id: 4409 reply_id: 15079[/import]

local angle = math.atan2(y-x)
angle = angle * 180 / PI (3.1415196)

object:rotate (angle-prevAngle)

prevAngle = angle;

Carlos

[import]uid: 24 topic_id: 4409 reply_id: 15085[/import]

Thanks Carlos…

My bad - I think I assumed certain things. The problem I referred to comes from transition.to (which I used for smooth animation from one angle to the next) tweening between 355 and 5 degrees through the larger range around the circle’s 360, not directly through the 360|0 border…

That, of course, is to simply check the difference and add/subtract 360 where appropriate.

m [import]uid: 8271 topic_id: 4409 reply_id: 15089[/import]

xcellent

post video of such animation when you have it available… would b great to see it

carlos [import]uid: 24 topic_id: 4409 reply_id: 15091[/import]

Not wishing to go off topic, but can you recommend something to take videos of the simulator screen?

matt
[import]uid: 8271 topic_id: 4409 reply_id: 15092[/import]

thats offtopic so no i won’t go there…

:wink:

I use screenflow http://www.telestream.net/screen-flow/overview.htm

there is a thread somewhere in the forum for other alternatives… but i like screenflow a lot but that is my preference :wink:

c. [import]uid: 24 topic_id: 4409 reply_id: 15093[/import]

Why isn’t this encapsulated into a useful module? [import]uid: 4596 topic_id: 4409 reply_id: 34514[/import]