module DominoSimulator

Constants

DOMINO
DOMINO_BLACK

Each domino RGB value.

DOMINO_BLUE
DOMINO_GREEN
DOMINO_HEIGHT

Domino height,length and width.

DOMINO_LENGTH
DOMINO_ORANGE
DOMINO_PINK
DOMINO_RED
DOMINO_VIOLET
DOMINO_WHITE
DOMINO_WIDTH
DOMINO_YELLOW
VERSION

Public Class Methods

close_to_domino(pixel_color) click to toggle source

Return which color domino close to pixel.

# File lib/domino_simulator.rb, line 52
def self.close_to_domino(pixel_color)
  min = Math.sqrt((DOMINO_BLACK.red-pixel_color.red)**2+(DOMINO_BLACK.green-pixel_color.green)**2+(DOMINO_BLACK.blue-pixel_color.blue)**2)
  tmp = DOMINO_BLACK
  for domino in DOMINO do
    distance = Math.sqrt((domino.red-pixel_color.red)**2+(domino.green-pixel_color.green)**2+(domino.blue-pixel_color.blue)**2)
    if distance < min then
      min = distance
      tmp = domino
    end
  end
  return tmp
end
count(fname) click to toggle source
# File lib/domino_simulator.rb, line 65
def self.count(fname)
  img = Magick::Image.read(fname).first
  for y in 0..img.rows-1 do
    for x in 0..img.columns-1 do
      tmp = self.close_to_domino(img.pixel_color(x,y))
      img.pixel_color(x,y,tmp)
      @domino_count[tmp]+=1
    end
  end
  for domino in DOMINO do
    puts "#{@domino_color[domino]} : #{@domino_count[domino]}"
  end
  img.write("#{ARGV[0]}_replace.jpg")
end
decrease_dpi(fname) click to toggle source

Decrease row dpi to 50.

# File lib/domino_simulator.rb, line 42
def self.decrease_dpi(fname) 
  img = Magick::Image.read(fname).first
  img = img.resize_to_fit(50, )
  img.write("#{fname}_decreasedpi.jpg")
  self.count("#{fname}_decreasedpi.jpg")
  puts "height : #{self.size("#{fname}_decreasedpi.jpg")[0]}m"
  puts "width : #{self.size("#{fname}_decreasedpi.jpg")[1]}m"
end
layout() click to toggle source
# File lib/domino_simulator.rb, line 86
def self.layout#Output the layout of domino.
  
end
size(fname) click to toggle source

Expression area that required to put domino.

# File lib/domino_simulator.rb, line 81
def self.size(fname)
  img = Magick::Image.read(fname).first
  return [(DOMINO_HEIGHT/2+DOMINO_WIDTH)*img.columns,(DOMINO_LENGTH+DOMINO_WIDTH)*img.rows]
end