How can I draw a curved line ?

Get help using Construct 2

Post » Thu Dec 01, 2011 8:38 pm

Hi...

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



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


chrisbrobs2011-12-01 20:38:46
B
21
S
6
G
8
Posts: 1,215
Reputation: 7,881

Post » Thu Dec 01, 2011 9:25 pm

You can with r0j0hound's canvas plugin.
Moderator
B
93
S
33
G
33
Posts: 3,006
Reputation: 27,719

Post » Fri Dec 02, 2011 10:23 am

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.
B
21
S
6
G
8
Posts: 1,215
Reputation: 7,881

Post » Fri Dec 02, 2011 5:33 pm

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 :PTokinsom2011-12-02 17:34:20
Image
B
240
S
28
G
13
Posts: 1,787
Reputation: 18,535

Post » Fri Dec 02, 2011 5:56 pm

C2 doesn't have qarp or cubic yet.
Moderator
B
93
S
33
G
33
Posts: 3,006
Reputation: 27,719

Post » Fri Dec 02, 2011 8:07 pm

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.
B
91
S
31
G
99
Posts: 5,197
Reputation: 65,680

Post » Fri Dec 02, 2011 9:25 pm

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:
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.

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?
B
21
S
6
G
8
Posts: 1,215
Reputation: 7,881

Post » Fri Dec 02, 2011 10:55 pm

[QUOTE=chrisbrobs]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?[/QUOTE]

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.
Image ImageImage
B
167
S
50
G
160
Posts: 8,171
Reputation: 103,438

Post » Sat Dec 03, 2011 1:14 am

[QUOTE=newt] [QUOTE=chrisbrobs]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?[/QUOTE]

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.[/QUOTE]


Thanks newt...I will see if i can get this to work.
(not the spline with handles part though!)
B
21
S
6
G
8
Posts: 1,215
Reputation: 7,881


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests