[Python] txt file to read painting

import turtle as t #painting library 
t.title('automatic trajectory drawing')
#title t.setup(800,600,0,0)
t.pencolor('red')
t.pensize(5) #data
read
datals = [ ] #Data list in order to extract
f = open('C:/Users/eternal/data.txt') #data.txt is opened and named file handle named f, the default is read-only
for line in f: # with each line line Extract
line = line.replace('\n','') # and replace the Enter key with a null character, then assign it to line
datals.append(list(map(eval,line.split(',') ))) #Add to the data list, separate the line into a list with commas ---> Use the eval and map functions to directly convert the elements in the list into data ---> Then use the list function to turn it into a list
f .close() #Here, line.split(',') is a list with strings as elements, but after being modulated by map and eval, it becomes a bunch of garbled characters that cannot be understood by individuals, and then it becomes a bunch of garbled characters after the list function. A list with data as elements
for i in range(len(datals)):
t.pencolor(datals[i][3],datals[i][4],datals[i][5]) #Pencil color is below Labeled as 345 added RGB
t.fd(datals[i][0]) #The subscript is 0 is the moving distance
if datals[i][1]: #Subscript 1 is to judge whether to turn left or right
t.right(datals[i][2]) #Subscript 2 is the angle of turning
else:
t.left(datals [i][2])
#------------------------------------data file

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325304717&siteId=291194637