1、根据实际图形,用符号画出原来图形

from PIL import Image import argparse #命令行输入参数处理 parser = argparse.ArgumentParser() parser.add_argument('file') #输入文件 parser.add_argument('-o', '--output') #输出文件 parser.add_argument('--width', type = int, default = 80) #输出字符画宽 parser.add_argument('--height', type = int, default = 80) #输出字符画高 #获取参数 args = parser.parse_args() IMG = args.file WIDTH = args.width HEIGHT = args.height OUTPUT = args.output ascii_char = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. ") # 将256灰度映射到70个字符上 def get_char(r,g,b,alpha = 256): if alpha == 0: return ' ' length = len(ascii_char) gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b) unit = (256.0 + 1)/length return ascii_char[int(gray/unit)] if __name__ == '__main__': im = Image.open(IMG) im = im.resize((WIDTH,HEIGHT), Image.NEAREST) txt = "" for i in range(HEIGHT): for j in range(WIDTH): txt += get_char(*im.getpixel((j,i))) txt += '\n' print txt #字符画输出到文件 if OUTPUT: with open(OUTPUT,'w') as f: f.write(txt) else: with open("output.txt",'w') as f: f.write(txt)

运行命令:

python ascii.py ascii_dora.png

python 画图的更多相关文章

  1. python画图—黑板客老师课程学习

    1.介绍 把每个图都看作一个对象,图中的每一个部分也是对象.——所有的一切都是对象. 工具——ipython notebook 是python里边用的最多的2D&3D的会图库,开源免费库,使用 ...

  2. Python画图笔记

    matplotlib的官方网址:http://matplotlib.org/ 问题 Python Matplotlib画图,在坐标轴.标题显示这五个字符 ⊥ + - ⊺ ⨁,并且保存后也能显示   h ...

  3. Python画图matplotlib展示图中中文乱码

    在用python的 matplotlib 画图的时候,在图表上面有中文乱码问题,如下的: 解决过程: 平台:windows,python2.7步骤一:打开设置文件 import matplotlib ...

  4. python画图设置坐标轴大小

    在console端输入python语句,会一句输一行,而且不保留你所做的操作,但是每一句之间加一个分号就能很好的解决. import pylab as Plot Plot.xlim(-150, 150 ...

  5. python 画图工具matplotlib 去掉坐标轴和坐标的方法

    1. 去掉坐标轴的方法: plt.axis('off') 2.去掉刻度的方法: plt.xticks([]) plt.yticks([]) 以上语句需要将其置于 plt.show() 之前,plt.i ...

  6. 数字的可视化:python画图之散点图sactter函数详解

    最近开始学习python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下: 1.scatter函数原型 2.其中散点的形状参数marker如下: 3.其中颜色参数c如 ...

  7. Python画图工具matplotlib的安装

    今天在机子上安装matplotlib遇到一些问题,特将此记录下来,供大家分享以少走弯路. 1:下载matplotlib 去官网上下载你所须要的版本号http://matplotlib.org/down ...

  8. linux 使用 Python 画图工具matplotlib 提示display 错误

    import matplotlib.pyplot as plt Traceback (most recent call last): File "<stdin>", l ...

  9. python画图matplolib

    http://python.jobbole.com/85106/ 1.画二维图 2.画三维图 我的电脑只能在jupyter notebook上面运行才能看的到,常规import库 %matplotli ...

随机推荐

  1. Platform 获取主机系统信息

    该模块用来访问平台相关属性. 常见属性和方法 1. import platform(pip install platform)   2.获取操作系统名称及版本号 def get_platform(): ...

  2. 在mac上面运行cherrytree

    下载源码包 wget http://www.giuspen.com/software/cherrytree-0.38.4.tar.xz 解压 tar -xvf cherrytree-0.38.4.ta ...

  3. PAT 1137 Final Grading

    For a student taking the online course "Data Structures" on China University MOOC (http:// ...

  4. 微信小程序-template模板

    ============================= 构建template模板                    ============================= 1.分析得出共为 ...

  5. PM2 & chmod +x

    PM2 https://www.npmjs.com/package/pm2 https://github.com/Unitech/pm2 docs https://pm2.io/doc/en/runt ...

  6. Uva1103 Ancient Messages

    题意:识别图中的象形文字.但是,图形可以任意的拉伸,但不能拉断. 分析:这种题如果图形没有特征是不可做类型的题,不过观察图形可以发现每个图形中的洞的数量是一定的,我们只需要数出每一个封闭图形的洞数就能 ...

  7. 1874 Bellman-ford算法 队列优化过的 用于稀疏图,有负权的图

    #include<stdio.h> #include<algorithm> #include<iostream> #include<queue> usi ...

  8. SGU - 321 - The Spy Network

    先上题目: 321. The Spy Network Time limit per test: 0.5 second(s)Memory limit: 65536 kilobytes input: st ...

  9. Inversion

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4176   Accepted: 1857 Description The i ...

  10. xcode5下取消ARC

    打开你的工程,点击目录的工程文件,最顶端蓝色的,然后选择project下你的工程,还是蓝色那项,然后build Settings,然后往下拉,在Apple LLVM 5.0 - Language - ...