chaos/scripts/utils.js

32 lines
739 B
JavaScript
Raw Normal View History

2015-12-11 23:38:15 +00:00
'use strict';
2013-12-15 21:45:16 +00:00
2015-12-22 20:33:40 +00:00
const colors = [
'#F44336',
'#2196F3',
'#4CAF50',
'#F9A825',
'#E91E63',
'#00838F'
].map(color => color.match(/[A-F0-9]{2}/g).map(
component => parseInt(component, 16)
));
2015-12-11 23:38:15 +00:00
/**
* Get a random whole number
*
* @param {number} min Minimal value for the number
* @param {number} max Maximal value for the number (excluded)
* @return {number} Random number
*/
2015-12-22 20:33:40 +00:00
export const getRandomNumber = (min, max) =>
2015-12-11 23:38:15 +00:00
Math.floor(Math.random() * (max - min)) + min;
/**
2015-12-22 20:33:40 +00:00
* Get a color at given index. For any given
* index, the same color will always be returned
2015-12-11 23:38:15 +00:00
*
2015-12-22 20:33:40 +00:00
* @param {number} index Color index
2015-12-11 23:38:15 +00:00
* @return {Array} RGB components
*/
2015-12-22 20:33:40 +00:00
export const getColor = index => colors[index % colors.length];