crowds/slides/js/lib/helpers.js

44 lines
812 B
JavaScript
Raw Normal View History

2018-03-27 17:39:08 +00:00
//////////////////
// HELPERS ///////
//////////////////
Math.TAU = 6.2831853072;
// The poor man's jQuery
function $(query){
return document.querySelector(query);
}
function $all(query){
return document.querySelectorAll(query);
}
// Wide Sigmoid
function sigmoid(x){
return x / (1 + Math.abs(x));
}
// Create retina canvas
function createCanvas(canvas, width, height){
// The "canvas" arg not provided? make a new one!
if(arguments.length==2){
height = arguments[1];
2018-03-28 14:57:19 +00:00
width = arguments[0];
2018-03-27 17:39:08 +00:00
canvas = document.createElement("canvas");
}
// Set difference in width & height
canvas.width = width*2;
canvas.height = height*2;
canvas.style.width = width;
canvas.style.height = height;
return canvas;
}
// Copy an object
function cloneObject(obj){
return JSON.parse(JSON.stringify(obj));
}