python画爱心也许是程序员浪漫的最初级吧,那作为程序员小白的我,会一点python的turtle库,就简简单单画了一个爱心,欢迎大家来参观!!
import turtle
turtle.bgcolor("lightblue")
a = turtle.Pen()
b = turtle.Pen()
a.speed(100)
b.speed(100)
a.color("pink", "pink")
b.color("pink", "pink")
a.pensize(5)
b.pensize(5)
a.hideturtle()
b.hideturtle()
a.sety(100)
b.sety(100)
a.pendown()
b.pendown()
x = 0
a.begin_fill()
b.begin_fill()
for i in range(100):
x += 2
y = -(17/4000)*x*(x-200)+100#这可是我自己用几何绘图器摸索出的函数再拼接起来
a.goto(x, y)
b.goto(-x, y)
for j in range(147):
y -= 2
x = -14/4000*y*(y-100)+200
a.goto(x, y)
b.goto(-x, y)
a.end_fill()
b.end_fill()
turtle.pencolor("red")
turtle.write("LOVE YOU ", align="center", font=('Futura', 35, "bold"))
for i in range(2000):
rx = random.uniform(-200.0, 200.0)
ry = random.uniform(-350.0, 200.0)
if ry >= 0:
if (abs(rx) <= 200) and (ry <= -(17/4000)*rx*(rx-200)+80):
a.penup()
a.goto(2*(i % 2-0.5)*rx, ry)
a.pendown()
a.write("️", align="center", font=("Futura", 35, "bold"))
elif ry >= -300 and (abs(rx) <= -14/4000*ry*(ry-100)+200):
a.penup()
a.goto(rx, ry)
a.pendown()
a.write("️", align='center', font=("Futura", 30, "bold"))