python浪漫表白源码
作者:咸鱼爱上猫 时间:2023-11-22 05:16:39
要知道我们程序猿也是需要浪漫的,小博我之前在网上搜寻了很多代码,确发现好多都不是最新的,所以自己就整理了一下代码,现在与广大博友们分享下
我们需要用到的包
使用pip install +(包名)
turtle 2.random
程序源码
# Project Leader:刘
# Project:表白源码
import turtle
import random
def love(x,y):#在(x,y)处画爱心lalala
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("名字",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()
运行效果
来源:https://blog.csdn.net/weixin_43292457/article/details/84671149
标签:python,表白,源码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Protocol Buffers的C语言拓展提速Python程序的示例
2022-12-04 08:46:20
Js中var,let,const的区别你知道吗
2024-05-09 15:07:50
微信小程序之数据缓存的实例详解
2024-04-19 09:49:53
![](https://img.aspxhome.com/file/2023/8/136128_0s.png)
菜鸟课堂:玩转MySQL数据库 性能优化八法
2009-03-25 14:44:00
Python实战之实现简易的学生选课系统
2023-10-07 02:49:37
![](https://img.aspxhome.com/file/2023/6/110206_0s.png)
MySQL Innodb表导致死锁日志情况分析与归纳
2024-01-27 04:04:42
![](https://img.aspxhome.com/file/2023/1/98391_0s.png)
asp函数收藏
2009-04-21 13:10:00
MySQL 表数据的导入导出操作示例
2024-01-18 17:20:19
古老的问题:清除浮动
2009-02-12 11:21:00
python 2.6.6升级到python 2.7.x版本的方法
2022-09-25 15:07:45
Python打印输出数组中全部元素
2022-08-07 19:35:12
如何使用分区处理MySQL的亿级数据优化
2024-01-21 04:49:01
MySQL的双机热备份安装和配置
2012-01-05 19:00:58
如何正确显示模式对话框showModalDialog中的中文?
2010-06-28 18:24:00
Python监控服务器实用工具psutil使用解析
2021-10-14 03:16:24
Python中顺序表的实现简单代码分享
2022-08-31 22:26:36
![](https://img.aspxhome.com/file/2023/1/115141_0s.png)
python类装饰器用法实例
2023-06-25 11:12:38
Python设计模式之代理模式实例详解
2022-11-20 05:24:29
![](https://img.aspxhome.com/file/2023/0/131470_0s.png)
改变链接,让别人永远找不到你的程序
2008-09-13 18:57:00
某大型网络公司应聘时的笔试题目附答案
2023-11-15 02:01:21