Class: LittleBrat::Letter

Inherits:
Object
  • Object
show all
Defined in:
lib/littlebrat.rb

Instance Method Summary collapse

Constructor Details

#initialize(window, text) ⇒ Letter

Returns a new instance of Letter.



91
92
93
94
95
96
97
98
# File 'lib/littlebrat.rb', line 91

def initialize window, text
  text_height = random_text_size window
  @image      = Gosu::Image.from_text window, text,
                                      Gosu::default_font_name,
                                      text_height
  @color      = random_color # Image text is white, so this is to modulate it
  @x, @y      = random_position window, text_height
end

Instance Method Details

#drawObject



100
101
102
# File 'lib/littlebrat.rb', line 100

def draw
  @image.draw @x, @y, 1, 0.5, 0.5, @color
end

#random_byteObject



116
117
118
# File 'lib/littlebrat.rb', line 116

def random_byte
  rand(255 - 40) + 40
end

#random_colorObject



108
109
110
111
112
113
114
# File 'lib/littlebrat.rb', line 108

def random_color
  color       = Gosu::Color.new 0xff000000
  color.red   = random_byte
  color.green = random_byte
  color.blue  = random_byte
  color
end

#random_position(window, text_height) ⇒ Object



120
121
122
123
# File 'lib/littlebrat.rb', line 120

def random_position window, text_height
  [ rand * window.width  - (text_height / 4),
    rand * window.height - (text_height / 4) ]
end

#random_text_size(window) ⇒ Object



104
105
106
# File 'lib/littlebrat.rb', line 104

def random_text_size(window)
  (window.height / (rand + 1)).to_i
end