Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
PointC

SVG stroke-dasharray quick tip

Recommended Posts

Hey everyone :)

 

Another quick SVG tip. Set your stroke dash length to 0 and your linecap to round. That will get you a nice circle border around your path or a string of circles along an open path. For a complete string of circle shapes along the stroke, set the gap equal to the stroke-width.

 

 

If you set the gap to less than the stroke-width, you can overlap the circles and create a nice scalloped edge. I personally like around 50-70% of the stroke-width. Throw a gradient on for a nice picture frame.

 

See the Pen bvvddx by PointC (@PointC) on CodePen

 

With some creative layering and masking you can confine the scalloped edge to the inside or outside of you path.

 

See the Pen YaaqPQ by PointC (@PointC) on CodePen

 

Using two strokes with different stroke-width and gap sizes, you can turn an ordinary ellipse into a cloud.

 

See the Pen RMMMKv by PointC (@PointC) on CodePen

 

Morphing shapes with a circle border creates some cool results.

 

See the Pen rddOqd by PointC (@PointC) on CodePen

 

Since these are circles making up the stroke and not actual elements, we can’t draw them on or make them move individually. Or can we…? Using a mask, we can draw them on and animating the gap size can bring them into position in an interesting manner.

 

See the Pen wmmmmK by PointC (@PointC) on CodePen

 

It has its limits but can produce some fun results. The main thing to remember is set your dash length to 0 and the linecap to round. After that, experiment with stroke-width and gap size.

 

Happy tweening. 

:)


 

See the Pen VXMmZV by PointC (@PointC) on CodePen

  • Like 8
Link to comment
Share on other sites

mmm... scallops.

 

Very nice, Craig. Had no idea about this.

  • Like 4
Link to comment
Share on other sites

Nice post, .. but you lost me at scalloped: yuck :blink:

  • Haha 3
Link to comment
Share on other sites

I love the last demo, really cool and great post as always.

  • Like 3
Link to comment
Share on other sites

Pretty neat! Was this an accidental discovery?

 

For canvas that would be...

 

context.lineWidth = size;
context.setLineDash([0, size]);

 

 

See the Pen XEEGze by osublake (@osublake) on CodePen

 

  • Like 4
Link to comment
Share on other sites

8 minutes ago, OSUblake said:

Was this an accidental discovery?

 

Haha - I'm busted. ;) 

 

A few months ago I was designing something and meant to type 10 in the dash length, but missed the 1 and found the circles by accident. I've been meaning to make some demos and type this up for the GS community ever since then, but kept pushing it to the back burner until now. Thanks for the canvas conversion. I think that will help some people.

:)

 

  • Like 4
Link to comment
Share on other sites

Accidental discoveries are always the best. They make you feel like you just discovered penicillin.

 

I understand why works after seeing it, but if somebody asked me to do that yesterday, I'm sure I would have done it the hard way. With a lot of circles and a lot of math.

  • Like 5
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×