Is it possible to draw a single filled shape in the canvas with different stroke styles?
In other words, can I draw a blue triangle, and have each side a different color?
I realize there's a less than optimal solution:
In short, draw a filled shape without strokes, then redraw each side with a unique stroke style.
This isn't a big deal for a single triangle, but if you've got many, more complex shapes, this seems inefficient.
So - is it possible to draw a single shape with different stroke styles along various segments of the path?
Transform your stroke into a shape - Illustrator Tutorial Then from the properties panel, click on the fill icon found under the appearance options and set the fill to none. Then to the object menu at the top, select path and the line stroke. In just one click, your stroke will become a shape.
The short answer is no, not in a built-in way anyway. The reason is because with each new call to stroke()
it will stroke the entire path, not just the not-yet-stroked parts.
You can always make your own function that, say, takes in a bunch of points or types of segments (you'd have to make your own class) giving each a color, and have that function parse them and do the drawing. But thats as buit-in as you'll get.
You'll quickly realize that opens up new and exciting problems, such as what to do about the mitering. And if you don't know what mitering is, you'll find out real quick by doing this :)
(...and then some of that problem can be alleviated by using ctx.linecap = 'round'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With