10个Python绘画表白代码【内附源码,再不收藏你只能单身了】

article/2025/9/10 22:32:47

发现一些很好玩的画图小项目,今天分享给大家,教你怎样用Python画一朵玫瑰花、时钟、爱心、太阳花、月饼、进阶自定义爱心、小猪佩奇、星空、超梦幻的蓝色背景樱花等大家快来学习吧。

运行工具:

pycharm 、python

玫瑰花

image

from turtle import *import timesetup(1000,800,0,0)speed(0)penup()seth(90)
fd(340)seth(0)pendown()speed(5)begin_fill()fillcolor('red')circle(50,30)for i in range(10):    
fd(1)    left(10)circle(40,40)for i in range(6):    
fd(1)    left(3)circle(80,40)for i in range(20):   
fd(0.5)    left(5)circle(80,45)for i in range(10):    
fd(2)    left(1)circle(80,25)for i in range(20):    
fd(1)    left(4)circle(50,50)time.sleep(0.1)circle(120,55)speed(0)seth(-90)
fd(70)right(150)fd(20)left(140)circle(140,90)left(30)circle(160,100)left(130)
fd(25)penup()right(150)circle(40,80)pendown()left(115)
fd(60)penup()left(180)
fd(60)pendown()end_fill()right(120)circle(-50,50)circle(-20,90)speed(1)
fd(75)speed(0)circle(90,110)penup()left(162)
fd(185)left(170)pendown()circle(200,10)circle(100,40)circle(-52,115)left(20)circle(100,20)circle(300,20)speed(1)
fd(250)penup()speed(0)left(180)
fd(250)circle(-300,7)right(80)circle(200,5)pendown()left(60)begin_fill()fillcolor('green')circle(-80,100)right(90)
fd(10)left(20)circle(-63,127)end_fill()penup()left(50)
fd(20)left(180)pendown()circle(200,25)penup()right(150)
fd(180)right(40)pendown()begin_fill()fillcolor('green')circle(-100,80)right(150)
fd(10)left(60)circle(-80,98)end_fill()penup()left(60)
fd(13)left(180)pendown()speed(1)circle(-200,23)exitonclick()

实时时钟

image

# coding=utf-8 import turtlefrom datetime import * 
# 抬起画笔,向前运动一段距离放下def Skip(step):    
turtle.penup()    
turtle.forward(step)    
turtle.pendown() def mkHand(name, length):    
# 注册Turtle形状,建立表针Turtle    
turtle.reset()    
Skip(-length * 0.1)    
# 开始记录多边形的顶点。当前的乌龟位置是多边形的第一个顶点。    
turtle.begin_poly()    
turtle.forward(length * 1.1)    
# 停止记录多边形的顶点。当前的乌龟位置是多边形的最后一个顶点。将与第一个顶点相连。    
turtle.end_poly()    
# 返回最后记录的多边形。    
handForm = turtle.get_poly()    
turtle.register_shape(name, handForm) def Init():    
global secHand, minHand, hurHand, printer    
# 重置Turtle指向北    turtle.mode("logo")    
# 建立三个表针Turtle并初始化    mkHand("secHand", 135)    
mkHand("minHand", 125)    
mkHand("hurHand", 90)    
secHand = turtle.Turtle()    
secHand.shape("secHand")    
minHand = turtle.Turtle()    
minHand.shape("minHand")    
hurHand = turtle.Turtle()    
hurHand.shape("hurHand")       
for hand in secHand, minHand, hurHand:        
hand.shapesize(1, 1, 3)        
hand.speed(0)       
# 建立输出文字Turtle    
printer = turtle.Turtle()    
# 隐藏画笔的turtle形状    
printer.hideturtle()    
printer.penup()    
def SetupClock(radius):    
# 建立表的外框    
turtle.reset()    
turtle.pensize(7)    
for i in range(60):        
Skip(radius)        
if i % 5 == 0:            
turtle.forward(20)            
Skip(-radius - 20)                       
Skip(radius + 20)            
if i == 0:                
turtle.write(int(12), align="center", font=("Courier", 14, "bold"))            
elif i == 30:                
Skip(25)                
turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))                
Skip(-25)            
elif (i == 25 or i == 35):                
Skip(20)                
turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))                
Skip(-20)            
else:                
turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))            
Skip(-radius - 20)       else:            
turtle.dot(5)            
Skip(-radius)        
turtle.right(6)        
def Week(t):       
week = ["星期一", "星期二", "星期三",            "星期四", "星期五", "星期六", "星期日"]    
return week[t.weekday()] def Date(t):    
y = t.year    
m = t.month    
d = t.day    
return "%s %d%d" % (y, m, d) def Tick():    
# 绘制表针的动态显示    
t = datetime.today()    
second = t.second + t.microsecond * 0.000001    
minute = t.minute + second / 60.0    
hour = t.hour + minute / 60.0    
secHand.setheading(6 * second)    
minHand.setheading(6 * minute)    
hurHand.setheading(30 * hour)        
turtle.tracer(False)     
printer.forward(65)    
printer.write(Week(t), align="center",                  
font=("Courier", 14, "bold"))    
printer.back(130)    
printer.write(Date(t), align="center",                  
font=("Courier", 14, "bold"))    
printer.home()    
turtle.tracer(True)     
# 100ms后继续调用tick    
turtle.ontimer(Tick, 100) def main():    
# 打开/关闭龟动画,并为更新图纸设置延迟。    
turtle.tracer(False)    
Init()    
SetupClock(160)    
turtle.tracer(True)    
Tick()    
turtle.mainloop() if __name__ == "__main__":    main()

表白爱心

image

import turtleimport mathturtle.pen()
t=turtlet.up()
t.goto(0,150)
t.down()
t.color('red')
t.begin_fill()
t.fillcolor('red')
t.speed(1)
t.left(45)
t.forward(150)
t.right(45)
t.forward(100)
t.right(45)
t.forward(100)
t.right(45)
t.forward(100)
t.right(45)
t.forward(250+math.sqrt(2)*100)
t.right (90)
t.speed(2)
t.forward(250+100*math.sqrt(2))
t.right(45)
t.forward(100)
t.right(45)
t.forward(100)
t.right(45)
t.forward(100)
t.right(45)
t.forward(150)
t.end_fill()
t.goto(-10,0)
t.pencolor('white')
#Lt.pensize(10)
t.goto(-50,0)
t.goto(-50,80)t.up ()
#It.goto(-100,0)
t.down()
t.goto(-160,0)
t.goto(-130,0)
t.goto(-130,80)
t.goto(-160,80)
t.goto(-100,80)
t.up()
#Ot.goto(10,25)t
.down()
t.right(45)
t.circle(25,extent=180)
t.goto(60,55)
t.circle(25,extent=180)
t.goto(10,25)
t.up()t.goto(75,80)
t.down()
t.goto(100,0)
t.goto(125,80)
t.up()
t.goto(180,80)
t.down()
t.goto(140,80)
t.goto(140,0)
t.goto(180,0)
t.up()
t.goto(180,40)
t.down()
t.goto(140,40)
#Ut.up()
t.goto(-40,-30)
t.down()
t.goto(-40,-80)
t.circle(40,extent=180)
t.goto(40,-30)
t.hideturtle()

小猪佩奇

image

# coding:utf-8import timeimport turtle as tt.pensize(4)
t.colormode(255)
t.color((255,155,192),"pink")
t.setup(840,500)
t.speed(10)t.pu()
t.goto(-100,100)
t.pd()
t.seth(-30)
t.begin_fill()a=0.4for i in range(120):    
if 0<=i<30 or 60<=i<90:        
a=a+0.08        
t.lt(3)        
t.fd(a)    
else:        
a=a-0.08        
t.lt(3)        
t.fd(a)
t.end_fill()
t.pu()
t.seth(90)
t.fd(25)
t.seth(0)
t.fd(10)
t.pd()
t.pencolor(255,155,192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160,82,45)
t.end_fill()
t.pu()
t.seth(0)
t.fd(20)
t.pd()t.pencolor(255,155,192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160,82,45)
t.end_fill()
t.color((255,155,192),"pink")
t.pu()
t.seth(90)
t.fd(41)
t.seth(0)
t.fd(0)
t.pd()
t.begin_fill()
t.seth(180)
t.circle(300,-30)
t.circle(100,-60)
t.circle(80,-100)
t.circle(150,-20)
t.circle(60,-95)
t.seth(161)
t.circle(-300,15)
t.pu()
t.goto(-100,100)
t.pd()
t.seth(-30)a=0.4for i in range(60):   if 0<=i<30 or 60<=i<90:        
a=a+0.08        
t.lt(3)        
t.fd(a)    
else:        
a=a-0.08        
t.lt(3)        
t.fd(a)        
t.end_fill()
t.color((255,155,192),"pink")
t.pu()
t.seth(90)
t.fd(-7)
t.seth(0)
t.fd(70)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50,50)
t.circle(-10,120)
t.circle(-50,54)
t.end_fill()
t.pu()
t.seth(90)
t.fd(-12)
t.seth(0)
t.fd(30)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50,50)
t.circle(-10,120)
t.circle(-50,56)
t.end_fill()
t.color((255,155,192),"white")
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-95)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
t.color((255,155,192),"white")
t.pu()
t.seth(90)
t.fd(-25)
t.seth(0)
t.fd(40)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
#腮
t.color((255,155,192))
t.pu()
t.seth(90)
t.fd(-95)
t.seth(0)
t.fd(65)
t.pd()
t.begin_fill()
t.circle(30)
t.end_fill()
#嘴
t.color(239,69,19)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(-100)
t.pd()
t.seth(-80)t.circle(30,40)
t.circle(40,80)
#身体
t.color("red",(255,99,71))
t.pu()t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-78)
t.pd()
t.begin_fill()
t.seth(-130)
t.circle(100,10)
t.circle(300,30)
t.seth(0)
t.fd(230)
t.seth(90)
t.circle(300,30)
t.circle(100,3)
t.color((255,155,192),(255,100,100))
t.seth(-135)
t.circle(-80,63)
t.circle(-150,24)
t.end_fill()
#手
t.color((255,155,192))
t.pu()
t.seth(90)
t.fd(-40)
t.seth(0)
t.fd(-27)
t.pd()t.seth(-160)
t.circle(300,15)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-10)
t.circle(-20,90)
t.pu()
t.seth(90)
t.fd(30)
t.seth(0)
t.fd(237)
t.pd()
t.seth(-20)
t.circle(-300,15)
t.pu()
t.seth(90)
t.fd(20)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-170)
t.circle(20,90)
#脚
t.pensize(10)
t.color((240,128,128))
t.pu()t.seth(90)t.fd(-75)
t.seth(0)t.fd(-180)t.pd()
t.seth(-90)t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
t.pensize(10)
t.color((240,128,128))
t.pu()t.seth(90)
t.fd(40)
t.seth(0)t.fd(90)
t.pd()
t.seth(-90)t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
#尾巴t.pensize(4)
t.color((255,155,192))
t.pu()
t.seth(90)
t.fd(70)
t.seth(0)
t.fd(95)
t.pd()
t.seth(0)
t.circle(60,20)
t.circle(10,230)
t.circle(60,30)

多角形太阳花

image

# coding=utf-8import turtleimport time 
# 同时设置pencolor=color1, fillcolor=color2turtle.color("red", "yellow") 
turtle.begin_fill()for _ in range(50):    
turtle.forward(200)    
turtle.left(170)turtle.end_fill() 
turtle.mainloop()

进阶自定义表白爱心

image

模拟3D星空

image

超梦幻的蓝色背景樱花

image

花儿

image

表白爱心树

image

其他

图片.png


http://chatgpt.dhexx.cn/article/3wgF1qO9.shtml

相关文章

python表白代码简单

你好&#xff0c;我是罡罡同学&#xff01; 代码谱第一页忘掉心上人&#xff0c;最后一页。。。。。。 打赏一点钱&#xff0c;帮我买包辣条&#xff0c;继续创作&#xff0c;谢大家&#xff01; python表白代码简单 1.首先你要现有python&#xff0c;以及环境配置&#xff0…

vm虚拟机安装教程及注意事项

前言 1.此教程仅适用于新手&#xff0c;自己用的没问题就不用看了。 2.此教程虚拟机使用的是VMware workstations&#xff0c;安装的是win7操作系统。 正文 1.先去官网下载vmware workstation主程序。 ----如果你的电脑是win10&#xff0c;需要安装win7虚拟机的话&#xf…

VMware 虚拟机安装

文章目录 1 下载与安装1.1 下载1.2 安装 2 虚拟机设置配置2.1 网段检查 3 打开虚拟机镜像 1 下载与安装 VMware是一个虚拟PC的软件&#xff0c;可以在现有的操作系统上虚拟出一个新的硬件环境&#xff0c;相当于模拟出一台新的PC&#xff0c;以此来实现在一台机器上真正同时运…

在vm虚拟机安装windows 11系统全教程

目录 作者语录&#xff1a; 一、准备工具 二、安装Windows系统 1、创建虚拟机环境 2、安装windows11系统 作者语录&#xff1a; 这篇文章从无到有&#xff0c;从小白到会轻轻松松的事&#xff0c;超级详细的过程&#xff0c;请认真观看这些步骤&#xff0c;方面你们操作实践…

VM虚拟机安装Linux系统

Linux的安装前的准备 1、首先在安装Linux前的保证电脑中得有虚拟机的存在&#xff0c;Vmware虚拟机官网网址&#xff1a;https://www.vmware.com/cn.html 如图&#xff1a; 进入vm官网后从资源中找到下载自己喜欢版本就行了&#xff0c;vm的安装我这就不一一解释安装了。或者…

M用户使用VM虚拟机安装win11连不上网,怎么解决

VMware Fusion一款非常受欢迎的虚拟机软件&#xff0c;可以借助VM虚拟机在Mac上运行Windows以及数百个其他操作系统&#xff0c;无需重启电脑。最近好多用户反映在M上使用VM虚拟机安装了windows11系统&#xff0c;结果不能联网怎么办&#xff0c;这个小编为大家带来了一种解决方…

vm虚拟机安装步骤

目录 一、软件安装环境和安装包的准备1、安装包的下载2、安装包截图 二、安装步骤1、点击安装包2、点击下一步3、勾选我接受许可&#xff0c;再点击下一步4、更改安装路径&#xff0c;点击下一步5、取消启动时检查产品更新和客户提升计划&#xff0c;点击下一步6、点击下一步7、…

VMware虚拟机安装

文章目录 一、裸机安装二、系统安装三、系统配置四、根据模板机创建虚拟机 一、裸机安装 创建新的虚拟机&#xff0c;选择"自定义"&#xff0c;点击"下一步" 直接"下一步" 选择"稍后安装操作系统"后&#xff0c;点击"下一步&quo…

VMware安装虚拟机

1.新建虚拟机 点击左上角的文件&#xff0c;选择新建虚拟机&#xff0c;会出现新建虚拟机向导界面&#xff0c;选择自定义(高级)&#xff0c;点击下一步 2.硬件兼容性选择 硬件兼容性选择Workstation 15.x,点击下一步 3.安装程序光盘映像文件(iso) 选择CentOS7的路径&am…

通过VM虚拟机安装linux系统(centos版本)

一、下载VMware虚拟机 1.下载官网&#xff1a;https://www.vmware.com/cn.html 2.进入官网搜索Workstation Pro 然后就是等待&#xff0c;选择合适的盘装就对了&#xff0c;激活码网上自己找找有很多。 二、linux系统镜像下载&#xff08;我下的是centos版本的&#xff09; …

VM虚拟机安装win10

仅用于学习和研究用途&#xff0c;并在下载后24小时删除。本文仅作学习和研究相关用途&#xff0c;作者不负任何法律责任。 准备工作 安装软件 开始 新建虚拟机 我这里已经准备过了&#xff0c;只截图吧&#xff0c;按照图片的设置做。 这里根据需要改动 放心&#xff0…

vm虚拟机怎么安装Win11系统?Win11系统安装到vm虚拟机详细图文教程

vm虚拟机怎么安装Win11系统&#xff1f;今天小编就为大家带来了Win11系统安装到vm虚拟机详细图文教程&#xff0c;感兴趣的朋友一起看看吧 Win11系统怎么安装到vm虚拟机&#xff1f;很多用户都想尝鲜使用最新的Win11系统&#xff0c;可是又怕影响原来的操作系统&#xff0c;那么…

VM (虚拟机)下载及安装详细步骤

下载与安装虚拟机VM详细步骤 一、 需要先下载VM 链接&#xff1a;link ### 选择第一个或第二个进行下载安装二、虚拟机安装 1 .打开下载好的虚拟机安装文件&#xff0c;exe结尾的&#xff0c;它会弹出安装界面。 2 .点击下一步&#xff0c;阅读协议并决定是否接受后再次…

VM虚拟机系统安装

VM安装系统&#xff08;Windows和centos&#xff09;遇到的问题 本文共分享两个问题 问题一&#xff1a;vm安装Windows提示couldn’t find bootmgr 问题二&#xff1a;vm安装centos黑屏&#xff0c;导致无法安装 问题一&#xff1a;vm安装Windows提示couldn’t find bootmgr 解…

轻松安装虚拟机:一步步教你安装VM虚拟机

虚拟化技术的发展使得我们可以在一台计算机上运行多个独立的操作系统&#xff0c;而不需要为每个操作系统购买一台独立的计算机。其中最常用的虚拟化软件之一是VM虚拟机&#xff0c;它提供了一个简单而强大的平台&#xff0c;让我们能够在一台主机上安装和运行多个虚拟机。本文…

Redis篇之设置Redis密码以及查看密码

一、前言 对于redis而言&#xff0c;其并没有实现访问控制这个功能&#xff0c;但是可以提供一个轻量级的auth认证方式。 可以通过编辑对应的redis配置文件。redis.conf来启动 二、设置密码 1、找到redis的配置文件 redis.conf 配置文件中的参数&#xff1a;requirepass &…

redis密码设置

最新window版本下载地址&#xff1a;https://github.com/mythz/redis-windows 找到redis的目录&#xff0c;双击redis-server.exe 双击redis-cli.exe&#xff0c; config get requirepass 获取密码 config set requirepass huikewk 重置密码 auth huikewk 验证密码 关于…

使用Redis如何设置永久密码

Redis默认配置是不需要密码认证的&#xff0c;也就是说只要连接的Redis服务器的host和port正确&#xff0c;就可以连接使用。这在安全性上会有一定的问题&#xff0c;所以需要启用Redis的认证密码&#xff0c;增加Redis服务器的安全性。 1. 修改配置文件 找到Redis所在的目录&…

Ubuntu下Redis密码设置问题及其解决方案

Ubuntu下Redis密码设置问题及其解决方案 一、Redis设置密码1. 命令行设置密码。2. 配置文件设置密码 二、遇到问题&解决问题1.无法打开配置文件&#xff1a;2.配置文件密码修改成功点击保存但是却gedit警告&#xff1a;3.gedit 配置文件修改密码成功但仍CONFIG GET为空4.注…

docker设置redis密码

docker设置redis密码 方法一&#xff1a;创建redis容器并设置密码 docker run -itd --name redis-6379 -p 6379:6379 redis --requirepass 123456说明: --name (启动容器的名称) -p 映射端口:redis启动端口 redis --requirepass 启动密码方法二&#xff1a;为现有的redis创…