▲ | An interactive guide to SVG paths(joshwcomeau.com) | |||||||||||||||||||||||||
454 points by joshwcomeau 8 days ago | 43 comments | ||||||||||||||||||||||||||
▲ | cousin_it 4 days ago | parent | next [-] | |||||||||||||||||||||||||
I wonder if there's a more intuitive way to define an elliptical arc given 2 endpoints. Dimension analysis shows we need 3 parameters. The SVG spec uses rx/ry/rotation, plus a couple booleans, but maybe there's a better parameterization without booleans? For example, it could be two coordinates of a control point - if the endpoints are A and B and the control point is C, the ellipse would be tangent to AC and BC - and an additional positive number for squishing the ellipse closer or farther from C, with values above 1 making the arc bubble outward. So it would occupy a natural spot between quadratic Bezier (with 2 parameters = 1 control point) and cubic Bezier (4 parameters = 2 control points). | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | tracker1 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Worth noting that SVG manipulation via JSX support (such as in React) can be incredibly useful in practice. I used this to add markers and highlights over scanned documents in the past, as well as bar charts, line graphs etc... all without having to add in massive module libraries. Most charting libraries are excessively large when you just want to show/chart a little data. | ||||||||||||||||||||||||||
▲ | amtunlimited 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
I'm really glad the article links to Freya's "Beauty of Bezier Curves" videos, it's genuinely one of the best math/graphics/explainer videos ever made | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | dang 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Same title, but different article: An interactive guide to SVG paths - https://news.ycombinator.com/item?id=36574645 - July 2023 (39 comments) | ||||||||||||||||||||||||||
▲ | AndrewStephens 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
I really could have used this last year when I was making a web adventure game with randomly created map. SVG is one of those frontend technologies that seem pointless until you really need them. Dynamically creating SVG in response to user actions in the game provided a very nice graphical representation of the adventure. Unlike the author of this piece, I found the lower-case relative commands extremely useful for creating shapes like arrows (or in my case, sectors of space) that can be translated around later. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | joshuat 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
NaN published a really great page about SVG paths a while ago: https://www.nan.fyi/svg-paths | ||||||||||||||||||||||||||
▲ | danielvaughn 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
I always took for granted that devs knew about SVG, but I had come into the industry by way of design, so I had already been toying with vectors for years with Adobe Illustrator and Sketch. SVG is awesome. Heavily underinvested in the web spec, would love to see SVG2 get some attention. | ||||||||||||||||||||||||||
▲ | ludicity 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Everything Comeau puts out is so goddamn good. I paid for his CSS course a year ago and the effort that went into the pedagogy is just spectacular. | ||||||||||||||||||||||||||
▲ | emschwartz 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
This is so detailed and easy to understand. Thank you for writing this up. | ||||||||||||||||||||||||||
▲ | kevg123 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Anything by Josh is gold. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | ZFleck 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Loved this. Thought it was perfect for my skill level (I know what an .svg is; that's about it). I think what I learned will actually come in handy the next time I'm trying to adjust / optimize an icon. I really liked the sound effects! Spent perhaps too long just picking up and dragging stuff. Thanks! | ||||||||||||||||||||||||||
▲ | simpaticoder 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
I wonder if Seymour Papert's Logo programming language influenced the SVG path syntax. M and L correspond directly to "pen up/pen down" and move. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | nayuki 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Well done on the excellent interactive visual explanation! Having experience reading/writing SVG paths from scratch, here are a few additions for the "Lil' extras" section: * 'H' (horizontal) is a shorthand for 'L' (line) where the y-coordinate does not change. For example, "M 12,34 H 56" is shorthand for "M 12,34 L 56,34". There is of course a lowercase relative version too, 'h', so "M 12,34 h 56" means "M 12,34 l 56,0". * 'V' (vertical) is a shorthand for 'L' (line) where the x-coordinate does not change. For example, "M 12,34 V 56" is shorthand for "M 12,34 L 12,56". There is of course a lowercase relative version too, 'v', so "M 12,34 v 56" means "M 12,34 v 0,56". | ||||||||||||||||||||||||||
▲ | WillAdams 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Is there a drawing program which focuses on the programmability aspect of SVG editing while allowing drawing in a natural fashion? I've done it in Inkscape, but it's a bit awkward --- there was a programming orienting tool mentioned here a while back, but it was light on the drawing aspect. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | igtztorrero 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
10 years hearing about SVG and now with 2 minutes I understand, it's like Logo language, the turtle. Thanks for the tutorial! | ||||||||||||||||||||||||||
▲ | Springtime 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Just something that would be worthwhile looking into is preventing blanking out the entire page if cookies (and by extension local storage) are disabled. The page loads fully briefly then blanks out to a full viewport React error. I see this on various sites where it's avoidable. | ||||||||||||||||||||||||||
▲ | manveerc 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Very nice! We had a use case where we needed to convert some images into SVGs. Since AI performed poorly at that task, we had to spend time reading and understanding the SVG code. This makes things much easier. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | NoSalt 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
This is a fantastic article, and the interactive visuals really drive it home! | ||||||||||||||||||||||||||
▲ | hinkley 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Curves were tough for me when I did logos. And at one point I decided one would be better off rotated, and realized a transform would be far, far easier than trying to modify the paths to run on a slant. | ||||||||||||||||||||||||||
▲ | leeoniya 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
heh, im currently working on an svg pathstring to canvs2d command compiler [1] and had to dive into this topic last week, including converting arc commands from centerpoint parameterization to endpoint parameterization [2] [1] https://github.com/leeoniya/uMarks (WIP!) [2] https://www.w3.org/TR/SVG/implnote.html#ArcConversionCenterT... | ||||||||||||||||||||||||||
▲ | DrewADesign 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
I enjoyed the linked explainer video about the math of Bézier curves. | ||||||||||||||||||||||||||
▲ | mark-r 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
The aside about whitespace and punctuation was interesting. Is there an SVG tidy program out there that will make your files more readable? | ||||||||||||||||||||||||||
▲ | royletron 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Of all the technologies I got exposure to on my Comp Sci degree, SVG is the only one I really still use every day. | ||||||||||||||||||||||||||
▲ | vFunct 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Would the same bezier curves be used in font rendering? And do we have GPU bezier drawing functions or shader kernels available? | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | andrewrn 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Wow someone put a lot of work into this. Always had trouble with the path element. Thanks! | ||||||||||||||||||||||||||
▲ | p0w3n3d 4 days ago | parent | prev [-] | |||||||||||||||||||||||||
those sounds are wonderful | ||||||||||||||||||||||||||
|