码迷,mamicode.com
首页 > 编程语言 > 详细

Python - Turtle Graphics

时间:2016-04-04 01:21:07      阅读:489      评论:0      收藏:0      [点我收藏+]

标签:

 1 import turtle            #allows us to use the turtles library
 2 wn = turtle.Screen()    #creates a graphics window
 3 wn.bgcolor("lightgreen")#set the window background color
 4 
 5 alex = turtle.Turtle()    #create a turtle named alex
 6 alex.pensize(3)            #set the width of her pen
 7 alex.color("pink")        #make alex pink color is attribute
 8 alex.forward(150)        #tell alex to move forward by 150 units
 9 alex.left(90)            #turn by 90 degrees, right is clockwise, left is counter clockwise
10 alex.forward(75)        #complete the second side of a rectangle
11 alex.left(90)            
12 alex.forward(150)
13 alex.left(90)
14 alex.forward(75)
15 
16 tess = turtle.Turtle()
17 tess.color("hotpink")
18 tess.pensize(5)
19 
20 tess.forward(150)
21 tess.left(120)
22 tess.forward(150)
23 tess.left(120)
24 tess.forward(150)
25 
26 david = turtle.Turtle()
27 david.color("blue")
28 david.pensize(5)
29 
30 for i in ["yellow", "red", "purple", "blue"]:
31     david.color(i)
32     david.forward(150)
33     david.left(90)
34 
35 wn.exitonclick()        #wait for a user click on the canvas

 

技术分享

 

Python - Turtle Graphics

标签:

原文地址:http://www.cnblogs.com/elewei/p/5351199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!