Here's a small thread of 5 useful but undocumented things you can do in #p5js (because they use drawingContext, the vanilla #javascript canvas API):
1. drawingContext.createLinearGradient() lets you create a gradient with as many colors as you want, at any angle you want, and lets use it as a fill style! developer.mozilla.org/en-US/docs/Web…
2. drawingContext.filter = `blur(${10 * pixelDensity()}px)` blurs everything you draw, and does it so much faster than the js-based blur() filter in p5 that you can use it in animations! developer.mozilla.org/en-US/docs/Web…
3. drawingContext.shadowBlur, shadowColor, shadowOffsetX and shadowOffsetY let you add drop shadows to anything that you draw developer.mozilla.org/en-US/docs/Web…
4. After drawing a shape, calling drawingContext.clip() will use that shape as a mask for anything new that you draw after that! developer.mozilla.org/en-US/docs/Web…
5. A few push() calls deep and want to know where the mouse coordinate is in local coordinates?
const matrix = drawingContext.getTransform();
const localCoord = matrix.inverse().transformPoint(new DOMPoint(mouseX*pixelDensity(), mouseY*pixelDensity()));
one more bonus that I remembered: drawingContext.globalAlpha = 0.5 lets you draw semitransparent shapes! developer.mozilla.org/en-US/docs/Web…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Dave Pagurek

Dave Pagurek Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(