Skip to content

Instantly share code, notes, and snippets.

@paweljw
Created May 28, 2017 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paweljw/c2c850dc5e9b74f071610fdfbc13fa83 to your computer and use it in GitHub Desktop.
Save paweljw/c2c850dc5e9b74f071610fdfbc13fa83 to your computer and use it in GitHub Desktop.
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