Skip to content

Instantly share code, notes, and snippets.

View varyndev's full-sized avatar

John Foster varyndev

View GitHub Profile
@jf990
jf990 / class-template.js
Created April 7, 2020 17:19
JavaScript class pattern
/**
* Example JavaScript code to demonstrate how to compose classes.
* This requires ES6 syntax.
*
* `Transportation` is a base class that is intended to have classes derived from it.
* Derived classes are expected to manage the base class properties and add their own.
* In each constructor, `super` is called first to allow the base class to perform its state
* initialization before the derived class do its, allowing the derived class to override
* anything done in the base class constructor.
*/
@lucprincen
lucprincen / save-canvas-thumb.js
Last active December 21, 2020 03:10
Save a copy of the canvas as a thumnail. Requires EaselJS and returns a base64 string.
function saveCanvasThumbnail( scale ){
if( scale === undefined ) scale = .3;
var canvas = getElementById( 'canvas' );
var bitmap = new createjs.Bitmap( canvas );
bitmap.cache( 0, 0, canvas.width, canvas.height, scale );
var base64 = bitmap.getCacheDataURL();