七夕如何向心爱的ta表白,看这里
软件测试test
共 4201字,需浏览 9分钟
·
2020-08-25 08:56
敲重点啦!
代码贴上:
(1)代码中的图形颜色,文字内容均可自己按照需求更改,是不是简单而又不失高级
import turtle
import random
def love(x, y): # 在(x,y)处画爱心
lv = turtle.Turtle()
lv.hideturtle()
lv.up()
lv.goto(x, y) # 定位到(x,y)
def curvemove(): # 画圆弧
for i in range(20):
lv.right(10)
lv.forward(2)
lv.color('red', 'pink')
lv.speed(10000000)
lv.pensize(1)
# 开始画爱心lalala
lv.down()
lv.begin_fill()
lv.left(140)
lv.forward(22)
curvemove()
lv.left(120)
curvemove()
lv.forward(22)
lv.write("xxx", font=("Arial", 12, "normal"), align="center") # 写上要表白的人的名字
lv.left(140) # 画完复位
lv.end_fill()
def tree(branchLen, t):
if branchLen > 5: # 剩余树枝太少要结束递归
if branchLen < 20: # 如果树枝剩余长度较短则变绿
t.color("green")
t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))
t.down()
t.forward(branchLen)
love(t.xcor(), t.ycor()) # 传输现在turtle的坐标
t.up()
t.backward(branchLen)
t.color("brown")
return
t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))
t.down()
t.forward(branchLen)
# 以下递归
ang = random.uniform(15, 45)
t.right(ang)
tree(branchLen - random.uniform(12, 16), t) # 随机决定减小长度
t.left(2 * ang)
tree(branchLen - random.uniform(12, 16), t) # 随机决定减小长度
t.right(ang)
t.up()
t.backward(branchLen)
myWin = turtle.Screen()
t = turtle.Turtle()
t.hideturtle()
t.speed(1000)
t.left(90)
t.up()
t.backward(200)
t.down()
t.color("brown")
t.pensize(32)
t.forward(60)
tree(100, t)
myWin.exitonclick()
看看效果:
第二种,制作一朵玫瑰花,代码易懂,用python标准库turtle一步步画图,完成之后用屏幕录制gif工具生成动图就完成了。
代码贴上:
import turtle
import time
# writing txt
turtle.hideturtle()
turtle.penup()
turtle.goto(80, 50)
# turtle.pendown()
turtle.color("purple")
time.sleep(1)
#XX同学可以改为你自己的表白对象
turtle.write("xxx给你画个东西", font=("Times", 18, "bold"))
time.sleep(0.5)
turtle.goto(180, 10)
turtle.write("马上开始咯", font=("Times", 18, "bold"))
time.sleep(0.5)
turtle.goto(200, -20)
turtle.write("Ready?", font=("Times", 18, "bold"))
time.sleep(0.5)
turtle.goto(215, -50)
turtle.write("go!", font=("Times", 18, "bold"))
time.sleep(0.5)
# turtle.end_fill()
#
# 设置初始位置
turtle.goto(0, 0)
turtle.color("black")
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
# 花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10, 180)
turtle.circle(25, 110)
turtle.left(50)
turtle.circle(60, 45)
turtle.circle(20, 170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30, 110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90, 70)
turtle.circle(30, 150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80, 90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150, 80)
turtle.left(50)
turtle.circle(150, 90)
turtle.end_fill()
# 花瓣1
turtle.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(60)
turtle.circle(80, 98)
turtle.circle(-90, 40)
# 花瓣2
turtle.left(180)
turtle.circle(90, 40)
turtle.circle(-80, 98)
turtle.setheading(-83)
# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80, 90)
turtle.right(90)
turtle.circle(-80, 90)
turtle.end_fill()
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
# 叶子2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80, 90)
turtle.left(90)
turtle.circle(80, 90)
turtle.end_fill()
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200, 60)
time.sleep(0.5)
turtle.penup()
turtle.color("orange")
turtle.goto(180, -100)
turtle.write("把我~送给你~", font=("Times", 18, "bold"))
turtle.goto(180, -120)
turtle.write("七夕快乐!", font=("Times", 18, "bold"))
time.sleep(10)
看效果:
屏幕录制工具我用的 licecapGIF,很强大,录制出来的像素很高体积很小
下载地址我也放这里,需要的可以直接下载使用哈
链接:https://pan.baidu.com/s/1p2i8T6lzRSj3ktE4E20y2Q
提取码:w66e
最后愿每个IT人都有温暖的另一半呀!
评论