Hacker News new | ask | show | jobs
by anvaka 2354 days ago
Thank you for sharing this! I think it is a very cool trick. Unfortunately it didn't work for me. Seems like whether path is closed or not is not persisted during `ctx.save()` operation: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRende...

Which causes the bottom closing line to appear where it shouldn't. Here is a simple jsbin to reproduce: https://jsbin.com/luzatuteha/1/edit?html,js,output

1 comments

Wow, bummer -- that's a surprise and disappointment to me that the canvas 2d API isn't more like PostScript in that way. Filling then stroking the same path is a very common operation.

NeWS's dialect of PostScript (but not standard Adobe PostScript) had currentpath / setpath operators to save and restore the current path as a first class object, so you could use it any number of times later in different contexts. I wish the canvas 2d api had that too, plus some set operations on regions.

http://bitsavers.trailing-edge.com/pdf/sun/NeWS/NeWS_1.1_Man...

It'd be fun and worth coding up a WebGL renderer, I think! Then you can pass all the points in one big chunk of memory, and draw it from any direction, with lighting and shadows!