日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python表白代码:“ 星光月夜烟花皆归你,我也归你”(满天烟花盛开、附番外玫瑰)

發(fā)布時(shí)間:2023/12/20 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python表白代码:“ 星光月夜烟花皆归你,我也归你”(满天烟花盛开、附番外玫瑰) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?導(dǎo)語

"慢品人間煙火色 閑觀人間歲月長"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ———致自己???

?

🌙 遇見我以后,我們的故事就開始了,愿你歷經(jīng)山河,仍覺得人間值得🌙。

?

?星光月夜煙花皆歸你,我也歸你。關(guān)于煙花🎇大家都?知道多少?有多少表白故事情節(jié)都發(fā)生在煙

花下,想必木木子👸不用說大家也知道叭~??

今天這則小短文就是關(guān)于煙花的故事你準(zhǔn)備好跟我一起進(jìn)入煙花的世界了嘛?


?正文

“每一句文案,都有一個(gè)故事,你仔細(xì)聽”

?

1)環(huán)境安裝🎊

準(zhǔn)備好:Python3、Pycharm、Tkinter、Pygame、Pillow以及一些自帶模塊。

安裝命令統(tǒng)一:

pip install -i https://pypi.douban.com/simple/ +模塊名

2)素材展示🎨

2.1音樂背景(可自選)

2.2圖片素材(可修改)

3)正式敲代碼🎊

3.1導(dǎo)入庫

import random import pygame as py import tkinter as tk from time import time, sleep from tkinter import filedialog from PIL import Image, ImageTk from math import sin, cos, radians from random import choice, uniform, randint

3.2界面窗口設(shè)置

if __name__ == '__main__': root = tk.Tk() root.title('漫天煙花——祝大家—有情人終成眷屬') # 設(shè)置窗體的標(biāo)題欄cv = tk.Canvas(root, height=600, width=600)#繪制一個(gè)高600,寬600的畫布 bgpath = filedialog.askopenfilename(title='請選擇背景圖片')#選擇背景圖片image = Image.open(bgpath)#打開背景圖片image = image.resize((600,600), Image.ANTIALIAS)#把背景圖片調(diào)整成窗口大小photo = ImageTk.PhotoImage(image) cv.create_image(0, 0, image=photo, anchor='nw')#在畫布上繪制加載的背景圖片 bgmusic = filedialog.askopenfilename(title='請選擇背景音樂')py.mixer.init()# 初始化py.mixer.music.load(bgmusic)# 文件加載py.mixer.music.play(-1, 0, fade_ms=50)# 播放 第一個(gè)是播放值 -1代表循環(huán)播放, 第二個(gè)參數(shù)代表開始播放的時(shí)間py.mixer.music.pause() #暫停py.mixer.music.unpause()#取消暫停cv.pack()#把cv添加進(jìn)去root.protocol("WM_DELETE_WINDOW", close)root.after(200, simulate, cv)#在0.1秒后再調(diào)用stimulate函數(shù),生成一輪煙花綻放效果root.mainloop()#執(zhí)行root,生成窗口

3.3顏色設(shè)置隨機(jī)

def randomcolor():#生成隨機(jī)顏色colArr = ['1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']color = ""for i in range(6):color += colArr[random.randint(0,14)]return "#"+colorGRAVITY = 0.06 #重力變量 colors = ['red', 'blue', 'yellow', 'white', 'green', 'orange', 'purple', 'seagreen','indigo', 'cornflowerblue', 'pink'] #顏色列表

3.4主程序煙花

class part: #為每一個(gè)煙花綻放出來的粒子單獨(dú)構(gòu)建一個(gè)類的對象 ,每個(gè)粒子都會(huì)有一些重要的屬性,決定它的外觀(大小、顏色)、移動(dòng)速度等def __init__(self, cv, idx, total, explosion_speed, x=0., y=0., vx = 0., vy = 0., size=2., color = 'red', lifespan = 2, **kwargs):self.id = idx#每個(gè)煙花的特定標(biāo)識(shí)符self.x = x#煙花綻放x軸self.y = y#煙花綻放y軸self.initial_speed = explosion_speed#粒子初始速度self.vx = vx#粒子運(yùn)動(dòng)x軸速度self.vy = vy#粒子運(yùn)動(dòng)y軸速度self.total = total#綻放粒子數(shù)self.age = 0#粒子已停留時(shí)間self.color = color#粒子顏色self.cv = cv#畫布self.cid = self.cv.create_oval(x - size, y - size, x + size,y + size, fill=self.color, outline='white',width=0.01)#指定一個(gè)限定矩形(Tkinter 會(huì)自動(dòng)在這個(gè)矩形內(nèi)繪制一個(gè)橢圓)self.lifespan = lifespan#粒子在畫布上停留的時(shí)間def update(self, dt): self.age += dt#更新粒子停留時(shí)間if self.alive() and self.expand():#如果粒子既存活又處于擴(kuò)張階段move_x = cos(radians(self.id*360/self.total))*self.initial_speed#粒子x軸繼續(xù)膨脹move_y = sin(radians(self.id*360/self.total))*self.initial_speed#粒子y軸繼續(xù)膨脹self.cv.move(self.cid, move_x, move_y)#根據(jù)id把畫布上的粒子移動(dòng)x和y個(gè)距離self.vx = move_x/(float(dt)*1000)#粒子x軸的速度elif self.alive():columnFont = ('華文行楷',14)#如果粒子僅存活不擴(kuò)張(只是停留時(shí)間足夠,說明膨脹到最大了),則自由墜落self.cv.create_text(250, 100, text='喜',tag="write_tag", fill=choice(colors),font = columnFont) #字體self.cv.create_text(300, 100, text='歡',tag="write_tag", fill=choice(colors),font = columnFont)self.cv.create_text(350, 100, text='你',tag="write_tag", fill=choice(colors),font = columnFont)self.cv.create_text(400, 100, text='吖',tag="write_tag", fill=choice(colors),font = columnFont)#刪除文字標(biāo)簽move_x = cos(radians(self.id*360/self.total))#x軸的移動(dòng)位移# we technically don't need to update x, y because move will do the jobself.cv.move(self.cid, self.vx + move_x, self.vy+GRAVITY*dt)self.vy += GRAVITY*dt#更新y軸elif self.cid is not None:#如果粒子生命周期已過,則將其移除cv.delete(self.cid)#在畫布上移除該粒子對象self.cv.delete("write_tag")#同時(shí)移除字體self.cid = Nonedef expand (self):#定義膨脹效果時(shí)間幀return self.age <= 1.2#判斷膨脹時(shí)間是否小于1.2秒def alive(self):#判斷粒子是否仍在生命周期內(nèi)return self.age <= self.lifespan#判斷已停留時(shí)間是否小于應(yīng)該停留時(shí)間''' Firework simulation loop: Recursively call to repeatedly emit new fireworks on canvas a list of list (list of stars, each of which is a list of particles) is created and drawn on canvas at every call, via update protocol inside each 'part' object '''def simulate(cv):t = time()#返回自1970年后經(jīng)過的浮點(diǎn)秒數(shù),精確到小數(shù)點(diǎn)后7位explode_points = []#爆炸點(diǎn)列表,煙花列表wait_time = randint(10,100)#等待時(shí)間為10到100之間整數(shù)numb_explode = randint(8,20)#爆炸煙花個(gè)數(shù)時(shí)6到10之間的隨機(jī)整數(shù)# create list of list of all particles in all simultaneous explosionfor point in range(numb_explode):#為所有模擬煙花綻放的全部粒子創(chuàng)建一列列表if point<=4:objects = []#每個(gè)點(diǎn)的爆炸粒子列表粒子列表x_cordi = 250 + point*50#每個(gè)爆炸點(diǎn)的x軸y_cordi = 100#每個(gè)爆炸點(diǎn)的y軸speed = uniform (0.5, 1.5) #每個(gè)爆炸點(diǎn)的速度size = uniform (0.5,3)#每個(gè)爆炸點(diǎn)的大小color = choice(colors)#每個(gè)爆炸點(diǎn)的顏色explosion_speed = uniform(0.6, 3)#爆炸的綻放速度total_particles = randint(10,60)#煙花的總粒子數(shù)for i in range(1,total_particles):#同一個(gè)煙花爆炸出來的粒子大小、速度、坐標(biāo)都是相同的r = part(cv, idx = i, total = total_particles, explosion_speed = explosion_speed, x = x_cordi, y = y_cordi, vx = speed, vy = speed, color=color, size = size, lifespan = uniform(0.6,1.75))#把上述參數(shù)代入part函數(shù),但是每個(gè)粒子的生存時(shí)間是自己獨(dú)立的objects.append(r)#把r添加進(jìn)粒子列表explode_points.append(objects)#把粒子列表添加進(jìn)煙花列表else: objects = []#每個(gè)點(diǎn)的爆炸粒子列表粒子列表x_cordi = randint(50,550)#每個(gè)爆炸點(diǎn)的x軸y_cordi = randint(50, 150)#每個(gè)爆炸點(diǎn)的y軸speed = uniform (0.5, 1.5) #每個(gè)爆炸點(diǎn)的速度size = uniform (0.5,3)#每個(gè)爆炸點(diǎn)的大小color = choice(colors)#每個(gè)爆炸點(diǎn)的顏色explosion_speed = uniform(0.3, 2)#爆炸的綻放速度total_particles = randint(10,50)#煙花的總粒子數(shù)for i in range(1,total_particles):#同一個(gè)煙花爆炸出來的粒子大小、速度、坐標(biāo)都是相同的r = part(cv, idx = i, total = total_particles, explosion_speed = explosion_speed, x = x_cordi, y = y_cordi, vx = speed, vy = speed, color=color, size = size, lifespan = uniform(0.6,1.75))#把上述參數(shù)代入part函數(shù),但是每個(gè)粒子的生存時(shí)間是自己獨(dú)立的objects.append(r)#把r添加進(jìn)粒子列表explode_points.append(objects)#把粒子列表添加進(jìn)煙花列表total_time = .0#初始化總時(shí)間# keeps undate within a timeframe of 1.8 second while total_time < 2:#當(dāng)總時(shí)間小于1.8秒時(shí)運(yùn)行該循環(huán)sleep(0.03)#讓畫面暫停0.01秒tnew = time()#刷新時(shí)間t, dt = tnew, tnew - t#時(shí)間等于新時(shí)間,和上次時(shí)間間隔為tnew-tfor point in explode_points:#遍歷煙花列表for item in point:#遍歷煙花里的粒子列表item.update(dt)#粒子更新時(shí)間cv.update()#刷新畫布total_time += dt#為while循環(huán)增加時(shí)間root.after(wait_time, simulate, cv)#將組件置于其他組件之后,放在最頂層,覆蓋下面的,遞歸調(diào)用自己,形成新一輪的爆炸def close(*ignore):#打開模擬循環(huán)并關(guān)閉窗口"""Stops simulation loop and closes the window."""global rootroot.quit()

?4)效果展示💐

展示四組煙花效果哈——其余的自己拿代碼試試哦~🎇其實(shí)都是動(dòng)態(tài)放煙花滴~

一、?PART 01🌻

1.0 隨機(jī)作品展示效果?

1.2 煙花文案——滿天星辰🌙

? 湊不夠滿天星辰 那就放煙花給你看

? 煙花很美 你看著煙花微笑時(shí)的微笑更美

? 你帶我看了一場煙花 我夢里都是你的微笑

? 若時(shí)光是醉世煙花,你能否與我共看璀璨風(fēng)華

? 心上人有他的煙花之火 心上人是你的眼光有火

I will luve thee still, my dear.

While the sands o' life shall run.?

二、PART 02🌻

1.0隨機(jī)作品展示效果?

1.2?煙花文案——三生煙火🌙

? 一根仙女棒可以燃燒9秒 瞬間釋放180個(gè)火焰比銀河系的星星還多 所以我喊你出來放煙花是想給你滿天繁星

? 獨(dú)看煙花綻放,獨(dú)守?zé)熁u涼
?

? 煙花轉(zhuǎn)瞬即逝,灰燼倒是永恒
?

? 我用三生煙火,還你一世迷離
?

? 你,曾如此美麗的煙花盛放在我的天空,當(dāng)煙火散盡后,我于殘?jiān)珨啾谔?#xff0c;只尋得一地的支離破碎

I will luve thee still, my dear.

While the sands o' life shall run.

?三、PART 03🌻

1.0?隨機(jī)作品展示效果?

1.2?煙花文案——十里長街🌙

? 從此煙花,不止剎那,如我的祝福,不會(huì)隨寂寞瞬間落下

? 你的出現(xiàn) 就像深夜里綻放的煙花 雖然只有一瞬間 卻照亮了我的整個(gè)人生

? 十里寒潭路,煙花一半醒

? 煙花綻放,徐徐仰望,寂寥無眠,思卿斷腸

? 長街長,煙花繁,你挑燈回看, 短亭短,紅塵輾,我把蕭再嘆

?

I will luve thee still, my dear.

While the sands o' life shall run.

四、PART 04🌻

1.0?隨機(jī)作品展示效果?

1.2?煙花文案——一眼萬年🌙

? 煙花是永遠(yuǎn)的,因?yàn)樗谖倚睦锟淘诹擞篮愕拿利悺熁ㄊ切腋5?#xff0c;因?yàn)樗约簩α粝碌乃查g肯定了自己的美麗

? 喜歡你時(shí),我的心里全都是綻放的小小煙花。那,在今年煙花盛開的時(shí)候,就讓我撲到你懷里好不好?

? 一定要和你看一場煙火大會(huì),感受一場浪漫與心動(dòng)

? 煙花絢麗綻放,一瞬即是一世。守護(hù)之心堅(jiān)定,千年亦在咫尺

? 剎那芳華,猶如指尖流沙。燦爛煙花,終究剪不下

I will luve thee still, my dear.

While the sands o' life shall run.

5)番外表白篇——玫瑰文末附代碼🍁

“誰都逃不過玫瑰 而玫瑰送誰都浪漫”

5.1 玫瑰Turtle作品一

5.2?玫瑰Turtle作品二

"我終將落俗 但浪漫不死"

總結(jié)

"哪有女孩子不喜歡鮮花不愛浪漫"! 好啦——煙花是你——玫瑰也是你!

文章就到這里就寫完啦~代碼拿去表白或者給對象叭!

???

🎯完整的源碼免費(fèi)分享滴!需要的滴滴我!

你們的支持是我最大的動(dòng)力!!記得三連哦~mua?歡迎大家閱讀往期的文章哦~

?

總結(jié)

以上是生活随笔為你收集整理的Python表白代码:“ 星光月夜烟花皆归你,我也归你”(满天烟花盛开、附番外玫瑰)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。