学习目标:
快速掌握和老婆表白的技巧学习内容:
1、 学习python中turtle库的用法
2、 掌握 turtle 基本语法
学习产出:
1、 画笔控制
绘图状态
pendown() | pd() | down() 画笔落下
penup() | pu() | up() 画笔抬起
pensize() | width() 画笔粗细
pen() 画笔
isdown() 画笔是否落下
颜色控制
color() 颜色
pencolor() 画笔颜色
fillcolor() 填充颜色
填充
filling() 是否填充
begin_fill() 开始填充
end_fill() 结束填充
更多绘图控制
reset() 重置
clear() 清空
write() 书写
2、海龟动作
移动和绘制
forward() | fd() 前进
backward() | bk() | back() 后退
right() | rt() 右转
left() | lt() 左转
goto() | setpos() | setposition() 前往/定位
setx() 设置x坐标
sety() 设置y坐标
setheading() | seth() 设置朝向
home() 返回原点
circle() 画圆
dot() 画点
stamp() 印章
clearstamp() 清除印章
clearstamps() 清除多个印章
undo() 撤消
speed() 速度
获取海龟的状态
position() | pos() 位置
towards() 目标方向
xcor() x坐标
ycor() y坐标
heading() 朝向
distance() 距离
设置与度量单位
degrees() 角度
radians() 弧度
3、开始编写可以画爱心的代码
代码示例:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from turtle import *
import time
def 画心():
speed(10)
up()
goto(0,-231.88)
pd()
color('red')
begin_fill()
lt(140)
fd(265.0)
circle(-143.72,180)
lt(84.11)
circle(-143.72,180)
fd(265.0)
end_fill()
ht()
up()
goto(-130,251.88)
if __name__ == '__main__':
bgcolor('#f4c696')#'PaleGoldenrod'
画心()
speed(10)
write('芝士先生爱小仙女',font=('楷体',20,'normal'))
time.sleep(1)
goto(-200,0)
speed(10)
pencolor('Snow')
write('结婚两周年快乐',font=('楷体',40,'normal'))
pencolor('OrangeRed')
goto(-200,-260)
write('早上窗帘没拉好,',font=('楷体',20,'normal'))
goto(-200,-290)
write('我可以看到你和阳光都在,',font=('楷体',20,'normal'))
goto(-200,-320)
write('我便感觉这一天都特别温暖~~~',font=('楷体',20,'normal'))
mainloop()
执行后的效果如下:

1233

被折叠的 条评论
为什么被折叠?



