Skip to content

Instantly share code, notes, and snippets.

@mutsuda
Last active August 15, 2016 19:17
Show Gist options
  • Save mutsuda/54ce7c4d719b9ccb5db0be7a578fa9e4 to your computer and use it in GitHub Desktop.
Save mutsuda/54ce7c4d719b9ccb5db0be7a578fa9e4 to your computer and use it in GitHub Desktop.
Match the color of your Hue lights to what you are seeing on your Mac's screen
require 'hue'
require 'RMagick'
require 'ColorMath'
$path = "tmp/out.jpg"
$client = Hue::Client.new
def lights(h,s,l)
$client.lights.each do |light|
light.on!
light.hue = ((h/360)*65535).round
light.saturation = (s*255).round
light.brightness = (l*255).round
end
end
def get_color(path)
img = Magick::Image.read(path).first
pix = img.scale(1, 1)
avg_color_hex = pix.to_color(pix.pixel_color(0,0))
return avg_color_hex
end
def screen_capture(path)
`screencapture #{path}`
end
while 1
screen_capture($path)
color = ColorMath::hex_color(get_color($path)[0,7])
lights(color.hue, color.saturation, color.luminance)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment