require 'chunky_png'
class Color
  def initialize(color_table=nil)
    @color_table = color_table || [1, 0]
  end

  def rgb
    colors = [
      [[255,192,192], [255,0,0], [192,0,0]], # Red
      [[255,255,192], [255,255,0], [192,192,0]], # Yellow
      [[192,255,192], [0,255,0], [0,192,0]], # Green
      [[192,255,255], [0,255,255], [0,192,192]], # NAME_1
      [[192,192,255], [0,0,255], [0,0,192]], # Blue
      [[255,192,255], [255,0,255], [192,0,192]], # NAME_2
    ]
    colors[@color_table[1]][@color_table[0]]
  end

  def push_color
    @color_table[0] = (@color_table[0] + 1) % 3
    rgb
  end

  def write_color
    @color_table[0] = (@color_table[0] + 2) % 3
    @color_table[1] = (@color_table[1] + 5) % 6
    rgb
  end
end

current_color = Color.new
piet_painting = []

def draw_block(piet_painting, current_color,size,num)
  block = Array.new(12) { Array.new(12) { Array.new(3, 0) } }
  if num != 0
    old_push_color = current_color.push_color
    current_color.write_color

    block.each_index do |i|
      block[i].each_index do |j|
        block[i][j] = current_color.rgb
      end
    end
    block[0][0] = old_push_color
    size += 1
  else
    block.each_index do |i|
      block[i].each_index do |j|
        block[i][j] = current_color.rgb
      end
    end
  end

  pix_lft = 144 - size
  div = pix_lft / 12
  rem = pix_lft % 12

  if div != 0
    block[(12-div)..-1].each_index do |i|
      block[(12-div)..-1][i].each_index do |j|
        block[(12-div)+i][j] = [0,0,0]
      end
    end
  end
  block[(11-