Help please..how to draw triangle

2,730 views
Skip to first unread message

Karim Elgammal

unread,
Mar 16, 2010, 6:57:10 AM3/16/10
to raph...@googlegroups.com
please...I want to draw triangle..how to draw using raphael
thx

Mat Schaffer

unread,
Mar 16, 2010, 7:49:22 AM3/16/10
to raph...@googlegroups.com
Use a path:

r.path("M0 0L50 0L25 25L0 0")

You'd need a little math to get a perfect triangle but this should get
you something triangleish.

-Mat

On Mar 16, 2010, at 6:57 AM, Karim Elgammal <egk...@gmail.com> wrote:

> please...I want to draw triangle..how to draw using raphael
> thx

> --
> You received this message because you are subscribed to the Google
> Groups "Raphaël" group.
> To post to this group, send an email to raph...@googlegroups.com.
> To unsubscribe from this group, send email to raphaeljs+...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/raphaeljs?hl=en-GB
> .

Dmitry Baranovskiy

unread,
Mar 16, 2010, 10:08:43 PM3/16/10
to raph...@googlegroups.com
Just a small note: you can write it shorter.
R.path("M0,0,50,0,25,25z");

Sent from my iPod

Mat Schaffer

unread,
Mar 16, 2010, 11:28:31 PM3/16/10
to raph...@googlegroups.com
Oh that's handy. I take it the "z" draws the shortest line to close
the path?

-Mat

On Mar 16, 2010, at 10:08 PM, Dmitry Baranovskiy <dmitry.ba...@gmail.com

Lachlan Hardy

unread,
Mar 16, 2010, 11:32:53 PM3/16/10
to raph...@googlegroups.com
> Oh that's handy. I take it the "z" draws the shortest line to close
> the path?

Yep. 'z' is awesome.

Mat Schaffer

unread,
Mar 17, 2010, 9:31:58 AM3/17/10
to raph...@googlegroups.com
This doesn't seem to work for me. I just tried:

r.path("M0,100,50,50,100,100z")

But get nothing on the canvas.

This works though:

r.path("M0,100,L,50,50,100,100z");

So I'm guessing the behavior is to repeat the last move/line/curve
directive if it's omitted?

Thanks,
Mat

tgoyer

unread,
Mar 17, 2010, 5:18:25 PM3/17/10
to Raphaël
You have to use SVG path syntax. Try:

r.path("M0,100 L50,50 L100,100 z")

(M denotes the starting coordinate, L denotes subsequent coordinates,
z ends the path)

On Mar 17, 7:31 am, Mat Schaffer <m...@schaffer.me> wrote:
> This doesn't seem to work for me. I just tried:
>
> r.path("M0,100,50,50,100,100z")
>
> But get nothing on the canvas.
>
> This works though:
>
> r.path("M0,100,L,50,50,100,100z");
>
> So I'm guessing the behavior is to repeat the last move/line/curve
> directive if it's omitted?
>
> Thanks,
> Mat
>
> On Tue, Mar 16, 2010 at 10:08 PM, Dmitry Baranovskiy
>

> <dmitry.baranovs...@gmail.com> wrote:
> > Just a small note: you can write it shorter.
> > R.path("M0,0,50,0,25,25z");
>
> > Sent from my iPod
>
> > On 16/03/2010, at 10:49 PM, Mat Schaffer <m...@schaffer.me> wrote:
>
> >> Use a path:
>
> >> r.path("M0 0L50 0L25 25L0 0")
>
> >> You'd need a little math to get a perfect triangle but this should get
> >> you something triangleish.
>
> >> -Mat
>

tgoyer

unread,
Mar 17, 2010, 5:23:43 PM3/17/10
to Raphaël
BTW, here is a link to the SVG path spec: http://www.w3.org/TR/SVG/paths.html#PathData

Ironically, they use a triangle as their example.

Ed Davies

unread,
Mar 17, 2010, 7:15:28 PM3/17/10
to Raphaël
On Mar 17, 1:31 pm, Mat Schaffer <m...@schaffer.me> wrote:
> So I'm guessing the behavior is to repeat the last move/line/curve
> directive if it's omitted?

Also didn't work for me but it should:

http://www.w3.org/TR/SVG11/paths.html#PathDataMovetoCommands

"If a moveto is followed by multiple pairs of coordinates, the
subsequent pairs are treated as implicit lineto commands."

Maybe it's a Raphaël bug? I'm still on 1.2.5. Anybody checked the
latest?

Mat Schaffer

unread,
Mar 17, 2010, 8:14:25 PM3/17/10
to raph...@googlegroups.com
Pretty sure I'm running the latest. I don't remember the version
offhand but I got it from the site like 3 days ago. I'm not really
worried about it. I have a helper to just join point objects on ",L,"
that's working fine.

-Mat

On Mar 17, 2010, at 7:15 PM, Ed Davies <ggl.rt...@edavies.nildram.co.uk
> wrote:

Ed Davies

unread,
Mar 18, 2010, 7:29:34 PM3/18/10
to Raphaël
It's fixed in 1.3.2.

paper.path("M0,100,50,50,100,100z");

didn't work in 1.2.5 whereas

paper.path("M0,100L50,50,100,100z");

did. Both work in 1.3.2. I assume it's one of the "small fixes"
Dmitry mentions in this tweet:

http://twitter.com/RaphaelJS/status/10693024738

Thanks Dmitry.

By the way, my preferred way of writing this would be:

paper.path("M0,100L50,50 100,100z");

or

paper.path("M0,100 50,50 100,100z");

with commas between the ordinates within the pairs and spaces between
the pairs but no extra punctuation. It seems to me to be the most
natural and readable minimal length form.

Mat Schaffer

unread,
Mar 20, 2010, 12:39:26 AM3/20/10
to raph...@googlegroups.com
Ah. I'm on 1.3.1 at the moment. Guess it's time for an upgrade :)

Thanks,
Mat

2010/3/18 Ed Davies <ggl.rt...@edavies.nildram.co.uk>:

Reply all
Reply to author
Forward
0 new messages