Created
October 12, 2011 22:50
-
-
Save alexalemi/1282878 to your computer and use it in GitHub Desktop.
python antialiased circles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: latin-1 -*- | |
import math | |
characters = [32,0x2591,0x2592,0x2593,0x2588] | |
breakpoints = [0.1,0.177,0.316,0.563] | |
#reakpoints = [0.2,0.4,0.6,0.8] | |
def raster(x,y,R,center,SIGMA=1.5): | |
r = math.sqrt(math.pow(x-center,2)+math.pow( (y-center)*0.9,2)) | |
return math.exp(-math.pow(r-R,2)/SIGMA) | |
from bisect import bisect | |
def genchr(z): | |
n = bisect(breakpoints,z) | |
return unichr(characters[n]) | |
def circle(R,sigma=1.5,side=10): | |
size = 2*R + 2*side | |
array = [] | |
for z in xrange(size): | |
array.append([' ']*size) | |
center = side+R | |
for i in xrange(size): | |
for j in xrange(size): | |
z = raster(i,j,R,center,sigma) | |
foo = genchr(z) | |
array[i][j] = foo | |
#print "{},{}:{}:{}".format(i,j,z,foo) | |
array[center][center] = 'X' | |
return array | |
import sys | |
def printarr(arr): | |
for line in arr: | |
for c in line: | |
print c, | |
if __name__=="__main__": | |
if len(sys.argv)>1: | |
if len(sys.argv)==2: | |
printarr(circle(int(sys.argv[1]))) | |
elif len(sys.argv)==3: | |
printarr(circle(int(sys.argv[1]),float(sys.argv[2]))) | |
else: | |
printarr(circle(int(sys.argv[1]),float(sys.argv[2]),int(sys.argv[3]))) | |
else: | |
mesg = r"""Usage: circle R [SIGMA] [SIDE] where R is radius, sigma is sigma and side is buffer on edges""" | |
print mesg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
▒ ▒ ▓ ▓ ▓ ▓ ▓ ▒ ▒ | |
░ ▒ ▓ █ █ █ █ █ █ █ █ █ ▓ ▒ ░ | |
▒ ▓ █ █ █ █ █ ▓ ▓ ▓ █ █ █ █ █ ▓ ▒ | |
▒ █ █ █ █ ▓ ▒ ░ ░ ▒ ▓ █ █ █ █ ▒ | |
▒ █ █ █ ▓ ░ ░ ▓ █ █ █ ▒ | |
▒ █ █ █ ▓ ▓ █ █ █ ▒ | |
▓ █ █ ▓ ▓ █ █ ▓ | |
▒ █ █ ▓ ░ ░ ▓ █ █ ▒ | |
▓ █ █ ▒ ▒ █ █ ▓ | |
▓ █ █ ░ ░ █ █ ▓ | |
░ █ █ ▓ ░ ░ ▓ █ █ ░ | |
░ █ █ ▓ X ▓ █ █ ░ | |
░ █ █ ▓ ░ ░ ▓ █ █ ░ | |
▓ █ █ ░ ░ █ █ ▓ | |
▓ █ █ ▒ ▒ █ █ ▓ | |
▒ █ █ ▓ ░ ░ ▓ █ █ ▒ | |
▓ █ █ ▓ ▓ █ █ ▓ | |
▒ █ █ █ ▓ ▓ █ █ █ ▒ | |
▒ █ █ █ ▓ ░ ░ ▓ █ █ █ ▒ | |
▒ █ █ █ █ ▓ ▒ ░ ░ ▒ ▓ █ █ █ █ ▒ | |
▒ ▓ █ █ █ █ █ ▓ ▓ ▓ █ █ █ █ █ ▓ ▒ | |
░ ▒ ▓ █ █ █ █ █ █ █ █ █ ▓ ▒ ░ | |
▒ ▒ ▓ ▓ ▓ ▓ ▓ ▒ ▒ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
░ ▒ ▓ ▓ ▓ ▓ ▓ ▓ ▓ ▒ ░ | |
░ ▓ ▓ █ █ █ █ █ █ █ █ █ █ █ ▓ ▓ ░ | |
░ ▓ █ █ █ █ █ █ █ ▓ ▓ ▓ █ █ █ █ █ █ █ ▓ ░ | |
▒ █ █ █ █ █ ▓ ▒ ░ ░ ▒ ▓ █ █ █ █ █ ▒ | |
░ ▓ █ █ █ ▓ ▒ ░ ░ ▒ ▓ █ █ █ ▓ ░ | |
░ ▓ █ █ █ ▒ ░ ░ ▒ █ █ █ ▓ ░ | |
░ ▓ █ █ ▓ ▒ ▒ ▓ █ █ ▓ ░ | |
▓ █ █ ▓ ░ ░ ▓ █ █ ▓ | |
▒ █ █ █ ▒ ▒ █ █ █ ▒ | |
░ ▓ █ █ ▒ ▒ █ █ ▓ ░ | |
▒ █ █ ▓ ░ ░ ▓ █ █ ▒ | |
▓ █ █ ▒ ▒ █ █ ▓ | |
░ █ █ █ ░ ░ █ █ █ ░ | |
▒ █ █ ▓ ▓ █ █ ▒ | |
▒ █ █ ▒ ▒ █ █ ▒ | |
▓ █ █ ▒ ▒ █ █ ▓ | |
▓ █ █ ▒ X ▒ █ █ ▓ | |
▓ █ █ ▒ ▒ █ █ ▓ | |
▒ █ █ ▒ ▒ █ █ ▒ | |
▒ █ █ ▓ ▓ █ █ ▒ | |
░ █ █ █ ░ ░ █ █ █ ░ | |
▓ █ █ ▒ ▒ █ █ ▓ | |
▒ █ █ ▓ ░ ░ ▓ █ █ ▒ | |
░ ▓ █ █ ▒ ▒ █ █ ▓ ░ | |
▒ █ █ █ ▒ ▒ █ █ █ ▒ | |
▓ █ █ ▓ ░ ░ ▓ █ █ ▓ | |
░ ▓ █ █ ▓ ▒ ▒ ▓ █ █ ▓ ░ | |
░ ▓ █ █ █ ▒ ░ ░ ▒ █ █ █ ▓ ░ | |
░ ▓ █ █ █ ▓ ▒ ░ ░ ▒ ▓ █ █ █ ▓ ░ | |
▒ █ █ █ █ █ ▓ ▒ ░ ░ ▒ ▓ █ █ █ █ █ ▒ | |
░ ▓ █ █ █ █ █ █ █ ▓ ▓ ▓ █ █ █ █ █ █ █ ▓ ░ | |
░ ▓ ▓ █ █ █ █ █ █ █ █ █ █ █ ▓ ▓ ░ | |
░ ▒ ▓ ▓ ▓ ▓ ▓ ▓ ▓ ▒ ░ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
▒ ▓ ▓ ▓ ▓ ▓ ▒ | |
░ ▓ █ █ █ █ █ █ █ ▓ ░ | |
░ ▓ █ █ █ █ ▓ █ █ █ █ ▓ ░ | |
▓ █ █ ▓ ▒ ▒ ▓ █ █ ▓ | |
▒ █ █ █ ░ ░ █ █ █ ▒ | |
▒ █ █ ▓ ▓ █ █ ▒ | |
▓ █ █ ▒ X ▒ █ █ ▓ | |
▒ █ █ ▓ ▓ █ █ ▒ | |
▒ █ █ █ ░ ░ █ █ █ ▒ | |
▓ █ █ ▓ ▒ ▒ ▓ █ █ ▓ | |
░ ▓ █ █ █ █ ▓ █ █ █ █ ▓ ░ | |
░ ▓ █ █ █ █ █ █ █ ▓ ░ | |
▒ ▓ ▓ ▓ ▓ ▓ ▒ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment