Today is Valentine's Day, I will send you a set of exclusive Python code, it seems a little late... But it doesn't matter, you can save it for next time (manual dog head)
Rose
Part of the code is implemented as follows:
# 花瓣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)
Effect:
love tree
Part of the code is implemented as follows:
# 画爱心
def love(x, y):
lv = turtle.Turtle()
lv.hideturtle()
lv.up()
# 定位
lv.goto(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)
lv.down()
lv.begin_fill()
lv.left(140)
lv.forward(22)
curvemove()
lv.left(120)
curvemove()
lv.forward(22)
# 画完复位
lv.left(140)
lv.end_fill()
Effect:
Cupid
Part of the code is implemented as follows:
t.color('red','pink')
t.begin_fill()
t.width(5)
t.left(135)
t.fd(100)
t.right(180)
t.circle(50,-180)
t.left(90)
t.circle(50,-180)
t.right(180)
t.fd(100)
t.pu()
t.goto(50,-30)
t.pd()
t.right(90)
t.fd(100)
t.right(180)
t.circle(50,-180)
t.left(90)
t.circle(50,-180)
t.right(180)
t.fd(100)
t.end_fill()
t.hideturtle()
t.pu()
t.goto(250,-70)
t.pd()
Effect:
colorful balloons
Part of the code is implemented as follows:
# 气球
balloons = []
# 颜色
color_option = ["red", "blue", "green", "purple", "pink", "yellow", "orange"]
# 气球大小
size = 50
# 气球线
def line(x, y, a, b, line_width=1, color_name="black"):
up()
goto(x, y)
down()
color(color_name)
width(line_width)
goto(a, b)
def distance(x, y, a, b):
# 判断鼠标点击位置和气球坐标的距离
return ((a - x) ** 2 + (b - y) ** 2) ** 0.5
def tap(x, y):
for i in range(len(balloons)):
# 判断是否点击气球队列中的其中一个
if distance(x, y, balloons[i][0], balloons[i][1]) < (size / 2):
# 删除气球
balloons.pop(i)
return
Effect:
The source code is obtained in the public number Python second background reply 20220214 ~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。