Preface
This blog is mainly about using turtle to draw graphical paths for data read from files
Well, independent completion, show operation, tomorrow will be refueling ducks ...
Data
The data is a. txt file, a total of 9 lines, each row of the first column to indicate the turtle forward the number of pixels, the second column indicates the direction of rotation (0 to the left), the third column indicates the angle of rotation, leaving three columns to represent the RGB value, the data screenshot as follows:
The idea is to read the data from the file first, then draw the graph parameters based on the data read, control the brush drawing path Turtle
Code
#-*-Coding:utf-8-*-"" "Created on Sun has been a 12:46:37
2018
@author: Xuanxuan" ""
# This code is T o Draw a picture which the parameter are based on the data in the "Data.txt" file.
#元素1 represents the path forward pixel
#元素2 represents the rotation direction
#元素3 represents
the rotation angle #元素4 the RGB value that represents the drawing color from
Turtle Import Turtle
p=turtle ()
def Draw_path (line):
#p =turtle ()
p.pensize (3)
p.hideturtle ()
p.fd (line[0))
if Line[1]==0:
p.left (line[2])
else:
p.right (line[2))
P.color (line[3],line[4],line[5])
def main ():
infile=open ("Data.txt", "R") for line in
infile:
numbers=line.split (', ')
data=[] For number in
numbers:
data.append (float (number))
Draw_path (data)
main ()
Results
Why is it still not going to go up the map Ah ,,,,
nonsense
think more, practice more, find the feeling slowly
———————————————————————————— 're going to have a duck tomorrow .