当前位置: 首页 > news >正文

【python】为你绘制玫瑰一束,爱意永存

前言

嗨喽~大家好呀,这里是魔王呐 ❤ ~!

若是有真情,爱意如溪水,

若是有真爱,爱意如阳光,

若是两情相悦,又岂在朝朝暮暮,

女子淡淡的情愫,深深地想念,

浓浓的爱意,蜜蜜的言语,醉了他的情,醉了他的意。

在这特别得一天给大家带来一个玫瑰花代码

更多教程源码资料电子书: 点击此处跳转文末名片获取

开发环境:

  • python 3.8 运行代码

  • pycharm 2022.3 辅助敲代码

模块使用:

本次使用均为内置模块,无需安装,导入即可使用

  • random是取随机数的模块

  • time是时间模块

  • turtle是绘图模块

  • math提供了一些基础的计算功能

代码展示

导入模块

import math
import time
import random
import turtle as t
list1=[]
for i in range(5):list1.append(int(random.uniform(-500,500)))
list2=[]
for i in range(5):list2.append(int(random.uniform(-200,-50)))
list3=[]
for i in range(8):list3.append(int(random.uniform(-400,400)))
list4=[]
for i in range(8):list4.append(int(random.uniform(-150,-50)))
list5=[]
for i in range(7):list5.append(int(random.uniform(-300,300)))
list6=[]
for i in range(7):list6.append(int(random.uniform(-200,-100)))
list7=[]
for i in range(18):list7.append(int(random.uniform(-500,500)))
list8=[]
for i in range(18):list8.append(int(random.uniform(-100,100)))
def move_pen_position(x, y):t.hideturtle()  # 隐藏画笔(先)t.up()  # 提笔t.goto(x, y)  # 移动画笔到指定起始坐标(窗口中心为0,0)t.down()  # 下笔t.showturtle()  # 显示画笔
love = input("请输入表白话语,默认为I LOVE U:")
signature = input("请签署你的名字:")
date=input("请写上日期:")
if love == '':love = 'I Love U'

初始化

t.setup(width=800, height=500)  # 窗口(画布)大小
t.color('red', 'pink')  # 画笔颜色
t.pensize(3)  # 画笔粗细
t.speed(0)  # 描绘速度

画大号爱心(位置随机)

for x,y in list(zip(list1,list2)):t.penup()t.goto(x, y)t.pendown()t.fillcolor("#A020F0")t.begin_fill()t.pencolor("#A020F0")t.forward(40)t.circle(20, 180)t.right(90)t.circle(20, 180)t.forward(40)t.end_fill()t.penup()t.goto(x, y)    

画中号爱心(位置随机)

for x,y in list(zip(list5,list6)):t.pendown()t.fillcolor("#DA70D6")t.begin_fill()t.pencolor("#DA70D6")t.forward(30)t.circle(15, 180)t.right(90)t.circle(15, 180)t.forward(30)t.end_fill()t.penup()t.goto(x, y)

画小号爱心(位置随机)

for x,y in list(zip(list3,list4)):t.pendown()t.fillcolor("#DDA0DD")t.begin_fill()t.pencolor("#DDA0DD")t.forward(20)t.circle(10,180)t.right(90)t.circle(10,180)t.forward(20)t.end_fill()t.penup()t.goto(x, y)

画点点(位置随机)

for x,y in list(zip(list7,list8)):t.pendown()t.fillcolor("#7B6BEE")t.begin_fill()t.pencolor("#7B6BEE")t.circle(3, 360)t.end_fill()t.penup()t.goto(x, y)
def DegreeCurve(n, r, d=1):for i in range(n):t.left(d)t.circle(r, abs(d))

初始位置设定

s = 0.2
# t.setup(450*5*s, 750*5*s)
t.pencolor("black")
t.fillcolor("#8A2BE2")
t.speed(100)
t.penup()
t.goto(0, 900*s)
t.pendown()

绘制花朵形状

t.begin_fill()
t.circle(200*s,30)
DegreeCurve(60, 50*s)
t.circle(200*s,30)
DegreeCurve(4, 100*s)
t.circle(200*s,50)
DegreeCurve(50, 50*s)
t.circle(350*s,65)
DegreeCurve(40, 70*s)
t.circle(150*s,50)
DegreeCurve(20, 50*s, -1)
t.circle(400*s,60)
DegreeCurve(18, 50*s)
t.fd(250*s)
t.right(150)
t.circle(-500*s,12)
t.left(140)
t.circle(550*s,110)
t.left(27)
t.circle(650*s,100)
t.left(130)
t.circle(-300*s,20)
t.right(123)
t.circle(220*s,57)
t.end_fill()

绘制花枝形状

t.left(120)
t.fd(280*s)
t.left(115)
t.circle(300*s,33)
t.left(180)
t.circle(-300*s,33)
DegreeCurve(70, 225*s, -1)
t.circle(350*s,104)
t.left(90)
t.circle(200*s,105)
t.circle(-500*s,63)
t.penup()
t.goto(170*s,-30*s)
t.pendown()
t.left(160)
DegreeCurve(20, 2500*s)
DegreeCurve(220, 250*s, -1)

绘制一个绿色叶子

t.fillcolor('#00CD00')
t.penup()
t.goto(670*s,-180*s)
t.pendown()
t.right(140)
t.begin_fill()
t.circle(300*s,120)
t.left(60)
t.circle(300*s,120)
t.end_fill()
t.penup()
t.goto(180*s,-550*s)
t.pendown()
t.right(85)
t.circle(600*s,40)

绘制另一个绿色叶子

t.penup()
t.goto(-150*s,-1000*s)
t.pendown()
t.begin_fill()
t.rt(120)
t.circle(300*s,115)
t.left(75)
t.circle(300*s,100)
t.end_fill()
t.penup()
t.goto(430*s,-1070*s)
t.pendown()
t.right(30)
t.circle(-600*s,35)
move_pen_position(300, -280)
# font:设定字体、尺寸(电脑下存在的字体都可设置)  align:中心对齐
t.write(love, font=('Arial', 20, 'bold'), align="center")

签写署名和日期

if (signature != '') & (date != ''):t.color('red', 'pink')time.sleep(2)move_pen_position(300, -320)t.hideturtle()  # 隐藏画笔t.write(signature, font=('Arial', 20), align="center")move_pen_position(300, -350)t.hideturtle()  # 隐藏画笔t.write(date, font=('Arial', 20), align="center")#1-5点击窗口关闭程序
window = t.Screen()
window.exitonclick()

爱意语录


我用短信表心意,将我爱意传予你,请你不要太在意,

你有真意我珍惜,将我诚意说与你,爱你爱你就爱你!


用最少语言,诉说给你最真的我。

用最纯的心,思念我最想的你。用最多的爱,呵护我最爱的你。


爱 是天意,一年一年,斗转星移,不求惊天动地,只想一爱到底


雨露花香是伴侣,蝴蝶双飞多甜蜜。缘分注定是天意,相爱不易多珍惜。

怀抱有你同呼吸,情意绵绵赏烟雨。两心长恋带笑意,幸福年年新天地。


最美的相遇,在岁月中沉淀,执笔流年,那些甜蜜心语,醉了时光。

蓦然回首,一往情深依旧,浪漫在时间与空间里独舞,用爱写满未来的信笺。爱你一生一世!


尾语 💝

要成功,先发疯,下定决心往前冲!

学习是需要长期坚持的,一步一个脚印地走向未来!

未来的你一定会感谢今天学习的你。

—— 心灵鸡汤

本文章到这里就结束啦~感兴趣的小伙伴可以复制代码去试试哦 😝

👇问题解答 · 源码获取 · 技术交流 · 抱团学习请联系👇

http://www.lryc.cn/news/33204.html

相关文章:

  • 智能家居创意产品一Homkit智能通断器
  • 【数据库】MySQL表的增删改查(基础命令详解)
  • 2023年全国最新保安员精选真题及答案15
  • KPN对任意形状文本检测
  • 同城外卖跑腿系统源码分析
  • SCL_PFENET跑通填坑
  • Redis 做延迟消息队列
  • 刚果金FERI证书模板
  • 什么是蜕变测试?
  • 74. ‘pip‘不是内部或外部命令,也不是可运行的程序-解决办法
  • MIL图像处理那些事:应用程序模块(Mapp)- 初始化和控制MIL应用程序的执行环境
  • Pytorch基础语法学习2——argparse模块
  • CHAPTER 2 目录及文件
  • 2021牛客OI赛前集训营-提高组(第四场) T1最终测试
  • 【华为OD机试2023】租车骑绿岛 C++ Java Python
  • 05-路由中的Hook
  • Ubuntu20.04 源码编译安装SRS-6流媒体服务器,开启GB28181支持
  • Web前端学习:六 -- 练习小总结
  • 微服务之 CAP原则
  • 乐鑫特权隔离机制 #4 | 用户应用程序的安全启动
  • 剑指 Offer 46. 把数字翻译成字符串
  • tar命令——归档/压缩和解压缩文件
  • Softing smartLink网关——推进过程工业数字化转型
  • Spark的常用算子
  • Unity Avatar Cover System - 如何实现一个Avatar角色的智能掩体系统
  • steam/csgo搬砖项目到底真的假的?
  • 【Python笔记20230307】
  • SBOM应该是软件供应链中的安全主食
  • [计算机组成原理(唐朔飞 第2版)]第一章 计算机系统概论 第二章 计算机的发展及应用(学习复习笔记)
  • Python的数据分析相关的框架