Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import pyglet
- import random
- from pyglet.gl import *
- from Path import Vector2
- from Path.Circle.Circle import Circle
- class Particle:
- def __init__(self, **kwargs):
- self.acceleration = Vector2(0, 0.05)
- self.velocity = Vector2(random.uniform(-1, 1), random.uniform(-1, 0))
- self.position = Vector2()
- self.time_to_live = 255
- self.numpoints = 50
- self._vertices = []
- for i in range(self.numpoints):
- angle = math.radians(float(i) / self.numpoints * 360.0)
- x = 10 * math.cos(angle) + self.velocity[0] + 300
- y = 10 * math.sin(angle) + self.velocity[1] + 400
- self._vertices += [x, y]
- def update(self, time=None):
- self.velocity += self.acceleration
- self.position -= self.velocity
- self.time_to_live -= 2
- def draw(self):
- glEnable(GL_BLEND)
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
- glPushMatrix()
- glTranslatef(self.position[0], self.position[1], 0)
- pyglet.graphics.draw(self.numpoints, GL_TRIANGLE_FAN, ('v2f', self._vertices), ('c4B', self.color))
- glPopMatrix()
- self.update()
- @property
- def is_dead(self):
- if self.time_to_live <= 0:
- return True
- return False
- @property
- def color(self):
- 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