2018年6月12日笔记
pendown()
forward(100)
pendown()的作用是落笔,只有落笔才能作画。 当不作画却想移动画笔的时候要提笔,用函数penup() forward是画笔向前移动,函数当中参数为移动距离。 forward(100)的意思是画笔向前移动100。
for i in range(4):
forward(200)
right(90)
def draw1():
reset()
speed(10)
for i in range(36):
forward(200)
left(170)
reset()
speed(10)
draw1()
speed()中的参数1-10画图速度递增,但是有一个反例参数为0时速度最快。 reset()会重置画笔,画布,作画速度。
reset()
fillcolor('red')
begin_fill()
circle(100,180)
end_fill()
8.复杂图形涂色示例,画一个“太极”图案。
reset()
speed(10)
pendown()
circle(100,180)
circle(200,180)
circle(100,-180)
fillcolor('black')
begin_fill()
circle(100,180)
circle(200,180)
circle(100,-180)
end_fill()
penup()
goto(0,100)
dot(50)
goto(0,-100)
pencolor('white')
dot(50)
hideturtle()
circle(100)与circle(100,360)两条命令效果相同。 撤回一步:undo(),清空画布:clear()。
画出的太极图形.png
for i in range(8):
circle(20,100)
circle(-20,100)
from turtle import *
reset()
speed(0)
pendown()
for i in range(6):
fd(150)
for j in range(10):
circle(40)
lt(36)
lt(60)
复杂图形1.png
from turtle import *
reset()
speed(0)
for i in range(6):
pendown()
fd(150)
for j in range(10):
circle(40)
lt(36)
lt(60)
penup()
goto(0,0)
复杂图形2.png
reset()
setheading(45)
circle(10,90)
circle(90,90)
circle(10,90)
circle(90,90)
14.画一个笑脸。下面的代码作为一个单独py文件可以运行。
from turtle import *
def go(x,y):
penup()
goto(x,y)
pendown()
def arc(radius):
circle(radius,90)
reset()
speed(0)
go(0,-150)
circle(200)
go(50,100)
seth(225)
arc(10)
arc(50)
arc(10)
arc(50)
go(-50,100)
seth(-45)
arc(-10)
arc(-50)
arc(-10)
arc(-50)
go(-70,-50)
arc(100)
hideturtle()
笑脸.png
直接在cmd中可能无法运行,需要先定义函数,再调用函数,如下图所示,。
cmd中运行示例.png
from turtle import *
reset()
bgcolor('black')
speed(0)
colors = ['red','orange','green','cyan','blue','purple']
for i in range(360):
pencolor(colors[i%6])
fd(i*3/6+i)
left(61)
pensize(i*6/200)
炫酷图案.png