基于Python实现流星雨效果的绘制


Posted in Python onMarch 18, 2022

1 前言

我们先给个小故事,提一下大家兴趣;然后我给出论据,得出结论。最后再浪漫的流星雨表白代码奉上,还有我自创的一首诗。开始啦:

  

基于Python实现流星雨效果的绘制

2 霍金说移民外太空

霍金说我们将来外星上生存;埃隆.马斯克也是这样想的。

我前面讲外星人来不到地球,这个道理已经很清楚。我再说几个数据,大家听听,我们且不要说到更远的外星,我们人类今天登上月球,把一个字航员送上月球,他在月球上待一分钟,要消耗地球一百万美元的资源才能在月球上待一分钟 。

我们说未来在火星上殖民,想想你在月球上一个人待一分钟,要消耗地球一百万美元的资源,你在火星上殖民几千人、几万人,你得把整个地球资源毁灭掉,都调到火星上去。然后你只把七十亿人调过去了几千、几万人,然后他在那可能死得更快,这根本不是出路,这怎么会成为出路呢?

我们再看,移居外星,离我们地球最近的另一个恒星系叫半人马座。半人马座,阿尔法星

也叫比邻星。大家注意,这都是恒星,比邻星距离太阳最近,有多近?  4.2光年,光以每秒钟三十万公里,走4.2年,就这我们还不知道比邻星的那个恒星旁边有没有行星。

就算有行星有没有宜居行星、类地行星。这我们还全然不知道。我们就假定那个地方有好了另一个地球,你按照今天人类火箭和卫星的最高速度,你单程从地球上飞到比邻星,需要一万五千年到三万年。

请注意我们文明史,文明有文字,以后的文明迄今才五千年,你单程飞到那个地方要一万五千年以上。我说过有没有行星都不知道。这个前途存在吗?根本不存在。就像外星人来不了我们这儿一样,我们也到不了任何外星存在。

我们今天连太阳系都没有走出去,没有在太阳系的任何一个行星上殖民,所以移民外星根本不是出路。

3 浪漫的流星雨展示 

基于Python实现流星雨效果的绘制

基于Python实现流星雨效果的绘制

动态视频最近几天由于后台服务器升级,所以视频过几天我上传上来。 

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("告白音乐")
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
 
    # 查找队列事件
    for event in pygame.event.get():
        # 查找点击关闭窗口事件
        if event.type == QUIT:
            sys.exit
        # 查找鼠标左右击事件
        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)

到此这篇关于基于Python实现流星雨效果的绘制的文章就介绍到这了,更多相关Python流星雨内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Python 相关文章推荐
python实现12306抢票及自动邮件发送提醒付款功能
Mar 08 Python
PyQt5每天必学之弹出消息框
Apr 19 Python
深入分析python数据挖掘 Json结构分析
Apr 21 Python
Python爬虫信息输入及页面的切换方法
May 11 Python
Python3+Pycharm+PyQt5环境搭建步骤图文详解
May 29 Python
pandas中遍历dataframe的每一个元素的实现
Oct 23 Python
tensorflow mnist 数据加载实现并画图效果
Feb 05 Python
Sublime Text3最新激活注册码分享适用2020最新版 亲测可用
Nov 12 Python
Pandas的数据过滤实现
Jan 15 Python
python工具——Mimesis的简单使用教程
Jan 16 Python
python爬虫爬取图片的简单代码
Jan 18 Python
Python通过m3u8文件下载合并ts视频的操作
Apr 16 Python
Python中with上下文管理协议的作用及用法
Mar 18 #Python
python 判断文件或文件夹是否存在
Mar 18 #Python
分享Python获取本机IP地址的几种方法
Mar 17 #Python
使用python求解迷宫问题的三种实现方法
Python超详细分步解析随机漫步
yolov5返回坐标的方法实例
Mar 17 #Python
PyTorch中的torch.cat简单介绍
Mar 17 #Python
You might like
php中实现用数组妩媚地生成要执行的sql语句
2015/07/10 PHP
简单谈谈PHP中的Reload操作
2016/12/12 PHP
解决安装WampServer时提示缺少msvcr110.dll文件的问题
2017/07/09 PHP
ThinkPHP3.2.3框架实现执行原生SQL语句的方法示例
2019/04/03 PHP
PHP笛卡尔积实现原理及代码实例
2020/12/09 PHP
一个加密JavaScript的开源工具PACKER2.0.2
2006/11/04 Javascript
非常实用的12个jquery代码片段
2015/11/02 Javascript
分类解析jQuery选择器
2016/11/23 Javascript
微信小程序开发之Tabbar实例详解
2017/01/09 Javascript
Easyui笔记2:实现datagrid多行删除的示例代码
2017/01/14 Javascript
从零学习node.js之文件操作(三)
2017/02/21 Javascript
JS实现简单的选择题测评系统代码思路详解(demo)
2017/09/03 Javascript
Angular中的$watch方法详解
2017/09/18 Javascript
jQuery实现的鼠标滚轮控制图片缩放功能实例
2017/10/14 jQuery
微信小程序MUI侧滑导航菜单示例(Popup弹出式,左侧不动,右侧滑动)
2019/01/23 Javascript
vue实现文字横向无缝走马灯组件效果的实例代码
2019/04/09 Javascript
js获取浏览器地址(获取第1个斜杠后的内容)
2019/09/03 Javascript
[01:00:14]DOTA2官方TI8总决赛纪录片 真视界True Sight
2019/01/16 DOTA
Python易忽视知识点小结
2015/05/25 Python
快速了解Python开发中的cookie及简单代码示例
2018/01/17 Python
tensorflow建立一个简单的神经网络的方法
2018/02/10 Python
python列表list保留顺序去重的实例
2018/12/14 Python
python利用thrift服务读取hbase数据的方法
2018/12/27 Python
深入解析python中的实例方法、类方法和静态方法
2019/03/11 Python
python文件读写代码实例
2019/10/21 Python
python爬虫开发之Request模块从安装到详细使用方法与实例全解
2020/03/09 Python
Python的in,is和id函数代码实例
2020/04/18 Python
通俗易懂了解Python装饰器原理
2020/09/17 Python
scrapy在python爬虫中搭建出错的解决方法
2020/11/22 Python
Canvas 文本转粒子效果的实现代码
2019/02/14 HTML / CSS
会走动的图形html5时钟示例
2014/04/27 HTML / CSS
亿阳信通股份有限公司C#笔试题
2016/12/06 面试题
销售人员自我评价怎么写
2013/09/19 职场文书
自强之星事迹材料
2014/05/12 职场文书
2014年社区卫生工作总结
2014/12/18 职场文书
2016年党员干部廉政承诺书
2016/03/24 职场文书