Don't reinvent the wheel (no pun intended :-)
require 'cairo'
radius = ARGV[0].to_f
aspect = (ARGV[1]||1.0).to_f
linewidth = (ARGV[2]||1.0).to_f
width = (aspect * radius * 2 + 1 + linewidth + 0.5).to_i
height = (radius * 2 + 1 + linewidth + 0.5).to_i
Cairo::ImageSurface.new(width, height) do |surface|
cr = Cairo::Context.new(surface)
cr.set_antialias(Cairo::ANTIALIAS_NONE)
cr.set_source_rgb(0,0,0)
cr.paint
cr.save
cr.scale(aspect, 1.0)
cr.arc(width / 2.0 / aspect + 0.5, height / 2.0 + 0.5, radius, 0, 2
* Math::PI)
cr.restore
cr.set_source_rgb(1,1,1)
cr.set_line_width(linewidth)
cr.stroke
height.times { |row|
puts cr.target.data[row * width * 4, width * 4].unpack("N*").map
{ |x| (x >> 8) > 0 ? '#' : ' ' }.join
}
end