drawing shapes on a canvas when the user clicks

This commit is contained in:
Gavin McDonald
2016-02-17 10:32:14 -05:00
commit f7cb7c094a
18 changed files with 1665 additions and 0 deletions

37
src/sketch.js Normal file
View File

@@ -0,0 +1,37 @@
export default class Sketch {
constructor(settings) {
this.lastTime = null;
['getContext', 'onResize', 'render'].map(method => this[method] = this[method].bind(this));
this.draw = settings.draw || function() {}; // () => {};
this.container = settings.element || document.body;
window.addEventListener('optimizedResize', this.onResize);
this.canvas = document.createElement('canvas');
this.canvas.width = this.container.offsetWidth;
this.canvas.height = this.container.offsetHeight;
this.context = this.canvas.getContext('2d');
this.container.appendChild(this.canvas);
requestAnimationFrame(this.render);
}
getContext() { return this.context; }
onResize(event) {
console.log('sketch - onResize', arguments);
}
render(now) {
this.draw(this.context, now, this.lastTime);
this.lastTime = now;
requestAnimationFrame(this.render);
}
}