Draw a graphical path using turtle based on the data read from the file

Source: Internet
Author: User
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 .

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.