一、turtle基本语法
1.导入turtle 模块
import turtle
2.显示箭头
turtle.showturtle()
3.写字符串
turtle.write("因小米")
4.前进100 像素
turtle.forward(100)
5.画笔颜色改为red
turtle.color("red")
6.箭头左转90 度
turtle.left(90)
7.箭头右转45 度
turtle.right(45)
8.去坐标点(0,50)处
turtle.goto(0,50)
9.抬笔,这样,路径就不会画出来
turtle.penup()
10.落笔,这样,路径就会画出来
turtle.pendown()
11.画圆,半径为100
turtle.circle(100)
二、turtle实例1螺旋线
具体代码如下:
1 import turtle 2 3 t = turtle.Pen() 4 for x in range(360): 5 t.forward(x) 6 t.left(59)
python简单几行代码即可完成上图的螺旋线
注意:不要在程序中,行开头处增加空格。空格在Python 中有缩进的含义。
三、turtle实例2奥运五环
具体代码如下:
1 #绘制奥运五环 2 import turtle 3 4 turtle.width(10) 5 6 turtle.color("blue") 7 turtle.circle(50) 8 9 turtle.color("black") 10 turtle.penup()#抬笔 11 turtle.goto(120,0) 12 turtle.pendown()#落笔 13 turtle.circle(50) 14 15 turtle.color("red") 16 turtle.penup() 17 turtle.goto(240,0) 18 turtle.pendown() 19 turtle.circle(50) 20 21 turtle.color("yellow") 22 turtle.penup() 23 turtle.goto(60,-50) 24 turtle.pendown() 25 turtle.circle(50) 26 27 turtle.color("green") 28 turtle.penup() 29 turtle.goto(180,-50) 30 turtle.pendown() 31 turtle.circle(50)