Created
April 8, 2012 23:55
-
-
Save rys/2340427 to your computer and use it in GitHub Desktop.
DPI calculator plugin for rbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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