py.turtle自动绘图&文本添加行号
Posted ZSYL
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了py.turtle自动绘图&文本添加行号相关的知识,希望对你有一定的参考价值。
py.turtle自动绘图&文本添加行号
py.turtle自动绘图
data.txt
300,1,144,1,0,0
300,1,144,0,1,0
300,0,144,0,0,1
300,0,144,1,1,0
300,0,108,0,1,1
184,0,72,1,0,1
184,0,72,0,0,0
184,0,72,0,0,0
184,0,72,0,0,0
184,0,72,1,0,1
184,1,72,0,0,0
184,1,72,0,0,0
184,1,72,0,0,0
184,0,72,0,0,0
184,1,720,0,0,0
# coding=utf-8
import turtle as t
t.setup(800, 800, 0, 0)
t.pensize(5)
t.speed(8)
lines = []
newLines = []
with open("data.txt", "r") as f:
lines = f.readlines()
for line in lines:
line = line.replace("\\n", "").split(",")
newLines.append(line)
for i in range(len(newLines)):
t.pencolor(int(newLines[i][3]), int(newLines[i][4]), int(newLines[i][5]))
t.fd(int(newLines[i][0]))
if newLines[i][1]:
t.lt(int(newLines[i][2]))
else:
t.rt(int(newLines[i][2]))
t.penup()
t.fd(100)
t.hideturtle()
t.pendown()
t.write("帅9091", font=("Arial", 16, "normal"))
t.done()
文本添加行号
#coding=gbk
# 给文件添加行号
lines = []
with open("帅-9091.txt", "r",encoding='gbk') as f:
lines = f.readlines()
lines = enumerate(lines) # 给列表上序号,变为元祖
lines = list(lines) # 将enumerate对象转化为列表
# 将加入行号的内容输出到new文件中
with open("帅-9091new.txt", "w",encoding='utf-8') as f:
for i in range(len(lines)):
line = lines[i][1].replace("\\n", "") # 获取第i行数据
line = "第"+str(i+1)+"行: " + line+"\\n"
f.writelines(line)
很久前的小代码!
以上是关于py.turtle自动绘图&文本添加行号的主要内容,如果未能解决你的问题,请参考以下文章
R语言应用calibrate包的textxy函数向R原生绘图结果中添加文本标签:添加多个文本标签改变文本标签的字体改变文本标签的字体颜色