# Called as # $ ruby image_generator.rb _width_ [_height_ [_num_zeroes_ [_max_num_]]] # height defaults to width # max_num defaults to 9 require 'optparse' w = ARGV[0].to_i h = w max = 999999 zeroes = 1 if ARGV.length > 1 h = ARGV[1].to_i if ARGV.length > 2 zeroes = ARGV[2].to_i if ARGV.length > 3 max = ARGV[3].to_i end end end def dist(a,b) #a.zip(b).map {|l| (l[0]-l[1]).abs}.max a.zip(b).map {|l| (l[0]-l[1]).abs}.reduce &:+ end prng = Random.new img = [] z_pos = [] zeroes.times do |i| z_pos.push [prng.rand(w), prng.rand(h)] end h.times do |y| img.push([]) w.times do |x| img[y][x] = z_pos.map {|z| [max,(dist z,[x,y])].min}.min end line = img[y].map(&:to_s).join ' ' puts line end