Inspired by a sketch created by @nagayama on Twitter. I mostly just simplified the code and ported it to the default Canvas API.
source code