七夕情人节
又双叒叕到了一年一度的中国传统情人节——七夕,那么思考一下自己有对象了吗,是否还是单身,或者想清楚怎么跟心动的ta表达心意了吗?不知道,那来看看如何利用我们的技能让女神男神刮目相看吧,说不定最后就眉目传情,就有对象了。有对象的拿去跟对象表达爱也是可以的。
敲重点啦!
代码贴上:
(1)代码中的图形颜色,文字内容均可自己按照需求更改,是不是简单而又不失高级
import turtleimport randomdef 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)# 开始画爱心lalalalv.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")returnt.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 turtleimport time# writing txtturtle.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()# 花瓣1turtle.left(150)turtle.circle(-90, 70)turtle.left(20)turtle.circle(75, 105)turtle.setheading(60)turtle.circle(80, 98)turtle.circle(-90, 40)# 花瓣2turtle.left(180)turtle.circle(90, 40)turtle.circle(-80, 98)turtle.setheading(-83)# 叶子1turtle.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)# 叶子2turtle.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,很强大,录制出来的像素很高体积很小
下载地址我也放这里,需要的可以直接下载使用哈
链接:/s/1p2i8T6lzRSj3ktE4E20y2Q
提取码:w66e
最后愿每个IT人都有温暖的另一半呀!
end
测试自动化框架的重要性– iSAFE的优势
Selenium 4.0-最新的测试自动化工具
增加并行测试的好处
API测试| 了解API接口测试| API接口测试指南