# How can I draw a curved line ?

Get help using Construct 2

### » 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)

chrisbrobs2011-12-01 20:38:46
B
19
S
6
G
7
Posts: 1,202
Reputation: 7,294

### » Thu Dec 01, 2011 9:25 pm

You can with r0j0hound's canvas plugin.
Moderator
B
84
S
31
G
33
Posts: 3,002
Reputation: 27,266

### » 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
19
S
6
G
7
Posts: 1,202
Reputation: 7,294

### » 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
B
223
S
26
G
13
Posts: 1,768
Reputation: 17,862

### » Fri Dec 02, 2011 5:56 pm

C2 doesn't have qarp or cubic yet.
Moderator
B
84
S
31
G
33
Posts: 3,002
Reputation: 27,266

### » 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
75
S
21
G
48
Posts: 4,663
Reputation: 37,191

### » 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
19
S
6
G
7
Posts: 1,202
Reputation: 7,294

### » 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.
B
160
S
48
G
80
Posts: 7,237
Reputation: 61,502

### » 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
19
S
6
G
7
Posts: 1,202
Reputation: 7,294