class Doge
Constants
- VERSION
Attributes
image[R]
Public Class Methods
new(image_path = nil, &block)
click to toggle source
# File lib/doge.rb, line 8 def initialize(image_path = nil, &block) image_path ||= File.expand_path('doge/images/doge.jpg', File.dirname(__FILE__)) @image = Magick::ImageList.new(image_path) @occupied = [] instance_eval &block if block end
Public Instance Methods
wuff(term)
click to toggle source
# File lib/doge.rb, line 15 def wuff(term) text = image_text metrics = text.get_type_metrics(@image, term) horizontal_padding = @image.columns * 0.1 horizontal_top = @image.columns - horizontal_padding - metrics.width height = metrics.height.round + 5 #padding @image.annotate(text, 0,0, Random.rand(horizontal_padding..horizontal_top), y_for_height(height), term) self end
Private Instance Methods
image_text()
click to toggle source
# File lib/doge.rb, line 34 def image_text text = Magick::Draw.new text.gravity = Magick::NorthWestGravity text.pointsize = 50 text.font_family = "Comic Sans MS" text.font_weight = Magick::BoldWeight text.fill = random_rgb text end
random_rgb()
click to toggle source
# File lib/doge.rb, line 30 def random_rgb "rgb(#{Random.rand(0..255)}, #{Random.rand(0..255)}, #{Random.rand(0..255)})" end
row_occupied?(row, height)
click to toggle source
# File lib/doge.rb, line 55 def row_occupied?(row, height) @occupied.each do |range| return true if range.include?(row) return true if range.include?(row + height) end false end
y_for_height(height)
click to toggle source
# File lib/doge.rb, line 44 def y_for_height(height) vertical_padding = @image.rows * 0.1 vertical_top = @image.rows - vertical_padding row = 0 begin row = Random.rand(vertical_padding..vertical_top).round end while row_occupied?(row, height) @occupied << (row..(row + height)) row end