#!/usr/bin/env ruby

require 'pathname'

input = ARGV.first

data = File.read input

t = data.chomp + "]"

t = eval t

formatted_tiles = t.map do |tile|
  s = "P6  8 8 3 "
  tile.each do |row|
    row.each do |pixel|
      s << pixel.chr * 3
    end
  end
  s << "\n"
end

out_path = Pathname.new "tile_set"
out_path.mkpath
formatted_tiles.each_with_index do |tile, i|
  (out_path + "#{i}.ppm").open("w:utf-8") {|f| f.write tile }
end
