0 Favourites

How can I draw a curved line ?

  • Hi...

    Does anybody know if its possible to draw a curved line in C2 ?

    <img src="http://dl.dropbox.com/u/22173473/drawline.png" border="0" />

    Can the usual method for drawing a line in the following example, be modified to achieve it?

    Mouse left button is down-

    Beam-Set width to distance(start.X, start.Y, Mouse.X, Mouse.Y)

    Thanks in advance

    <img src="smileys/smiley5.gif" border="0" align="middle" />

  • You can with r0j0hound's canvas plugin.

  • Arima   You can with r0j0hound's canvas plugin.

    Thanks....will check it out.

    I was hoping there might be a way to do it without having to

    to use a plugin.

  • Well you can always have a 'cursor' or 'pencil' that creates static duplicates of itself every tick / few milliseconds as it moves, creating a "line". You can then use lerp(),qarp(),or cubic() to move the pencil how you want.

    Maybe not the best idea but if you insist on not using plugins there ya go :P

  • C2 doesn't have qarp or cubic yet.

  • To get a formula for cubic look on the wikipedia page for "bezier curves".

    Here's an implementation:

    http://dl.dropbox.com/u/5426011/examples%208/cubicCurve.capx

    You will get better results with the canvas plugin though, which won't have breaks in the curve.

  • Tokinsom

    Well you can always have a 'cursor' or 'pencil' that creates static duplicates of itself every tick / few milliseconds as it moves, creating a "line". You can then use lerp(),qarp(),or cubic() to move the pencil how you want.

    Maybe not the best idea but if you insist on not using plugins there ya go :P

    Sounds a bit technical for me! Thanks for help.

    R0J0hound

    To get a formula for cubic look on the wikipedia page for "bezier curves".

    Here's an implementation:

    dl.dropbox.com/u/5426011/examples%208/cubicCurve.capx

    You will get better results with the canvas plugin though, which won't have breaks in the curve.

    Brilliant example as ever.....i will also check out the Canvas plugin.

    Many thanks.

    Note:

    Does the Canvas allow me to draw a curved line, if for example i left mouse click and move the cursor away to another position and release the mouse?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Does the Canvas allow me to draw a curved line, if for example i left mouse click and move the cursor away to another position and release the mouse?

    Yeah, you would have to set up a counter, and some variables for each click, like on click one set start xy to mouse xy, on click two set end xy to mouse xy, then on click 3 set offset to mouse xy.

    Then on mouse release draw using the variables.

    Or you could set up your own spline with handles, but that's way more complicated.

  • > Does the Canvas allow me to draw a curved line, if for example i left mouse click and move the cursor away to another position and release the mouse?

    Yeah, you would have to set up a counter, and some variables for each click, like on click one set start xy to mouse xy, on click two set end xy to mouse xy, then on click 3 set offset to mouse xy.

    Then on mouse release draw using the variables.

    Or you could set up your own spline with handles, but that's way more complicated.

    Thanks newt...I will see if i can get this to work.

    (not the spline with handles part though!)

    <img src="smileys/smiley1.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)