Skip to content

Instantly share code, notes, and snippets.

View stevenkuipers's full-sized avatar
🌍
Working from home - stay safe

Steven Kuipers stevenkuipers

🌍
Working from home - stay safe
View GitHub Profile
@stevenkuipers
stevenkuipers / randomIntRange.js
Created May 23, 2018 09:33
Takes two integers as input and returns an integers as output that is min inclusive and max exclusive
// @Param integer, integer - Takes two integers as input
// Returns an integer that is min inclusive and max exclusive
// @Return integer
const randomIntRange = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
@stevenkuipers
stevenkuipers / relativeCoords.js
Created May 23, 2018 09:28
Helper function for mouse events to get relative coordinates within bounds. Useful for mouse events on canvas.
// @param Object - Takes a mouse move event object as input
// @return Object - returns an object with an x and y coordinate
const relativeCoords = ( event ) => {
let bounds = event.target.getBoundingClientRect();
let x = event.clientX - bounds.left;
let y = event.clientY - bounds.top;
return {x: x, y: y};
}