Skip to content

Instantly share code, notes, and snippets.

@paweljw paweljw/color.es6.js
Created May 28, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.