-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspark.py
108 lines (81 loc) · 3.66 KB
/
spark.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pygame
import random
import math
from pygame.locals import *
pygame.init()
# dt it missing (the epic sumo is fps dependent)
class Spark:
sparks = {}
scroll = [0, 0]
two_pi = round(math.pi * 2) * 100
def __init__(self, pos, angle, speed, colorS, group, scale=1):
self.object_pos = pos
self.angle = angle
self.speed = speed
self.scale = scale
self.scales = [self.scale * 3.5, self.scale * 0.3]
self.color = colorS
self.group = group
# preparing math
self.cosS = math.cos(self.angle) * self.speed
self.L_cosS = math.cos(self.angle + math.pi / 2) * self.speed
self.sinS = math.sin(self.angle) * self.speed
self.L_sinS = math.sin(self.angle + math.pi / 2) * self.speed
def move(self, display):
self.object_pos[0] += self.cosS
self.object_pos[1] += self.sinS
self.draw(display)
self.speed -= 0.2
# im missing the other 2 funcs here didnt really needed them currently
self.angle += 0.1
if self.speed <= 0:
self.delete_self(self)
self.redo_math()
def draw(self, display):
scroll = self.get_scroll()
c1 = self.L_cosS * self.scales[1]
c2 = self.L_sinS * self.scales[1]
p1 = [self.object_pos[0] + self.cosS * self.scale,
self.object_pos[1] + self.sinS * self.scale]
p2 = [self.object_pos[0] + c1,
self.object_pos[1] + c2]
p3 = [self.object_pos[0] - self.cosS * self.scales[0],
self.object_pos[1] - self.sinS * self.scales[0]]
p4 = [self.object_pos[0] - c1,
self.object_pos[1] - c2]
pygame.draw.polygon(display, self.color, [[p1[0] - scroll[0], p1[1] - scroll[1]],
[p2[0] - scroll[0], p2[1] - scroll[1]],
[p3[0] - scroll[0], p3[1] - scroll[1]],
[p4[0] - scroll[0], p4[1] - scroll[1]]])
def redo_math(self):
self.cosS = math.cos(self.angle) * self.speed
self.L_cosS = math.cos(self.angle + math.pi / 2) * self.speed
self.sinS = math.sin(self.angle) * self.speed
self.L_sinS = math.sin(self.angle + math.pi / 2) * self.speed
@classmethod
def delete_self(cls, spark):
cls.sparks[spark.group].remove(spark)
@classmethod
def central(cls, group, display):
for spark in cls.sparks[group]:
spark.move(display)
# math.radians(random.randint(0, 360)),
# random.uniform(0, cls.two_pi)
@classmethod
def generate(cls, group, pos, speed_lim, color_lim, scaler):
cls.sparks[group].append(Spark(pos, random.randint(0, cls.two_pi) / 100,
random.randint(speed_lim[0], speed_lim[1]),
(random.randint(color_lim[0][0], color_lim[0][1]),
random.randint(color_lim[1][0], color_lim[1][1]),
random.randint(color_lim[2][0], color_lim[2][1])), group, scaler))
@classmethod
def create(cls, group, pos, speed_lim, color_lim, scaler, amount):
for i in range(amount):
cls.generate(group, pos.copy(), speed_lim, color_lim, scaler)
@classmethod
def create_3d(cls, group, pos, speed_lim, color_lim, scaler, amount):
for i in range(amount):
cls.generate(group, pos, speed_lim, color_lim, scaler)
@classmethod
def get_scroll(cls):
return cls.scroll