代码段:
import turtle as t
def main() :
t.setup(1024,768,0,0)
t.pencolor("red")
t.width(5)
t.speed(5)
result=[]
file = open("data.txt","r",encoding='utf-8-sig')
for line in file:
result.append(list(map(float, line.split(","))))
print(result)
for i in range(len(result)):
t.pencolor(result[i][3], result[i][4], result[i][5])
t.forward(result[i][0])
if result[i][1]:
t.rt(result[i][2])
else:
t.lt(result[i][2])
t.goto(0,0)
if __name__=='__main__':
main()
t.mainloop()
data.txt
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
300,0,216,1,0,0
300,1,144,0,1,0
300,1,144,0,0,1
300,1,144,1,1,0
300,1,108,0,1,1
184,1,72,1,0,1
184,1,72,0,0,0
184,1,72,0,0,0
184,0,72,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,0,108,1,0,1
300,0,36,1,0,0
300,0,144,0,1,0
300,0,144,0,0,1
300,0,144,1,1,0
300,0,144,0,1,1
300,1,144,0,1,1
184,1,0,1,0,1
300,1,144,1,0,0
300,1,144,0,1,0
300,1,144,0,0,1
300,1,144,1,1,0
300,1,108,0,1,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
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,1,144,0,1,1
184,1,72,1,0,1
184,1,72,1,0,1
184,1,72,1,0,1
184,0,36,1,0,1
运行结果:
可能是电脑屏幕太小啦?