Dynamic path drawing in window based on data file

#Draw the dynamic path in the window according to the data file
import turtle


def main(): #Set the
    window information
    turtle.title('Data-driven dynamic path drawing')
    turtle.setup(800,600,0,0) #Set the
    brush
    pen=turtle .Turtle()
    pen.color("red")
    pen.width(5)
    pen.shape("turtle")
    pen.speed(5) #Read
    the file
    result=[]
    file=open("data.txt", "r")
    for line in file:
        result.append(list(map(float,line.split(','))))
    print(result) #Dynamic
    drawing
    for i in range(len(result)):
        pen. color((result[i][3],result[i][4],result[i][5]))#The rgb value of the color
        pen. fd(result[i][0])#path length
        if result[i][1]:#Rotation direction, 0 left and 1 right
            pen.rt(result[i][2])#Rotation angle
        else:
            pen.lt(result[i][2])
    pen.goto( 0,0)

main()

'''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,0,0,0
184,1, 72,0,0,0
184,1, 72,0,0,0
184,1, 72,0,0,0
184,1, 72,0,0,0'''

Guess you like

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