Skip to content

Instantly share code, notes, and snippets.

@nanki
Created March 17, 2013 15:03
Show Gist options
  • Save nanki/5181932 to your computer and use it in GitHub Desktop.
Save nanki/5181932 to your computer and use it in GitHub Desktop.
draw circle with Unicode Braille Patterns.
# -*- coding: UTF-8 -*-;
def dot(index)
index = index & 7 | (index & 112) >> 1 | (index & 8) << 3 | index & 128
case index
when 0
" "
else
[0x2800 + index].pack('U*')
end
end
def circle(x, y, r)
(x - r) ** 2 + (y - r) ** 2 < r ** 2 ? 1 : 0
end
R = 32
(0...R/2).each do |y|
(0...R).each do |x|
print dot (0...8).inject(0){|r, i| r | circle(x * 2 + ((i & 4) >> 2), y * 4 + (i & 3), R) << i}
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment