Skip to content

Instantly share code, notes, and snippets.

@stephanschubert
Last active August 30, 2015 14:24
Show Gist options
  • Save stephanschubert/149945 to your computer and use it in GitHub Desktop.
Save stephanschubert/149945 to your computer and use it in GitHub Desktop.
Convert CMYK to RGB with automatic caching
cmyk = Hash.new do |cache, rgb|
cmy = rgb.map { |color| 255 - color }
k = cmy.min
cache[rgb] = cmy.map { |color| color - k } + [k]
end
# Usage
cmyk[ [128, 42, 23] ] # => [0, 86, 105, 127]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment