Created
February 25, 2017 17:06
-
-
Save dammyammy/292c9fbb9f6be33bd3621843dd96c4dc to your computer and use it in GitHub Desktop.
A simple color generator ES6 Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ColorGenerator { | |
grab(number) { | |
var colors = []; | |
for(var i = 0; i < number; i++){ | |
colors.push(this.random); | |
} | |
return colors; | |
} | |
get random() { | |
var number = Math.floor((Math.random() * 20) + 1) - 1; | |
return this.colors[number]; | |
} | |
constructor(){ | |
this.colors = [ | |
'rgba(255, 99, 132, 0.2)', | |
'rgba(54, 162, 235, 0.2)', | |
'rgba(255, 206, 86, 0.2)', | |
'rgba(75, 192, 192, 0.2)', | |
'rgba(153, 102, 255, 0.2)', | |
'rgba(255, 159, 64, 0.2)', | |
'rgba(255,99,132,0.2)', | |
'rgba(54, 162, 235, 0.2)', | |
'rgba(255, 206, 86, 0.2)', | |
'rgba(75, 192, 192, 0.2)', | |
'rgba(153, 102, 255, 0.2)', | |
'rgba(255, 159, 64, 0.2)', | |
'rgba(255, 130, 42, 0.2)', | |
'rgba(202, 30, 32, 0.2)', | |
'rgba(160, 68, 190, 0.2)', | |
'rgba(103, 202, 155, 0.2)', | |
'rgba(234, 159, 74, 0.2)', | |
'rgba(200, 130, 52, 0.2)', | |
'rgba(222, 30, 62, 0.2)', | |
'rgba(180, 68, 180, 0.2)', | |
]; | |
} | |
} | |
export default ColorGenerator; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment