标签:open demo text odi asc port str turn 等于
from PIL import Image
def main():
for a in range(0, 100):
print(a)
if a < 10:
pic = "001 - 2333000" + str(a) + ".jpg"
if a >= 10 and a < 100:
pic = "001 - 233300" + str(a) + ".jpg"
if a >= 100 and a < 1000:
pic = "001 - 23330" + str(a) + ".jpg"
if a >= 1000:
pic = "001 - 2333" + sta(a) + ".jpg"
# 0000
# 10个字符表示按“灰度级别”从高到低排序
asciis = "@%#*+=-:. "
# 设置缩放系数
zoom = 1
# 设置垂直比例系数
vscale = 1
texts = pic2ascii(pic, asciis, zoom, vscale)
with open(str(a)+".txt", "w") as file:
file.write(texts)
def pic2ascii(pic_, asciis, zoom, vscale):
img = Image.open(pic_)
# 打开图片并转换为灰度模式
out = img.convert("L")
# 获取图片的宽度和高度
width, height = out.size
# 由于字符的宽度并不会等于高度,所以需要进行调整
out = out.resize((int(width * zoom), int(height * zoom * vscale)))
ascii_len = len(asciis)
texts = ‘‘
for row in range(out.height):
for col in range(out.width):
gray = out.getpixel((col, row))
texts += asciis[int((gray / 255) * (ascii_len - 1))]
texts += ‘\n‘
return texts
if __name__ == "__main__":
main()
import sys
from time import sleep
for a in range(0, 1477):
#################
sleep(0.1)#注入灵魂,画面稳定
#################
with open(str(a) + ‘.txt‘,‘r‘,encoding=‘utf-8‘) as f:
for line in f.readlines():
# end=‘‘控制文本中换行时不读取出换行号
print(line,end=‘‘)
# 定义列表
ls = ["sunny","dghahdfg"]
with open(‘demo.txt‘,‘a‘,encoding=‘utf-8‘) as f:
for line in ls:
f.write(‘{}\n‘.format(line))
标签:open demo text odi asc port str turn 等于
原文地址:https://www.cnblogs.com/Little-Turtle--QJY/p/13333903.html