Skip to content

Instantly share code, notes, and snippets.

@robertcdawson
Created September 24, 2015 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertcdawson/cdbc461cb9d8140bdc2f to your computer and use it in GitHub Desktop.
Save robertcdawson/cdbc461cb9d8140bdc2f to your computer and use it in GitHub Desktop.
// ref 1: http://toddmotto.com/mastering-the-module-pattern/
// ref 2: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillText
// create basic diagram module (w/ "revealing module" pattern from ref 1)
var D_ = (function() {
// draw container
var draw = function(label) {
var canvas = document.getElementById('canvas');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
// x, y, w, h
ctx.strokeRect(10, 10, 200, 200);
ctx.font = "1rem sans-serif";
// "text", x, y, max width (will squeeze text)
ctx.fillText(label, 50, 100, 180);
}
};
var step = function(label) {
draw(label);
};
return {
step: step
};
})();
D_.step('Step 1');
// make copy of D_
// var D1_ = (function(D_){
// var step = D_.step;
// return {
// step: step
// };
// })(D_ || {});
//
// D1_.step("Step 2");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment