#!/usr/bin/env ruby # # visualize.rb # def main if ARGV.delete('--text') main_TEXT else ARGV.delete('--image') main_IMAGE end end def usage(status) $stderr.puts "#{$0} --size=N --true=C --false=C > out.png" exit status end def main_IMAGE require 'GD' require 'getopts' ok = getopts(nil, 'false:', 'true:', 'size:') usage 1 unless ok size = $OPT_size.to_i img = GD::Image.new(size, size) fcolor = img.colorAllocate($OPT_false) img.fill 0, 0, fcolor tcolor = img.colorAllocate($OPT_true) `./ss #{size}`.each_with_index do |line, y| line[1..-2].split(/,/).each_with_index do |item, x| img.setPixel x, y, tcolor if item == 'True' end end print img.pngStr end def main_TEXT map = { 'True' => '¢£', 'False' => '¢¢' } `./ss #{size}`.each do |line| puts line.gsub(/[,\[\]]|True|False/) {|s| map[s] || '' } end end main