-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspinnerParticle.py
More file actions
39 lines (35 loc) · 1.36 KB
/
spinnerParticle.py
File metadata and controls
39 lines (35 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from utility import *
import pygame,random
vec = pygame.math.Vector2
from random import gauss
class SpinnerParticle():
def __init__(self,main,x,y,col,dir):
self.main = main
self.position = vec(x,y)
#random magnitude of initial velocity
self.magVel = self.RANDOM()
self.velocity = vec(-self.magVel,0).rotate(dir)
self.acceleration = vec(0,0)
self.birthTime = pygame.time.get_ticks()
self.activeDuration = 700
self.colorCollection = col
self.size = 2
def draw(self):
#selecting a random colour from colorCollection array and drawing a circle at the calculated position
choice = random.choice(self.colorCollection)
pygame.draw.circle(self.main.screen,choice,(int(self.position.x),int(self.position.y)),self.size)
def update(self):
#if survived more than lifespan then kill
now = pygame.time.get_ticks()
if now-self.birthTime > self.activeDuration:
self.main.SpinnerParticles.remove(self)
#motion
self.velocity += self.acceleration
self.position += self.velocity*self.main.dt
def RANDOM(self):
#return a gaussain random value
ran = gauss(50,1000)
if ran > 10 and ran <1000:
return ran
else:
return self.RANDOM()