Created
May 28, 2017 14:22
-
-
Save paweljw/c2c850dc5e9b74f071610fdfbc13fa83 to your computer and use it in GitHub Desktop.
This file contains 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 Color { | |
constructor (r, g, b) { | |
this.r = r | |
this.g = g | |
this.b = b | |
} | |
mix (otherColor) { | |
let red = Math.floor((this.r + otherColor.r) / 2) | |
let green = Math.floor((this.g + otherColor.g) / 2) | |
let blue = Math.floor((this.b + otherColor.b) / 2) | |
return new Color(red, green, blue) | |
} | |
toPastel () { | |
return this.mix(new Color(255, 255, 255)) | |
} | |
toString () { | |
return `rgb(${this.r}, ${this.g}, ${this.b})` | |
} | |
static random () { | |
let red = Math.floor(Math.random() * 255) | |
let green = Math.floor(Math.random() * 255) | |
let blue = Math.floor(Math.random() * 255) | |
return new Color(red, green, blue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment