Skip to content

Instantly share code, notes, and snippets.

@rys
Created April 8, 2012 23:55
Show Gist options
  • Save rys/2340427 to your computer and use it in GitHub Desktop.
Save rys/2340427 to your computer and use it in GitHub Desktop.
DPI calculator plugin for rbot
class DpiPlugin < Plugin
def help(plugin, topic="")
"!dpi width height diagonal"
end
def dpi(m, params)
begin
x = params[:width].to_f
y = params[:height].to_f
d = params[:diagonal].to_f
if x == 0 or y == 0
m.reply "oops"
return
end
dpi = (x / Math.sqrt(d**2 / (1 + ((y/x)**2)))).to_i
m.reply "#{dpi}DPI"
rescue Exception => e
m.reply "error: #{e.message}"
end
end
end
plugin = DpiPlugin.new
plugin.map 'dpi [:width] [:height] [:diagonal]',
:defaults => { :width => 2048, :height => 1536, :diagonal => 9.7 },
:thread => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment