Advertisement
Guest User

Untitled

a guest
Dec 25th, 2017
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. import math
  2. import pyglet
  3. import random
  4.  
  5. from pyglet.gl import *
  6.  
  7. from Path import Vector2
  8. from Path.Circle.Circle import Circle
  9.  
  10.  
  11. class Particle:
  12.  
  13.     def __init__(self, **kwargs):
  14.         self.acceleration = Vector2(0, 0.05)
  15.         self.velocity = Vector2(random.uniform(-1, 1), random.uniform(-1, 0))
  16.         self.position = Vector2()
  17.         self.time_to_live = 255
  18.  
  19.         self.numpoints = 50
  20.  
  21.         self._vertices = []
  22.  
  23.         for i in range(self.numpoints):
  24.             angle = math.radians(float(i) / self.numpoints * 360.0)
  25.             x = 10 * math.cos(angle) + self.velocity[0] + 300
  26.             y = 10 * math.sin(angle) + self.velocity[1] + 400
  27.             self._vertices += [x, y]
  28.  
  29.     def update(self, time=None):
  30.         self.velocity += self.acceleration
  31.         self.position -= self.velocity
  32.         self.time_to_live -= 2
  33.  
  34.     def draw(self):
  35.         glEnable(GL_BLEND)
  36.         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
  37.         glPushMatrix()
  38.         glTranslatef(self.position[0], self.position[1], 0)
  39.         pyglet.graphics.draw(self.numpoints, GL_TRIANGLE_FAN, ('v2f', self._vertices), ('c4B', self.color))
  40.         glPopMatrix()
  41.  
  42.         self.update()
  43.  
  44.     @property
  45.     def is_dead(self):
  46.         if self.time_to_live <= 0:
  47.             return True
  48.         return False
  49.  
  50.     @property
  51.     def color(self):
  52.         return tuple(color for i in range(self.numpoints) for color in (255, 255, 255,  self.time_to_live))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement