Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw Meteor shower effect based on Python

Shulou Source: shulou.com Published: 2022-06-01 04:57:04 10月01日 Update

Today, the editor will share with you how to draw the meteor shower effect based on Python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Romantic display of meteor shower

4 Python code def bgpic (self, picname=None): "Set backgroundimage 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 [coding]) self._bgpicname = picname # coding: utf-8import pygameimport osimport sysfrom pygame.locals import * os.chdir ('confession under the stars') os.getcwd () pygame.init () pygame.mixer.init () pygame.mixer.music.load ("beauty of the stars. MP3") # pygame.mixer.music.set_volume (0.4) pygame.mixer.music.play () bg_size = width, height = 300, 200bg_rgb = (255,255) Screen1 = pygame.display.set_mode (bg_size) pygame.display.set_caption ("advertising music") 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) / / 2from turtle import * from random import random Randint os.chdir ('E: confession under the stars') screen = Screen () width, height = 900, 700screen.setup (width, height) screen.title ("romantic meteor shower") screen.bgcolor ("black") screen.mode ("logo") screen.delay (0) printer = Turtle () printer.hideturtle () printer.penup () printer.color ('red') printer.goto (- 100,350) printer.write Align= "left", font= ("Italic", 30, "bold") printer.goto (- 50,400) printer.write ("only find you! (drink only a ladle!)\ 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.01and 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 = 0pause = Falsewhile 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 # find queue event for event in pygame.event.get (): # find click close window event if event.type = = QUIT: sys.exit # find left and right mouse click event 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) these are all the contents of the article "how to draw Meteor shower effects based on Python" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Meteors meteor showers knowledge articles events advertisements starry sky effects romance content different broad large code most universe that is more knowledge points industries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Microsoft Redmi Xiaomi