gpu_particle_burst_03.py Diff

gpu_particle_burst_03.py
--- C:\Users\craven\Desktop\WebServer\arcade\doc\tutorials\gpu_particle_burst\gpu_particle_burst_02.py
+++ C:\Users\craven\Desktop\WebServer\arcade\doc\tutorials\gpu_particle_burst\gpu_particle_burst_03.py
@@ -1,6 +1,8 @@
 """
 Example showing how to create particle explosions via the GPU.
 """
+import random
+import time
 from array import array
 from dataclasses import dataclass
 import arcade
@@ -10,11 +12,14 @@
 SCREEN_HEIGHT = 768
 SCREEN_TITLE = "GPU Particle Explosion"
 
+PARTICLE_COUNT = 300
+
 @dataclass
 class Burst:
     """ Track for each burst. """
     buffer: arcade.gl.Buffer
     vao: arcade.gl.Geometry
+    start_time: float
 
 class MyWindow(arcade.Window):
     """ Main window"""
@@ -40,6 +45,9 @@
         # Loop through each burst
         for burst in self.burst_list:
 
+            # Set the uniform data
+            self.program['time'] = time.time() - burst.start_time
+
             # Render the burst
             burst.vao.render(self.program, mode=self.ctx.POINTS)
 
@@ -52,8 +60,13 @@
 
         def _gen_initial_data(initial_x, initial_y):
             """ Generate data for each particle """
-            yield initial_x
-            yield initial_y
+            for i in range(PARTICLE_COUNT):
+                dx = random.uniform(-.2, .2)
+                dy = random.uniform(-.2, .2)
+                yield initial_x
+                yield initial_y
+                yield dx
+                yield dy
 
         # Recalculate the coordinates from pixels to the OpenGL system with
         # 0, 0 at the center.
@@ -68,13 +81,13 @@
 
         # Create a buffer description that says how the buffer data is formatted.
         buffer_description = arcade.gl.BufferDescription(buffer,
-                                                         '2f',
-                                                         ['in_pos'])
+                                                         '2f 2f',
+                                                         ['in_pos', 'in_vel'])
         # Create our Vertex Attribute Object
         vao = self.ctx.geometry([buffer_description])
 
         # Create the Burst object and add it to the list of bursts
-        burst = Burst(buffer=buffer, vao=vao)
+        burst = Burst(buffer=buffer, vao=vao, start_time=time.time())
         self.burst_list.append(burst)