基于Python實(shí)現(xiàn)流星雨效果的繪制
1 前言
我們先給個(gè)小故事,提一下大家興趣;然后我給出論據(jù),得出結(jié)論。最后再浪漫的流星雨表白代碼奉上,還有我自創(chuàng)的一首詩(shī)。開(kāi)始啦:

2 霍金說(shuō)移民外太空
霍金說(shuō)我們將來(lái)外星上生存;埃隆.馬斯克也是這樣想的。
我前面講外星人來(lái)不到地球,這個(gè)道理已經(jīng)很清楚。我再說(shuō)幾個(gè)數(shù)據(jù),大家聽(tīng)聽(tīng),我們且不要說(shuō)到更遠(yuǎn)的外星,我們?nèi)祟?lèi)今天登上月球,把一個(gè)字航員送上月球,他在月球上待一分鐘,要消耗地球一百萬(wàn)美元的資源才能在月球上待一分鐘 。
我們說(shuō)未來(lái)在火星上殖民,想想你在月球上一個(gè)人待一分鐘,要消耗地球一百萬(wàn)美元的資源,你在火星上殖民幾千人、幾萬(wàn)人,你得把整個(gè)地球資源毀滅掉,都調(diào)到火星上去。然后你只把七十億人調(diào)過(guò)去了幾千、幾萬(wàn)人,然后他在那可能死得更快,這根本不是出路,這怎么會(huì)成為出路呢?
我們?cè)倏?,移居外星,離我們地球最近的另一個(gè)恒星系叫半人馬座。半人馬座,阿爾法星
也叫比鄰星。大家注意,這都是恒星,比鄰星距離太陽(yáng)最近,有多近? 4.2光年,光以每秒鐘三十萬(wàn)公里,走4.2年,就這我們還不知道比鄰星的那個(gè)恒星旁邊有沒(méi)有行星。
就算有行星有沒(méi)有宜居行星、類(lèi)地行星。這我們還全然不知道。我們就假定那個(gè)地方有好了另一個(gè)地球,你按照今天人類(lèi)火箭和衛(wèi)星的最高速度,你單程從地球上飛到比鄰星,需要一萬(wàn)五千年到三萬(wàn)年。
請(qǐng)注意我們文明史,文明有文字,以后的文明迄今才五千年,你單程飛到那個(gè)地方要一萬(wàn)五千年以上。我說(shuō)過(guò)有沒(méi)有行星都不知道。這個(gè)前途存在嗎?根本不存在。就像外星人來(lái)不了我們這兒一樣,我們也到不了任何外星存在。
我們今天連太陽(yáng)系都沒(méi)有走出去,沒(méi)有在太陽(yáng)系的任何一個(gè)行星上殖民,所以移民外星根本不是出路。
3 浪漫的流星雨展示


動(dòng)態(tài)視頻最近幾天由于后臺(tái)服務(wù)器升級(jí),所以視頻過(guò)幾天我上傳上來(lái)。
4 Python代碼
def bgpic(self, picname=None):
"""Set background image or return name of current backgroundimage.
Optional argument:
picname -- a string, name of a gif-file or "nopic".
If picname is a filename, set the corresponding image as background.
If picname is "nopic", delete backgroundimage, if present.
If picname is None, return the filename of the current backgroundimage.
Example (for a TurtleScreen instance named screen):
>>> screen.bgpic()
'nopic'
>>> screen.bgpic("landscape.gif")
>>> screen.bgpic()
'landscape.gif'
"""
if picname is None:
return self._bgpicname
if picname not in self._bgpics:
self._bgpics[picname] = self._image(picname)
self._setbgpic(self._bgpic, self._bgpics[picname])
self._bgpicname = picname
# coding: utf-8
import pygame
import os
import sys
from pygame.locals import *
os.chdir('E:/星空下的告白')
os.getcwd()
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load("星空之美.mp3")
# pygame.mixer.music.set_volume(0.4)
pygame.mixer.music.play()
bg_size = width, height = 300, 200
bg_rgb = (255, 255, 255)
screen1 = pygame.display.set_mode(bg_size)
pygame.display.set_caption("告白音樂(lè)")
clock = pygame.time.Clock()
pause_rect = pause_image.get_rect()
print(pause_rect.width, pause_rect.height)
pause_rect.left, pause_rect.top = (width - pause_rect.width) // 2, (height - pause_rect.height) // 2
from turtle import *
from random import random, randint
os.chdir('E:星空下的告白')
screen = Screen()
width, height = 900, 700
screen.setup(width, height)
screen.title("浪漫的流星雨")
screen.bgcolor("black")
screen.mode("logo")
screen.delay(0)
printer = Turtle()
printer.hideturtle()
printer.penup()
printer.color('red')
printer.goto(-100, -350)
printer.write("宇宙廣闊(弱水三千)""\n\n", move=True, align="left", font=("Italic", 30, "bold"))
printer.goto(-50, -400)
printer.write("只尋你一顆!(只取一瓢飲!)\n\n", move=True, align="left", font=("Italic", 30, "bold"))
t = Turtle(visible=False, shape='circle')
t.pencolor("white")
t.fillcolor("white")
t.penup()
t.setheading(-90)
t.goto(width / 2, randint(-height / 2, height / 2))
stars = []
for i in range(300):
star = t.clone()
s = random() / 3
if s > 0.01 and s < 0.03:
star.pencolor("black")
star.fillcolor("black")
elif s > 0.03 and s < 0.04:
star.pencolor("lightcoral")
star.fillcolor("lightcoral")
elif s > 0.05 and s < 0.1:
star.pencolor("green")
star.fillcolor("green")
elif s > 0.15 and s < 0.16:
star.pencolor("yellow")
star.fillcolor("yellow")
elif s > 0.19 and s < 0.2:
star.pencolor("red")
star.fillcolor("red")
elif s > 0.21 and s < 0.22:
star.pencolor("purple")
star.fillcolor("purple")
elif s > 0.29 and s < 0.3:
star.pencolor("darkorange")
star.fillcolor("darkorange")
elif s > 0.31 and s < 0.32:
star.pencolor("red")
star.fillcolor("yellow")
elif s > 0.32 and s < 0.33:
star.pencolor("yellow")
star.fillcolor("white")
star.shapesize(s, s)
star.speed(int(s * 30))
star.setx(width / 2 + randint(1, width))
star.sety(randint(-height / 2, height / 2))
# star.showturtle()
stars.append(star)
i = 0
pause = False
while True:
i += 0
for star in stars:
star.setx(star.xcor() - 3 * star.speed())
if star.xcor() < -width / 2:
star.hideturtle()
star.setx(width / 2 + randint(1, width))
star.sety(randint(-height / 2, height / 2))
star.showturtle()
if i >= 100:
break
# 查找隊(duì)列事件
for event in pygame.event.get():
# 查找點(diǎn)擊關(guān)閉窗口事件
if event.type == QUIT:
sys.exit
# 查找鼠標(biāo)左右擊事件
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
pause = not pause
if event.button == 3:
pause = not pause
if event.type == KEYDOWN:
if event.key == K_SPACE:
pause = not pause
screen1.fill(bg_rgb)
if pause:
pygame.mixer.music.pause()
screen1.blit(pause_image, pause_rect)
else:
pygame.mixer.music.unpause()
screen1.blit(play_image, pause_rect)
pygame.display.flip()
clock.tick(30)到此這篇關(guān)于基于Python實(shí)現(xiàn)流星雨效果的繪制的文章就介紹到這了,更多相關(guān)Python流星雨內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python優(yōu)先隊(duì)列實(shí)現(xiàn)方法示例
這篇文章主要介紹了Python優(yōu)先隊(duì)列實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Python優(yōu)先隊(duì)列的具體定義與使用方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2017-09-09
Numpy數(shù)組的廣播機(jī)制的實(shí)現(xiàn)
這篇文章主要介紹了Numpy數(shù)組的廣播機(jī)制的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
python中json、字典的區(qū)別以及相互轉(zhuǎn)換方法
在Python中我們經(jīng)常會(huì)用到JSON格式的數(shù)據(jù),而將JSON格式轉(zhuǎn)化為Python的字典類(lèi)型是一種常見(jiàn)的操作,這篇文章主要給大家介紹了關(guān)于python中json、字典的區(qū)別以及相互轉(zhuǎn)換方法的相關(guān)資料,需要的朋友可以參考下2023-11-11
Python實(shí)例練習(xí)水仙花數(shù)問(wèn)題講解
這篇文章介紹了Python找水仙花數(shù)從分析到實(shí)現(xiàn)的過(guò)程,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
python使用信號(hào)量動(dòng)態(tài)更新配置文件的操作
這篇文章主要介紹了python使用信號(hào)量動(dòng)態(tài)更新配置文件的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04
python kafka 多線程消費(fèi)者&手動(dòng)提交實(shí)例
今天小編就為大家分享一篇python kafka 多線程消費(fèi)者&手動(dòng)提交實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12
手把手教你搭建python+selenium自動(dòng)化環(huán)境(圖文)
本文主要介紹了手把手教你搭建python+selenium自動(dòng)化環(huán)境,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06

