Module: Contrek::Bitmaps::Painting

Included in:
Bitmap
Defined in:
lib/contrek/bitmaps/painting.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.direct_draw_polygons(polygons, png_image) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/contrek/bitmaps/painting.rb', line 22

def self.direct_draw_polygons(polygons, png_image)
  polygons.compact.each do |poly|
    color = ChunkyPNG::Color("red @ 1.0")
    poly[:outer].each_cons(2) do |coords|
      png_image.draw_line(coords[0][:x], coords[0][:y], coords[1][:x], coords[1][:y], color)
    end
    png_image.draw_line(poly[:outer][0][:x], poly[:outer][0][:y], poly[:outer][-1][:x], poly[:outer][-1][:y], color)
    color = ChunkyPNG::Color("green @ 1.0")
    poly[:inner].each do |sequence|
      sequence.each_cons(2) do |coords|
        png_image.draw_line(coords[0][:x], coords[0][:y], coords[1][:x], coords[1][:y], color)
      end
      png_image.draw_line(sequence[0][:x], sequence[0][:y], sequence[-1][:x], sequence[-1][:y], color)
    end
  end
end

Instance Method Details

#bitmap_colors(step: 1, max: 0) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/contrek/bitmaps/painting.rb', line 8

def bitmap_colors(step: 1, max: 0)
  colors = {}
  step = 1 if step <= 0
  0.step(h - 1, step) do |h|
    0.step(w - 1, step) do |w|
      color = value_at(w, h)
      colors[color] ||= 0
      colors[color] += 1
      break if colors.size == max
    end
  end
  colors.sort_by { |color, count| -color }
end

#draw_line(start_x, start_y, end_x, end_y, value) ⇒ Object

Raises:

  • (NoMethodError)


4
5
6
# File 'lib/contrek/bitmaps/painting.rb', line 4

def draw_line(start_x, start_y, end_x, end_y, value)
  raise NoMethodError
end