python绘制一个会长玫瑰的爱心

python画爱心也许是程序员浪漫的最初级吧,那作为程序员小白的我,会一点python的turtle库,就简简单单画了一个爱心,欢迎大家来参观!!👏👏👏👏

step1(准备好画笔和画布):

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()

step2(开始画爱心轮廓并填充)

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()

step3( 写上I love you )

turtle.pencolor("red")
turtle.write("LOVE YOU ", align="center", font=('Futura', 35, "bold"))

step4(开始长玫瑰)

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"))

end


​​​​​​​

 

  • 5
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Freshman小白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值