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
19
S
6
G
7
Posts: 1,205
Reputation: 7,298

Post » Thu Dec 01, 2011 9:25 pm

You can with r0j0hound's canvas plugin.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

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
19
S
6
G
7
Posts: 1,205
Reputation: 7,298

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
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Fri Dec 02, 2011 5:56 pm

C2 doesn't have qarp or cubic yet.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

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
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

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
19
S
6
G
7
Posts: 1,205
Reputation: 7,298

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 Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

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
19
S
6
G
7
Posts: 1,205
Reputation: 7,298


Return to How do I....?

Who is online

Users browsing this forum: fredriksthlm, MPPlantOfficial and 18 guests