母亲节到了,为了庆祝母亲节我做了这个程序。
这个程序用到了turtle画图库了的很多指令,大家可以学一学!
1.首先先导入库
import turtle
import time
import random
2. 创建小海龟t1
t1 = turtle.Turtle()
t1.pensize(3)
t1.shape("turtle")
t1.speed(0)
3.# 绘制小人
# 绘制小人
# 头
t1.circle(30)
# 右眼
t1.penup()
t1.goto(10, 30)
t1.left(90)
t1.pendown()
t1.forward(10)
# 左眼
t1.penup()
t1.goto(-10, 30)
t1.pendown()
t1.forward(10)
# 身体和腿
t1.penup()
t1.goto(0, 0)
t1.pendown()
t1.left(180)
t1.forward(80)
t1.right(45)
t1.forward(60)
t1.backward(60)
t1.left(135)
t1.forward(60)
t1.right(90)
t1.forward(40)
# 手
t1.penup()
t1.goto(0, -20)
t1.pendown()
t1.left(90)
t1.forward(60)
t1.left(45)
t1.forward(10)
# 另一只手
t1.penup()
t1.goto(0, -30)
t1.pendown()
t1.right(45)
t1.forward(60)
t1.right(45)
t1.forward(10)
5.显示文字
t1.penup()
t1.goto(80, 30)
t1.pendown()
t1.write("送你小心心~~~", font=("微软雅黑", 15))
6.初始化t2
t2=turtle.Turtle()
t2.ht()
turtle.tracer(False)
numlist = [100]
colorlist = ["red", "yellow", "blue", "pink", "orange", "grey",
"silver", "purple", "black"]
t2.speed(0)
7.最后让海龟发射爱心
while True:
if numlist[0]>100 and numlist[0]%100==0:
numlist.append(100)
if numlist[0]>500:
numlist.pop(0)
t2.clear()
for i in numlist:
coloridx = random.choice(colorlist)
t2.color(coloridx)
a = random.randint(-10,10)
t2.penup()
t2.goto(i,-10+a)
t2.begin_fill()
t2.pendown()
t2.setheading(90)
t2.circle(10,180)
t2.circle(30,70)
t2.penup()
t2.goto(i,-10+a)
t2.pendown()
t2.setheading(90)
t2.circle(-10,180)
t2.circle(-30,70)
t2.end_fill()
idx = numlist.index(i)
numlist[idx]+=10
turtle.update()
turtle.done()
这一个是一个无限循环的,如果想要用for循环,大伙是可以改的。点赞并关注这件事可不要忘了哦!