其他分享
首页 > 其他分享> > 中秋佳节,来个月饼

中秋佳节,来个月饼

作者:互联网

 


from PIL import Image
import sys

img = Image.open("mooncake.png")
gray_img = img.convert('L')
width    = img.width
height   = img.height
scale    = width // 130
char_lst = ' .:-=+*#%@'
char_len = len(char_lst)

for y in range(0, height, scale):
    for x in range(0, width, scale):
        choice =gray_img.getpixel((x, y)) * char_len // 255
        if choice==char_len:
            choice=char_len-1
        sys.stdout.write(char_lst[choice])
    sys.stdout.write('\n')
    sys.stdout.flush()

标签:sys,中秋佳节,月饼,img,来个,len,choice,char,width
来源: https://www.cnblogs.com/devbobcorn/p/happy-mid-autumn-festival.html