Class: Doodler::Strategy

Inherits:
Object
  • Object
show all
Includes:
Notification
Defined in:
lib/doodler/strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Notification

#notify_complete, #notify_start

Constructor Details

#initialize(image) ⇒ Strategy

Returns a new instance of Strategy.



7
8
9
# File 'lib/doodler/strategy.rb', line 7

def initialize(image)
  @image = image
end

Instance Attribute Details

#imageObject

Returns the value of attribute image.



5
6
7
# File 'lib/doodler/strategy.rb', line 5

def image
  @image
end

Instance Method Details

#bubblizeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/doodler/strategy.rb', line 11

def bubblize
  notify_start

  50000.times do
    centre = [rand(width), rand(height)] ; radius = rand(5)
    color = ChunkyPNG::Color(image[centre[0], centre[1]])

    left = [0, centre[0] - radius].max
    right = [centre[0] + radius, (width-1)].min
    up = [centre[1] + radius, (height-1)].min
    down = [0, centre[1] - radius].max

    (left..right).to_a.each do |x|
      (down..up).to_a.each do |y|
        image[x,y] = color if distance_from_centre(centre, x, y) <= radius
      end
    end

  end

  render
  notify_complete
end

#cubifyObject



35
36
37
# File 'lib/doodler/strategy.rb', line 35

def cubify
  # another method
end

#renderObject



43
44
45
# File 'lib/doodler/strategy.rb', line 43

def render
  image.save("image/render/output.png")
end

#textifyObject



39
40
41
# File 'lib/doodler/strategy.rb', line 39

def textify
  # another method
end