question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stable strokes for shapes

See original GitHub issue

Hey there! Great tool 😃

Currently, the strokes are not stable when creating o resizing a shape: stable-shapes-current

Looks like Rough.js first draws the fill using a variable number of Math.random calls, so the stroke starts at a different seed even after using withCustomMathRandom. If you use Solid Fill this issue disappears, the first Math.random call is used for the stroke directly in that case.

It would be great as was discussed before if Rough.js would support stable strokes, in the meanwhile a possible workaround is to draw the fill and the stroke separately. I think the improved user experience makes the extra calls worthy. The only way I found to only draw the fill for the first call is to pass a stroke: "rgba(0,0,0,0)" though.

You can play with this approach in this forked code sandbox: https://codesandbox.io/s/currying-architecture-8f7nt

This would be the result: stable-shapes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
pshihncommented, Jan 6, 2020

There are a couple of issues here that are on my list in roughjs that address this to some extent:

  1. Seeding randomness
  2. Update roughness and bowing variability based on the size of the shape - this issue is particularly visible for non-linear shapes like ellipses. The reason is that for ellipses, for example, I estimate n number of points on the perimeter of the ellipse and fit a curve through them. the value of n is configurable here but I had planned roughjs to automatically computer the value of n based on the size of the shape. This is not hard to do, I just never got around to doing it.

I have some time this week, and will implement these appropriately.

As for the reordering of stroke/fill random calculations, it is a bit tricky because the number of points to randomize is a function of the size of the shape. I’ll give it some more thought.

Also, note that the shape of the sketched line can be preserved when the aspect ratio stays the same, It gets complicated when it’s not.

2reactions
patak-devcommented, Jan 6, 2020

Great @pshihn! Doing the stroke calculation first would at least keep some of the shapes stable without a more involved change.

But I see your point, this should be an implementation detail to let you add later features like dynamic fitting for curves so a more careful solution is needed.

If seeding is implemented in Rough.js, maybe you could allow the user to pass two seeds for the shape: one for the fill and one for the stroke. If you want users to provide only one seed to simplify the API, then the same seed could be used for both the stroke and fill. Or the seed may be used for the stroke, and then modify it in a fixed way to do the fill.

Thanks for such an awesome lib by the way 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Draw Smooth Lines with Stroke Stabilization in Procreate
Learn how to use Stroke Stabilization in Procreate to draw smooth lines. ... drawing outlines or shapes with stroke stabilization enabled.
Read more >
Steady and Predictive Stroke - Sketchbook
Use Steady Stroke to draw uniform smoother strokes. ... Predictive stroke tries to understand your objective when drawing shapes such as lines, triangles, ......
Read more >
Steady and Predictive Stroke - Autodesk Knowledge Network
Use Steady Stroke to draw uniform smoother strokes. Steady Stroke has an option ... The higher the number the better the shape recognition....
Read more >
is there a stroke stabilizer/correction in fresco?
There is a shape tool which you can use now but it seems to mainly be for filling shapes rather than drawing a...
Read more >
Brush Studio Settings - Procreate® Handbook
If you reduce down to no space, the brush shapes along the path will merge into one single fluid stroke. Jitter. Takes each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found