News for hackers. Stuff that matters.
Re:Fibre:A WebGL application for visualizing 3D vector field... by DonHopkins on Friday January 04, 2019 @02:22AM (#18822528)
Lovely code! Thanks for sharing.

Oh cool, TIL you can dispatch a fake click event on an invisible anchor element pointing to a png object url to download a file, without even putting the anchor in the document! I presume it all just gets garbage collected with it's done. I would have never have thought to attempt that, but it works like a charm, in just a few lines.

https://github.com/portsmouth/fibre/blob/master/js/fibre.js#...

        case 80: // P key: save current image to disk
        {
            if (fibre.editing) break;
            var link = document.createElement('a');
            link.download = "fibre.png";
            this.render_canvas.toBlob(function(blob){
                    link.href = URL.createObjectURL(blob);
                    var event = new MouseEvent('click');
                    link.dispatchEvent(event);
                },'image/png', 1);
            break;
        }
Re:Fibre:A WebGL application for visualizing 3D vector field... by robin_reala on Friday January 04, 2019 @08:36AM (#18823885)
The link.download is the important point: in DOM terms that’s <a download="fibre.png"> which specifies that the resource should be downloaded with a filename of fibre.png.