最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用Python繪制虎年煙花秀

 更新時(shí)間:2022年01月26日 14:57:18   作者:川川菜鳥  
2022虎年新年即將來臨,小編為大家?guī)砹艘粋€(gè)利用Python編寫的虎年煙花特效,文中的示例代碼簡潔易懂,感興趣的同學(xué)可以動(dòng)手試一試

一、演示效果

b站:虎年煙花演示

二、python代碼

import pygame
from math import *
from pygame.locals import *

import random


class firew:
? ??
? ? def __init__(self, pos, color, light, size, move):
? ? ? ? self.pos = list(pos)
? ? ? ? self.color = list(color)
? ? ? ? self.light = light
? ? ? ? self.size = size
? ? ? ??
? ? ? ? self.move = list(move)
? ??
? ? def force(self, force):
? ? ? ? self.move[0] += force[0]
? ? ? ? self.move[1] += force[1]

? ? ? ? self.move[0] *= force[2]
? ? ? ? self.move[1] *= force[2]
? ??
? ? def update(self):
? ? ? ? self.pos[0] += self.move[0]
? ? ? ? self.pos[1] += self.move[1]

? ? def render(self, fenster, glitter):
? ? ? ? glitter = (glitter and random.randint(40, 100)/100) or 1
? ? ? ? c = rund( mult(self.color, self.light*glitter) )
? ? ? ? rad = int(round(self.light* self.size))
? ? ? ? rad += rad < 1
? ? ? ? #print(c)
? ? ? ??
? ? ? ? pygame.draw.circle(fenster, c, rund(self.pos), rad)
? ? ? ??

def summon(fws, pos, pre_move = [0,0]):
? ? mix.stop()
? ? #anz = random.randint(30, 250)
? ? anz = random.randint(200, 350)
? ? r = random.randint(0, 255)
? ? g = random.randint(0, 255)
? ? b = random.randint(0, 255)
? ??
? ? ? ??
? ? for i in range(anz):
? ? ? ? ang = random.randint(0, 360) ? ? ? ?
? ? ? ? speed = random.randint(100, 1000) / 250
? ? ? ??
? ? ? ? move = (cos(radians(ang))*speed + pre_move[0],
? ? ? ? ? ? ? ? sin(radians(ang))*speed + pre_move[1])

? ? ? ? light = random.randint(60, 100)/100
? ? ? ? size = random.randint(100, 300)/100
? ? ? ??
? ? ? ? fws.append( firew(pos, (r,g,b), light, size, move) )

? ? # Sound abspielen
? ? l, r = ( 0.2 + 0.8*(ww-pos[0])/ww, 0.2 + 0.8*pos[0]/ww )
? ? mix.set_volume(l, r)
? ??
? ? mix.play(sound)

? ? return fws


def rund(liste):
? ? new = []
? ? for i in liste:
? ? ? ? new.append(int(round(i)))
? ??
? ? return new

def mult(color, multi):
? ? new = list(color)
? ? new[0] *= multi
? ? new[1] *= multi
? ? new[2] *= multi
? ??
? ? return new


pygame.init()

sound = pygame.mixer.Sound("firew.wav")
mix = pygame.mixer.Channel(0)
mix.set_volume(1, 1)

bg = (0, 0, 0)
ww, wh = (1200, 800)
fenster = pygame.display.set_mode((ww, wh))
#pygame.display.set_caption("[Leertaste] für Pause; [c] für automatisches Feuerwerk")


fws = [] # firework particles
rockets = []
force = [0, 0.02, 0.985]

max_counter = random.randint(0, 200)
counter = max_counter

auto ?= True
pause = False

run = 1
clock = pygame.time.Clock()

while run:
? ? pygame.display.set_caption("[Spacebar] to pause; [c] disable automatic fireworks")
? ? counter -= (auto and not pause)

? ? if counter <= 0: # neues erstellen
? ? ? ? #pos = [random.randint(ww*1/4, ww*3/4), random.randint(wh*1/4, wh*3/5)]
? ? ? ? pos = [random.randint(ww*2/5, ww*3/5), wh]
? ? ? ? move = [random.randint(-100, 100)/100, -random.randint(800, 1500)/110]
? ? ? ??
? ? ? ? rockets.append( firew(pos, (255, 255, 255), 1, 2, move) )
? ? ? ??
? ? ? ? #fuse = random.randint(50, 150) # Zuendschnur
? ? ? ? fuse = random.randint(50, 80)
? ? ? ? rockets[-1].fuse = fuse

? ? ? ? #fws = summon(fws, pos)
? ? ? ??
? ? ? ? max_counter = random.randint(10, 100)
? ? ? ? counter = max_counter

? ? for e in pygame.event.get():
? ? ? ? if e.type == QUIT:
? ? ? ? ? ? run = 0
? ? ? ? if e.type == KEYDOWN:
? ? ? ? ? ? if e.key == K_c:
? ? ? ? ? ? ? ? auto = not auto
? ? ? ? ? ? if e.key == K_SPACE:
? ? ? ? ? ? ? ? pause = not pause
? ? ? ? ? ? if e.key == K_v:
? ? ? ? ? ? ? ? fws = []; rockets = []
? ? ? ? ? ??
? ? ? ? if e.type == MOUSEBUTTONDOWN:
? ? ? ? ? ? fws = summon(fws, e.pos)
? ? ? ??

? ? fenster.fill(bg)
? ? dellist1 = []
? ? dellist2 = []

? ? for i, rocket in enumerate(rockets):
? ? ? ? if not pause:
? ? ? ? ? ? rocket.force(force)
? ? ? ? ? ? rocket.update()
? ? ? ? ? ??
? ? ? ? rocket.render(fenster, False)
? ? ? ? rocket.fuse -= not pause
? ? ? ??
? ? ? ? if rocket.fuse < 0:
? ? ? ? ? ? dellist1.append(i)
? ? ? ? ? ? # explosion erschaffen
? ? ? ? ? ? fws = summon(fws, rocket.pos, rocket.move)
? ? ? ? ? ??
? ??
? ? for i, f in enumerate(fws):
? ? ? ? if not pause:
? ? ? ? ? ? f.force(force)
? ? ? ? ? ? f.update()


? ? ? ? f.render(fenster, True and not pause)

? ? ? ? f.light -= (not pause) * random.randint(0, 150) / 7500

? ? ? ? if f.light < 0:
? ? ? ? ? ? dellist2.append(i)

? ? dellist1.reverse()
? ? dellist2.reverse()
? ??
? ? for d in dellist1:
? ? ? ? del rockets[d]
? ? for d in dellist2:
? ? ? ? del fws[d]

? ? pygame.display.update()
? ? clock.tick(80)


pygame.quit()

演示:

三、前端代碼

效果:

到此這篇關(guān)于利用Python繪制虎年煙花秀的文章就介紹到這了,更多相關(guān)Python虎年煙花秀內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python 安裝virtualenv和virtualenvwrapper的方法

    python 安裝virtualenv和virtualenvwrapper的方法

    下面小編就為大家?guī)硪黄猵ython 安裝virtualenv和virtualenvwrapper的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • python將數(shù)據(jù)插入數(shù)據(jù)庫的代碼分享

    python將數(shù)據(jù)插入數(shù)據(jù)庫的代碼分享

    在本篇文章里小編給大家整理的是關(guān)于python將數(shù)據(jù)插入數(shù)據(jù)庫的代碼內(nèi)容,有興趣的朋友們可以參考下。
    2020-08-08
  • 簡單了解django索引的相關(guān)知識(shí)

    簡單了解django索引的相關(guān)知識(shí)

    這篇文章主要介紹了簡單了解django索引的相關(guān)知識(shí),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • Python連接HDFS實(shí)現(xiàn)文件上傳下載及Pandas轉(zhuǎn)換文本文件到CSV操作

    Python連接HDFS實(shí)現(xiàn)文件上傳下載及Pandas轉(zhuǎn)換文本文件到CSV操作

    這篇文章主要介紹了Python連接HDFS實(shí)現(xiàn)文件上傳下載及Pandas轉(zhuǎn)換文本文件到CSV操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • Python中bytes字節(jié)串和string字符串之間的轉(zhuǎn)換方法

    Python中bytes字節(jié)串和string字符串之間的轉(zhuǎn)換方法

    python中字節(jié)字符串不能格式化,獲取到的網(wǎng)頁有時(shí)候是字節(jié)字符串,需要轉(zhuǎn)化后再解析,下面這篇文章主要給大家介紹了關(guān)于Python中bytes字節(jié)串和string字符串之間的轉(zhuǎn)換方法,需要的朋友可以參考下
    2022-01-01
  • python通過re正則表達(dá)式切割中英文的操作

    python通過re正則表達(dá)式切割中英文的操作

    這篇文章主要介紹了python通過re正則表達(dá)式切割中英文的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • Python實(shí)現(xiàn)DBSCAN聚類算法并樣例測試

    Python實(shí)現(xiàn)DBSCAN聚類算法并樣例測試

    聚類是一種機(jī)器學(xué)習(xí)技術(shù),它涉及到數(shù)據(jù)點(diǎn)的分組,聚類是一種無監(jiān)督學(xué)習(xí)的方法,是許多領(lǐng)域中常用的統(tǒng)計(jì)數(shù)據(jù)分析技術(shù)。本文給大家分享Python實(shí)現(xiàn)DBSCAN聚類算法并樣例測試,感興趣的朋友一起看看吧
    2021-06-06
  • python數(shù)學(xué)建模之Numpy?應(yīng)用介紹與Pandas學(xué)習(xí)

    python數(shù)學(xué)建模之Numpy?應(yīng)用介紹與Pandas學(xué)習(xí)

    這篇文章主要介紹了python數(shù)學(xué)建模之Numpy?應(yīng)用介紹與Pandas學(xué)習(xí),NumPy?是一個(gè)運(yùn)行速度非??斓臄?shù)學(xué)庫,一個(gè)開源的的python科學(xué)計(jì)算庫,主要用于數(shù)組、矩陣計(jì)算
    2022-07-07
  • python3多線程中使用線程睡眠的方法實(shí)現(xiàn)

    python3多線程中使用線程睡眠的方法實(shí)現(xiàn)

    線程睡眠是一個(gè)常見且有用的工具,用于控制線程的執(zhí)行順序和速度,本文主要介紹了python3多線程中使用線程睡眠的方法實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-08-08
  • python多進(jìn)程并發(fā)demo實(shí)例解析

    python多進(jìn)程并發(fā)demo實(shí)例解析

    這篇文章主要介紹了python多進(jìn)程并發(fā)demo實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12

最新評(píng)論

兰坪| 祥云县| 称多县| 措勤县| 措美县| 新疆| 靖安县| 黔江区| 南江县| 子长县| 福泉市| 邛崃市| 江北区| 杨浦区| 新野县| 西充县| 南投市| 宝坻区| 甘孜| 张掖市| 龙里县| 洪洞县| 金川县| 永和县| 东兴市| 安化县| 阜平县| 麻城市| 尼勒克县| 屯门区| 钟山县| 灌云县| 历史| 霍邱县| 五华县| 武威市| 汉沽区| 莱阳市| 贵定县| 隆德县| 军事|