66If Python and Arcade are installed, this example can be run from the command line with:
77python -m arcade.examples.particle_fireworks
88"""
9+
910import random
1011from typing import Optional
1112
1213import pyglet
1314from pyglet .math import Vec2
1415
1516import arcade
16- from arcade .types import Point , PathOrTexture
17+ from arcade .types import Point , PathOrTexture , LBWH
1718from arcade .math import rand_in_rect , clamp , lerp , rand_in_circle , rand_on_circle
1819from arcade .particles import (
1920 Emitter ,
2324 EmitMaintainCount ,
2425 EmitBurst ,
2526)
26- from arcade import LBWH
27-
2827
2928SCREEN_WIDTH = 800
3029SCREEN_HEIGHT = 600
@@ -68,10 +67,8 @@ def make_spinner():
6867 center_xy = (SCREEN_WIDTH / 2 , SPINNER_HEIGHT - 5 ),
6968 emit_controller = EmitterIntervalWithTime (0.025 , 2.0 ),
7069 particle_factory = lambda emitter : FadeParticle (
71- filename_or_texture = random .choice (STAR_TEXTURES ),
72- change_xy = (0 , 6.0 ),
73- lifetime = 0.2
74- )
70+ filename_or_texture = random .choice (STAR_TEXTURES ), change_xy = (0 , 6.0 ), lifetime = 0.2
71+ ),
7572 )
7673 spinner .change_angle = 16.28
7774 return spinner
@@ -89,9 +86,9 @@ def make_rocket(emit_done_cb):
8986 lifetime = random .uniform (1.0 , 1.5 ),
9087 start_alpha = 100 ,
9188 end_alpha = 0 ,
92- mutation_callback = rocket_smoke_mutator
89+ mutation_callback = rocket_smoke_mutator ,
9390 ),
94- emit_done_cb = emit_done_cb
91+ emit_done_cb = emit_done_cb ,
9592 )
9693 rocket .change_x = random .uniform (- 1.0 , 1.0 )
9794 rocket .change_y = random .uniform (5.0 , 7.25 )
@@ -104,10 +101,8 @@ def make_flash(prev_emitter):
104101 center_xy = prev_emitter .get_pos (),
105102 emit_controller = EmitBurst (3 ),
106103 particle_factory = lambda emitter : FadeParticle (
107- filename_or_texture = FLASH_TEXTURE ,
108- change_xy = rand_in_circle ((0.0 , 0.0 ), 3.5 ),
109- lifetime = 0.15
110- )
104+ filename_or_texture = FLASH_TEXTURE , change_xy = rand_in_circle ((0.0 , 0.0 ), 3.5 ), lifetime = 0.15
105+ ),
111106 )
112107
113108
@@ -119,38 +114,40 @@ def make_puff(prev_emitter):
119114 particle_factory = lambda emitter : FadeParticle (
120115 filename_or_texture = PUFF_TEXTURE ,
121116 change_xy = Vec2 (* rand_in_circle ((0.0 , 0.0 ), 0.4 )) + Vec2 (0.3 , 0.0 ),
122- lifetime = 4.0
123- )
117+ lifetime = 4.0 ,
118+ ),
124119 )
125120
126121
127122class AnimatedAlphaParticle (LifetimeParticle ):
128123 """A custom particle that animates between three different alpha levels"""
129124
130125 def __init__ (
131- self ,
132- filename_or_texture : Optional [PathOrTexture ],
133- change_xy : Vec2 ,
134- start_alpha : int = 0 ,
135- duration1 : float = 1.0 ,
136- mid_alpha : int = 255 ,
137- duration2 : float = 1.0 ,
138- end_alpha : int = 0 ,
139- center_xy : Point = (0.0 , 0.0 ),
140- angle : float = 0 ,
141- change_angle : float = 0 ,
142- scale : float = 1.0 ,
143- mutation_callback = None ,
126+ self ,
127+ filename_or_texture : Optional [PathOrTexture ],
128+ change_xy : Vec2 ,
129+ start_alpha : int = 0 ,
130+ duration1 : float = 1.0 ,
131+ mid_alpha : int = 255 ,
132+ duration2 : float = 1.0 ,
133+ end_alpha : int = 0 ,
134+ center_xy : Point = (0.0 , 0.0 ),
135+ angle : float = 0 ,
136+ change_angle : float = 0 ,
137+ scale : float = 1.0 ,
138+ mutation_callback = None ,
144139 ):
145- super ().__init__ (filename_or_texture ,
146- change_xy ,
147- duration1 + duration2 ,
148- center_xy ,
149- angle ,
150- change_angle ,
151- scale ,
152- start_alpha ,
153- mutation_callback )
140+ super ().__init__ (
141+ filename_or_texture ,
142+ change_xy ,
143+ duration1 + duration2 ,
144+ center_xy ,
145+ angle ,
146+ change_angle ,
147+ scale ,
148+ start_alpha ,
149+ mutation_callback ,
150+ )
154151 self .start_alpha = start_alpha
155152 self .in_duration = duration1
156153 self .mid_alpha = mid_alpha
@@ -197,8 +194,8 @@ def __init__(self):
197194 mid_alpha = 128 ,
198195 duration2 = random .uniform (2.0 , 6.0 ),
199196 end_alpha = 0 ,
200- center_xy = rand_in_rect (LBWH (0.0 , 0.0 , SCREEN_WIDTH , SCREEN_HEIGHT ))
201- )
197+ center_xy = rand_in_rect (LBWH (0.0 , 0.0 , SCREEN_WIDTH , SCREEN_HEIGHT )),
198+ ),
202199 )
203200 self .emitters .append (stars )
204201
@@ -217,8 +214,8 @@ def __init__(self):
217214 mid_alpha = 255 ,
218215 duration2 = random .uniform (5.0 , 10.0 ),
219216 end_alpha = 0 ,
220- center_xy = rand_in_circle ((0.0 , 0.0 ), 50 )
221- )
217+ center_xy = rand_in_circle ((0.0 , 0.0 ), 50 ),
218+ ),
222219 )
223220 self .emitters .append (self .cloud )
224221
@@ -237,7 +234,7 @@ def launch_random_firework(self, _delta_time):
237234 self .emitters .append (rocket )
238235
239236 def launch_ringed_firework (self , _delta_time ):
240- """"Firework that has a basic explosion and a ring of sparks of a different color"""
237+ """ "Firework that has a basic explosion and a ring of sparks of a different color"""
241238 rocket = make_rocket (self .explode_ringed_firework )
242239 self .emitters .append (rocket )
243240
@@ -267,8 +264,8 @@ def explode_firework(self, prev_emitter):
267264 filename_or_texture = spark_texture ,
268265 change_xy = rand_in_circle (center = (0.0 , 0.0 ), radius = 9.0 ),
269266 lifetime = random .uniform (0.5 , 1.2 ),
270- mutation_callback = firework_spark_mutator
271- )
267+ mutation_callback = firework_spark_mutator ,
268+ ),
272269 )
273270 self .emitters .append (sparks )
274271
@@ -285,8 +282,8 @@ def explode_ringed_firework(self, prev_emitter):
285282 filename_or_texture = spark_texture ,
286283 change_xy = rand_in_circle ((0.0 , 0.0 ), 8.0 ),
287284 lifetime = random .uniform (0.55 , 0.8 ),
288- mutation_callback = firework_spark_mutator
289- )
285+ mutation_callback = firework_spark_mutator ,
286+ ),
290287 )
291288 self .emitters .append (sparks )
292289
@@ -297,8 +294,8 @@ def explode_ringed_firework(self, prev_emitter):
297294 filename_or_texture = ring_texture ,
298295 change_xy = rand_on_circle (center = (0.0 , 0.0 ), radius = 5.0 ),
299296 lifetime = random .uniform (1.0 , 1.6 ),
300- mutation_callback = firework_spark_mutator
301- )
297+ mutation_callback = firework_spark_mutator ,
298+ ),
302299 )
303300 self .emitters .append (ring )
304301
@@ -319,8 +316,8 @@ def explode_sparkle_firework(self, prev_emitter):
319316 mid_alpha = 0 ,
320317 duration2 = random .uniform (0.1 , 0.2 ),
321318 end_alpha = 255 ,
322- mutation_callback = firework_spark_mutator
323- )
319+ mutation_callback = firework_spark_mutator ,
320+ ),
324321 )
325322 self .emitters .append (sparks )
326323
0 commit comments