首页 > 编程语言 >用python根据文本数据自动绘制轨迹

用python根据文本数据自动绘制轨迹

时间:2022-11-28 23:02:02浏览次数:47  
标签:轨迹 python detals 300 72 184 line 文本 绘制

1.具体步骤

1.1导包

import turtle as t

1.2设置基本参数

t.title('自动轨迹绘制')
t.setup(800,600,0,0)
t.pencolor('red')
t.pensize(5)

1.3数据读取

#数据读取
detals=[]
f=open('a.txt')
for line in f:
    line = line.replace('\n','')
    detals.append(list(map(eval,line.split(','))))
f.close()

1.4自动绘制

#自动绘制
for i in range(len(detals)):
    t.pencolor(detals[i][3],detals[i][4],detals[i][5])
    t.fd(detals[i][0])
    if detals[i][1]:
        t.right(detals[i][2])
    else:
        t.left(detals[i][2])

2.完整代码

import turtle as t
t.title('自动轨迹绘制')
t.setup(800,600,0,0)
t.pencolor('red')
t.pensize(5)
#数据读取
detals=[]
f=open('a.txt')
for line in f:
    line = line.replace('\n','')
    detals.append(list(map(eval,line.split(','))))
f.close()
#自动绘制
for i in range(len(detals)):
    t.pencolor(detals[i][3],detals[i][4],detals[i][5])
    t.fd(detals[i][0])
    if detals[i][1]:
        t.right(detals[i][2])
    else:
        t.left(detals[i][2])

3.数据

300,0,144,1,0,0
300,0,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,1,72,1,0,1
184,1,72,0,0,0
184,1,72,0,0,0
184,1,72,0,0,0
184,1,72,0,0,0
184,1,720,0,0,0

标签:轨迹,python,detals,300,72,184,line,文本,绘制
From: https://blog.51cto.com/husheng/5893766

相关文章