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

48
src/utils.js Normal file
View File

@@ -0,0 +1,48 @@
export function throttleEvent(type, name, obj) {
obj = obj || window;
let running = false;
let throttle = () => {
if (!running) {
running = true;
requestAnimationFrame(() => {
obj.dispatchEvent(new CustomEvent(name));
running = false;
});
}
}
obj.addEventListener(type, throttle);
}
throttleEvent('resize', 'optimizedResize');
export function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
export function extend(obj, src) {
for (let key in src) {
if (src.hasOwnProperty(key)) obj[key] = src[key];
}
return obj;
}
export function hypotenuse(a, b) {
if (b == null) b = a;
return Math.sqrt(a*a + b*b);
}
export function random(min, max) {
if (max == null) {
max = min;
min = 0;
}
return min + Math.floor(Math.random() * (max - min + 1));
}