Class: Cheers::Texture

Inherits:
ImageComponent show all
Defined in:
lib/cheers/texture.rb

Constant Summary collapse

IMAGES =
%w( texture.png )

Instance Attribute Summary collapse

Attributes inherited from ImageComponent

#canvas, #color_randomizer, #image_randomizer

Attributes inherited from Component

#canvas, #randomizer

Instance Method Summary collapse

Methods inherited from Component

#base_image, #colored_image, #composite_with_mask, #extract_background_color, #image_path

Constructor Details

#initialize(canvas, color_randomizer, element_randomizer = nil) ⇒ Texture

Returns a new instance of Texture.



8
9
10
11
12
# File 'lib/cheers/texture.rb', line 8

def initialize(canvas, color_randomizer, element_randomizer = nil)
  super
  
  @image = IMAGES.sample random: element_randomizer
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



6
7
8
# File 'lib/cheers/texture.rb', line 6

def color
  @color
end

#imageObject (readonly)

Returns the value of attribute image.



6
7
8
# File 'lib/cheers/texture.rb', line 6

def image
  @image
end

Instance Method Details

#applyObject



14
15
16
17
18
19
20
# File 'lib/cheers/texture.rb', line 14

def apply
  texture = MiniMagick::Image.open(image_path(image))
  canvas.composite(texture) do |c|
    c.compose "Over"    # OverCompositeOp
    c.geometry "+0+0"
  end
end