Skip to content

Instantly share code, notes, and snippets.

@alpicola
Created September 22, 2011 15:48
Show Gist options
  • Save alpicola/1235112 to your computer and use it in GitHub Desktop.
Save alpicola/1235112 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'RMagick'
if ARGV.length != 2
puts 'Usage: ./ame.rb latitude longtitude'
exit
end
url = 'http://tokyo-ame.jwa.or.jp/mesh/100/%s.gif' %
Time.at((Time.now - 30).to_i / 300 * 300).strftime('%Y%m%d%H%M')
x = (ARGV[1].to_f - 138.4) / 2.14
y = (36.23 - ARGV[0].to_f) / 1.13
if [x, y].all? {|n| (0...1).include? n }
image = Magick::Image.read(open(url).to_path).first
x = (x * image.columns).to_i
y = (y * image.rows).to_i
pixel = image.pixel_color(x, y)
pixel = image.pixel_color(x-1, y-1) if pixel.to_color == 'black'
if pixel.opacity == 0
pixel = (pixel.red & 0xff) << 16 | (pixel.green & 0xff) << 8 | pixel.blue & 0xff
intensity = [0xccffff, 0x6699ff, 0x33ffff, 0x00ff00,
0xffff00, 0xff9900, 0xff00ff, 0xff0000].index(pixel) + 1
else
intensity = 0
end
puts "intensity: #{intensity}"
else
puts 'outside the area'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment