前言

嗨喽,大家好呀~这里是爱看美女的茜茜呐

今天,3月7日啦~更是个特别得你日子,你想起来了嘛

没错,今天就是女生节(明天就是妇女节啦,记得给老婆/母亲准备点小礼物噢~)。

三七女生节,种下小小的愿望,收获大大的梦想。

登上小小的舞台,成为大大的主角。

甩开小小,拥抱大大的未来。女生节,祝你美丽快乐、人生精彩!

进入主题:今天就就展示一些好看得代码给大家吧~


本文章完整源码直接在文末名片领取。点击此处跳转


一、永远为你心动

代码展示

✨ 愿你阳光下像个孩子,风雨里像个大人。

导入所需模块

此模块为内置模块,无需安装

import turtle as t

画背景框

t.title("Python学习交流Q群:261823976")
#t.screensize(1000, 800)
t.setup(startx=0, starty = 0, width=800, height = 600)
t.hideturtle()
print('画爱心')

画爱心

def heart(x, y):t.penup()t.goto(x, y)t.pendown()t.color('pink')t.setheading(50)t.circle( -5, 180)t.circle( -45, 12)t.setheading(130)t.circle( -45, 12)t.circle( -5, 180)
heart(-30, 155)
heart(-220, 145)
heart(-210, 60)
heart(-100, 100)
heart(-20, 20)
heart(-70, 130)
heart(-140, -20)
heart(30, 100)
heart(-60, -20)
heart(10, 60)
heart(-100, -70)
heart(20, 145)
heart(-140, -20)
heart(-130, 130)
heart(-180, 20)
heart(-170, 155)
heart(-230, 100)
def write_mes(x, y, size, ss):t.hideturtle()t.penup()t.goto(x, y)t.pendown()t.pencolor('black')t.write(ss, font=('Times New Roman', size, 'normal'))

画红心

print('画红心')
def heart_fill(x, y):t.penup()t.goto(x, y)t.pendown()t.color('red', 'red')t.begin_fill()t.setheading(50)t.circle( -5, 180)t.circle( -45, 12)t.setheading(130)t.circle( -45, 12)t.circle( -5, 180)t.end_fill()
x = 90
y = 110

右边爱心

write_mes(x, y, 11, '超')
heart_fill(-100, 100)
heart_fill(-70, 130)
heart_fill(-30, 155)
heart_fill(20, 145)
heart_fill(30, 100)
write_mes(x, y-30, 11, '爱')
heart_fill(10, 60)
heart_fill(-20, 20)
heart_fill(-60, -20)
heart_fill(-100, -70)

左边爱心

write_mes(x, y-30*2, 11, '你')
heart_fill(-140, -20)
heart_fill(-180, 20)
heart_fill(-210, 60)
heart_fill(-230, 100)
write_mes(x, y-30*3, 11, '呀')
heart_fill(-220, 145)
heart_fill(-170, 155)
heart_fill(-130, 130)
write_mes(x, y-30*4, 11, '宝')
t.speed(200)
print('画心动线')
def heart_bit():

画心动线

    t.penup()t.goto(-170, 40)t.pendown()t.pencolor('red')t.setheading(0)t.pensize(2)t.forward(10)

第一个小波浪

    t.setheading(45)t.circle(50, 10)t.setheading(0)t.circle(-3,90)t.circle(50, 5)

横线

    t.setheading(0)t.forward(10)

第一个下尖峰

    t.setheading(-80)t.forward(7)t.setheading(70)t.forward(25)t.setheading(-85)t.forward(29)t.setheading(70)t.forward(13)t.setheading(0)t.forward(15)

画心

    t.setheading(150)t.circle(-20, 40)t.circle(-10, 170)t.setheading(70)t.circle(-10, 170)t.circle(-20, 40)t.setheading(0)t.forward(15)#2t.setheading(-80)t.forward(7)t.setheading(70)t.forward(25)t.setheading(-85)t.forward(29)t.setheading(70)t.forward(13)t.setheading(0)t.forward(15)t.setheading(0)t.forward(10)t.setheading(45)t.circle(50, 10)t.setheading(0)t.circle(-3,90)t.circle(50, 5)t.setheading(0)t.forward(10)
def write_name(x, y, size, ss):t.hideturtle()t.penup()t.goto(x, y)t.pendown()t.pencolor('black')t.write(ss, font=('Times New Roman', size, 'normal'))
def undo_back():t.undo()t.undo()t.undo()t.undo()t.undo()t.undo()t.undo()t.undo()t.undo()t.undo()
def undo_back2():t.undo()t.undo()
def name_heart_bit():

写两个人的姓名

    write_name(-180, 70, 11, '笔芯')write_name(-180, 70, 11, '笔芯')write_name(-180, 70, 11, '笔芯')heart_bit()write_name(-60, 70, 11, 'Python')write_name(-60, 70, 11, 'Python')write_name(-60, 70, 11, 'Python')write_name(-60, 70, 11, 'Python')write_name(-60, 70, 11, 'Python')undo_back()undo_back()undo_back()undo_back()undo_back()undo_back()undo_back()undo_back()undo_back()undo_back2()
while 1:name_heart_bit()

二、为你跳动得心

代码展示

✨ 晚上星月争辉,美梦陪你入睡

模块导入

( 完整源码等直接点击找管理小姐姐免费领取呀~ )

import random
from math import sin, cos, pi, log
from tkinter import *

背景画布

CANVAS_WIDTH = 640  # 画布的宽
CANVAS_HEIGHT = 480  # 画布的高
CANVAS_CENTER_X = CANVAS_WIDTH / 2  # 画布中心的X轴坐标
CANVAS_CENTER_Y = CANVAS_HEIGHT / 2  # 画布中心的Y轴坐标
IMAGE_ENLARGE = 11  # 放大比例

心的颜色,这个是中国红

HEART_COLOR = "#ff8181"

基础函数

def heart_function(t, shrink_ratio: float = IMAGE_ENLARGE):x = 16 * (sin(t) ** 3)y = -(13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t))

放大

    x *= shrink_ratioy *= shrink_ratio

移到画布中央

    x += CANVAS_CENTER_Xy += CANVAS_CENTER_Yreturn int(x), int(y)

随机内部扩散

def scatter_inside(x, y, beta=0.15):ratio_x = - beta * log(random.random())ratio_y = - beta * log(random.random())dx = ratio_x * (x - CANVAS_CENTER_X)dy = ratio_y * (y - CANVAS_CENTER_Y)return x - dx, y - dy

抖动

def shrink(x, y, ratio):force = -1 / (((x - CANVAS_CENTER_X) ** 2 + (y - CANVAS_CENTER_Y) ** 2) ** 0.6)  # 这个参数...dx = ratio * force * (x - CANVAS_CENTER_X)dy = ratio * force * (y - CANVAS_CENTER_Y)return x - dx, y - dy

自定义曲线函数,调整跳动周期

def curve(p):# 可以尝试换其他的动态函数,达到更有力量的效果(贝塞尔?)return 2 * (2 * sin(4 * p)) / (2 * pi)

爱心类

class Heart:def __init__(self, generate_frame=20):self._points = set()  # 原始爱心坐标集合self._edge_diffusion_points = set()  # 边缘扩散效果点坐标集合self._center_diffusion_points = set()  # 中心扩散效果点坐标集合self.all_points = {}  # 每帧动态点坐标self.build(2000)self.random_halo = 1000self.generate_frame = generate_framefor frame in range(generate_frame):self.calc(frame)def build(self, number):# 爱心for _ in range(number):t = random.uniform(0, 2 * pi)  # 随机不到的地方造成爱心有缺口x, y = heart_function(t)self._points.add((x, y))# 爱心内扩散for _x, _y in list(self._points):for _ in range(3):x, y = scatter_inside(_x, _y, 0.05)self._edge_diffusion_points.add((x, y))# 爱心内再次扩散point_list = list(self._points)for _ in range(4000):x, y = random.choice(point_list)x, y = scatter_inside(x, y, 0.17)self._center_diffusion_points.add((x, y))@staticmethoddef calc_position(x, y, ratio):# 调整缩放比例force = 1 / (((x - CANVAS_CENTER_X) ** 2 + (y - CANVAS_CENTER_Y) ** 2) ** 0.520)  # 魔法参数dx = ratio * force * (x - CANVAS_CENTER_X) + random.randint(-1, 1)dy = ratio * force * (y - CANVAS_CENTER_Y) + random.randint(-1, 1)return x - dx, y - dydef calc(self, generate_frame):ratio = 10 * curve(generate_frame / 10 * pi)  # 圆滑的周期的缩放比例halo_radius = int(4 + 6 * (1 + curve(generate_frame / 10 * pi)))halo_number = int(3000 + 4000 * abs(curve(generate_frame / 10 * pi) ** 2))all_points = []# 光环heart_halo_point = set()  # 光环的点坐标集合for _ in range(halo_number):t = random.uniform(0, 2 * pi)  # 随机不到的地方造成爱心有缺口x, y = heart_function(t, shrink_ratio=11.6)  # 魔法参数x, y = shrink(x, y, halo_radius)if (x, y) not in heart_halo_point:# 处理新的点heart_halo_point.add((x, y))x += random.randint(-14, 14)y += random.randint(-14, 14)size = random.choice((1, 2, 2))all_points.append((x, y, size))# 轮廓for x, y in self._points:x, y = self.calc_position(x, y, ratio)size = random.randint(1, 3)all_points.append((x, y, size))# 内容for x, y in self._edge_diffusion_points:x, y = self.calc_position(x, y, ratio)size = random.randint(1, 2)all_points.append((x, y, size))for x, y in self._center_diffusion_points:x, y = self.calc_position(x, y, ratio)size = random.randint(1, 2)all_points.append((x, y, size))self.all_points[generate_frame] = all_pointsdef render(self, render_canvas, render_frame):for x, y, size in self.all_points[render_frame % self.generate_frame]:render_canvas.create_rectangle(x, y, x + size, y + size, width=0, fill=HEART_COLOR)def draw(main: Tk, render_canvas: Canvas, render_heart: Heart, render_frame=0):render_canvas.delete('all')render_heart.render(render_canvas, render_frame)main.after(160, draw, main, render_canvas, render_heart, render_frame + 1)if __name__ == '__main__':root = Tk()  # 一个Tkcanvas = Canvas(root, bg='black', height=CANVAS_HEIGHT, width=CANVAS_WIDTH)canvas.pack()heart = Heart()  # 心draw(root, canvas, heart)  # 开始画画~root.mainloop()

三、专属你得玫瑰

代码展示

✨ 愿你自强到无需有人宠有人惯,却依然幸运到有人宠有人惯。

导入模块

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

四、幸运四叶草

代码展示

✨ 轻铺光阴如笺,拾一支流云廋笔,寻一盏韶华入墨,把情愫写满。

导入模块

import turtle

画布背景

turtle.title('四叶草') #画布标题
# turtle.bgcolor("green") #背景颜色
turtle.pensize(5) #画笔宽度
turtle.speed(2) #海龟移动速度
turtle.fillcolor("green") #填充的颜色
turtle.begin_fill() #开始填色

花瓣

for i in range(4):turtle.circle(80, 50)turtle.circle(20, 180)turtle.left(180)turtle.circle(20, 180)turtle.circle(80, 50)turtle.left(180)
turtle.end_fill() #结束填色

花心

turtle.penup()
turtle.goto(-15, 0)
turtle.pendown()
turtle.circle(1)

花枝

turtle.penup()
turtle.goto(-10, -10)
turtle.pendown()
turtle.right(90)
turtle.circle(-200, 80)

打印

turtle.penup()
turtle.goto(0, 100) #移动位置,改变write的位置
turtle.write(' 四叶草它的花语是幸运!', font = ('arial', 18, 'normal')) #打印内容
turtle.done() #手动关闭

尾语

感谢你观看我的文章呐~本次航班到这里就结束啦

【python】美丽的代码,心动得效果,送给美丽得她~相关推荐

  1. python做万花筒代码_Python实现PS滤镜的万花筒效果示例

    本文实例讲述了Python实现PS滤镜的万花筒效果.分享给大家供大家参考,具体如下: 这里用 Python 实现 PS 的一种滤镜效果,称为万花筒.也是对图像做各种扭曲变换,最后图像呈现的效果就像从万 ...

  2. 编写一个python程序、输出如下图形效果_Tkinter模块编写Python图形界面代码实例...

    本篇文章小编给大家分享一下Tkinter模块编写Python图形界面代码实例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. 一.为何使用Tkinter ...

  3. 4行python代码做出打字机效果

    4行python代码做出打字机效果 文章目录 4行python代码做出打字机效果 前言 一.导入库 二.完整代码 前言 今天想用python做一个打字机的效果出来看看! 一.导入库 import py ...

  4. python 微信 表白代码-python520表白

    广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 备战520|python花式表白的几种姿势其实内容都大同小异无非是画个爱心或者制 ...

  5. python浪漫表白代码

    python浪漫表白代码 示例代码: import turtle import random# 在(x, y)处画爱心lalala def love(x, y):lv = turtle.Turtle( ...

  6. 如何学习Python开源项目代码

    2019独角兽企业重金招聘Python工程师标准>>> 阅读Python开源项目代码主要有如下三个原因: 1. 在工作过程中遇到一些问题,Google和StackOverFlow等网 ...

  7. python表白代码照片墙-python入会生成照片墙 利用python生成照片墙代码

    本篇文章小编给大家分享一下利用python生成照片墙代码,对大家的学习有一定的帮助,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. PIL(Python Image Libr ...

  8. 2021-04-05 Python tqdm显示代码任务进度

    Python tqdm显示代码任务进度 有时候在使用Python处理比较耗时操作的时候,为了便于观察处理进度,这时候就需要通过进度条将处理情况进行可视化展示,以便我们能够及时了解情况. tqdm就能非 ...

  9. ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(四)

    ML之XGBoost:XGBoost参数调优的优秀外文翻译-<XGBoost中的参数调优完整指南(带python中的代码)>(四) 目录 Step 3: Tune gamma步骤3:伽马微 ...

最新文章

  1. Open Drug Discovery Toolkit
  2. uuid生成_php如何生成 uuid(总结)
  3. Broadcast简单使用
  4. 程序员精美简历Top榜—面试必备
  5. java ee 值范围_javaEE四大作用域(共享域)
  6. python之matplotlib中plt.show()不显示
  7. pandas中dataframe的索引问题
  8. NOI2004 郁闷的出纳员 splay
  9. 应用程序热补丁(二):自动生成热补丁
  10. 我看过的机器学习方面的好文章
  11. html特殊符号圆点,HTML特殊符号(字符实体)大全
  12. oracle中删除级联方法,Oracle 外键级联删除
  13. go beego在apache服务器上域名配置 --小丑
  14. c语言while延时10ms,for循环实现C语言精确延时
  15. R shiny echart4r 常见问题整理
  16. 关于MySQL联合索引和优化军规
  17. pythonocc的BRepPrimAPI在OCC.Core.BRepPrimAPI里
  18. Testpoint设置的疑问
  19. 肺结节目标检测_一种基于CT图像的肺结节检测方法及系统与流程
  20. android绘制心形,Android中的心形按钮

热门文章

  1. 关于postman的断言的解释
  2. Smartform 介绍
  3. 10__jsp入门el表达式入门CookieSession
  4. 《风起洛阳》数字藏品发售,带你一起梦回神都!
  5. 读《后汉演义》之王莽:是古非今
  6. 做喜欢的事或能看到希望,就不会觉得辛苦
  7. 推荐一款国内最好的个人知识管理、笔记软件,学习工作最好帮手
  8. 蓝桥杯-暴力破解-03-罗马数字
  9. 中文流行歌曲歌词文本挖掘
  10. sugarCrm翻译