-
Notifications
You must be signed in to change notification settings - Fork 1
/
fires.py
176 lines (142 loc) · 7.4 KB
/
fires.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from visual import *
import thread
import random
import math
class Fires:
def __init__(self):
self.ball = sphere(pos=(0,0,0), radius=0.05, color=vector(0,0,0), visible=False)
self.dt = 0.01
self.totaldt = 0
self.fires = []#set small balls
self.tail = []#set retain tails by small balls
self.swi = False
def __del__(self):
print ("dell")
def setColor(self,r,g,b):
self.ball.color = vector(r,g,b)
def rann(self):#0~2pi random number
return random.random()*2*math.pi
def funcInit(self,x,y,z,h,a,u):
self.ball.pos = (x,y,z) #(x,y,z): balls position
self.ball.velocity = vector(0,h,0) #h: bigball yaxis velocity
self.a = a #a: explosion speed of small balls
self.u = u #u: fireworks axis tilt angle
def run_Twinkle(self,x,y,z,h,a,u):
self.funcInit(x,y,z,h,a,u)
self.ball.visible=True
while 1:
rate(100)
self.ball.pos = self.ball.pos + self.ball.velocity*self.dt
self.ball.velocity.y = self.ball.velocity.y-10*self.dt
#generating small balls, once original ball reached an apex
if self.ball.velocity.y <= 0.5 and not self.swi:
self.ball.visible = False
for i in range(300) :
self.tt = self.rann()#theta
self.tp = self.rann()/2#pi
self.tx = 0.1*math.sin(self.tp)*math.cos(self.tt)
self.ty = 0.1*math.sin(self.tp)*math.sin(self.tt)
self.tz = 0.1*math.cos(self.tp)
self.fires.append(sphere(pos=(self.ball.x+self.tx, self.ball.y+self.ty, self.ball.z+self.tz),
velocity=vector(self.tx*self.a, self.ty*self.a, self.tz*self.a),
radius=0.02, color=self.ball.color, opacity=1))
self.swi = True #explosion swich on.
if self.swi:
self.totaldt += self.dt*100
opacity = 1.
for i in range(300) :
self.fires[i].pos = self.fires[i].pos +self.fires[i].velocity*self.dt
self.fires[i].velocity.y = self.fires[i].velocity.y-0.5*self.dt
self.fires[i].opacity = self.fires[i].opacity-0.5*self.dt
randNum = random.randrange(0,2)
self.fires[i].color = (randNum, randNum, randNum)
if self.totaldt == 300:
break
def run_Fire(self,x,y,z,h,a,u):
self.funcInit(x,y,z,h,a,u)
self.ball.visible=True
while 1:
rate(100)
self.ball.pos = self.ball.pos + self.ball.velocity*self.dt
self.ball.velocity.y = self.ball.velocity.y-10*self.dt
#generating small balls, once original ball reached an apex
if self.ball.velocity.y <= 0.5 and not self.swi:
self.ball.visible = False
for i in range(100):
self.tt = self.rann()#theta
self.tp = self.rann()/2#pi
self.tx = 0.1*math.sin(self.tp)*math.cos(self.tt)
self.ty = 0.1*math.sin(self.tp)*math.sin(self.tt)
self.tz = 0.1*math.cos(self.tp)
self.fires.append(sphere(pos=(self.ball.x+self.tx, self.ball.y+self.ty, self.ball.z+self.tz),
velocity=vector(self.tx*self.a, self.ty*self.a, self.tz*self.a),
radius=0.02, color=self.ball.color, opacity=1))
# self.tail.append(curve(pos=(self.ball.x+self.tx, self.ball.y+self.ty, self.ball.z+self.tz),
# radius=0.01,color=self.ball.color))
self.swi = True #explosion swich on.
if self.swi:
self.totaldt += self.dt*100
for i in range(100):
self.fires[i].pos = self.fires[i].pos +self.fires[i].velocity*self.dt
self.fires[i].velocity.y = self.fires[i].velocity.y - 0.5 *self.dt
self.fires[i].opacity = self.fires[i].opacity-0.5*self.dt
# self.tail[i].append(pos=self.fires[i].pos, retain=40)
# self.tail[i].color = self.tail[i].color-(0.3*self.dt,0.3*self.dt,0.3*self.dt)
if self.totaldt == 300:
break
def run_Circle(self,x,y,z,h,a,u):
self.funcInit(x,y,z,h,a,u)
self.ball.visible=True
while 1:
rate(100)
self.ball.pos = self.ball.pos + self.ball.velocity*self.dt
self.ball.velocity.y = self.ball.velocity.y-10*self.dt
#generating small balls, once original ball reached an apex
if self.ball.velocity.y <= 0.5 and not self.swi:
self.ball.visible = False
for i in range(100) :
self.tt = self.rann()#theta
self.tp = self.rann()/2#pi
self.tx = 0.1*math.cos(self.tt)
self.ty = 0.1*math.sin(self.tt+self.u)
self.tz = 0.1*math.cos(self.tt+0.5)
self.fires.append(sphere(pos=(self.ball.x+self.tx, self.ball.y+self.ty, self.ball.z+self.tz),
velocity=vector(self.tx*self.a, self.ty*self.a, self.tz*self.a),
radius=0.02, color=self.ball.color, opacity=1))
self.swi = True #explosion swich on.
if self.swi:
self.totaldt += self.dt*100
for i in range(100) :
self.fires[i].pos = self.fires[i].pos +self.fires[i].velocity*self.dt
self.fires[i].velocity.y = self.fires[i].velocity.y - 0.5 *self.dt
self.fires[i].opacity = self.fires[i].opacity-0.5*self.dt
if self.totaldt == 300:
break
def run_8form(self,x,y,z,h,a,u):
self.funcInit(x,y,z,h,a,u)
self.ball.visible=True
while 1:
rate(100)
self.ball.pos = self.ball.pos + self.ball.velocity*self.dt
self.ball.velocity.y = self.ball.velocity.y-10*self.dt
#generating small balls, once original ball reached an apex
if self.ball.velocity.y <= 0.5 and not self.swi:
self.ball.visible = False
for i in range(100) :
self.tt = self.rann()#theta
self.tp = self.rann()/2#pi
self.tx = 0.1*math.sin(self.tt)*math.cos(self.tt)
self.ty = 0.1*math.cos(self.tt+self.u)
self.tz = 0.1*math.sin(self.tt)
self.fires.append(sphere(pos=(self.ball.x+self.tx, self.ball.y+self.ty, self.ball.z+self.tz),
velocity=vector(self.tx*self.a, self.ty*self.a, self.tz*self.a),
radius=0.02, color=self.ball.color, opacity=1))
self.swi = True #explosion swich on.
if self.swi == 1:
self.totaldt += self.dt*100
for i in range(100) :
self.fires[i].pos = self.fires[i].pos +self.fires[i].velocity*self.dt
self.fires[i].velocity.y = self.fires[i].velocity.y - 0.5 *self.dt
self.fires[i].opacity = self.fires[i].opacity-0.5*self.dt
if self.totaldt == 300:
break