-
Notifications
You must be signed in to change notification settings - Fork 2
/
cTransition.py
144 lines (115 loc) · 2.87 KB
/
cTransition.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
from pygame import Rect, image, transform, draw
from random import randint
from colors import *
class cTransition:
background = None
draw_background = True
#transition T1
rects = []
active = False
growing = True
rw = 15
rh = 15
window = None
ttype = 1
#Transition t2
radius = 0
step = 10
#Trans Types
SQUARES = 1
CIRCLE = 2
TOTALTYPES = 2
def __init__(self,window):
rw = self.rw
rh = self.rh
rx = 0
ry = 0
width = window.get_width()
height = window.get_height()
self.window = window
for x in range(0,width,rw):
for y in range(0,height,rh):
self.rects.append(Rect(x,y,0,0))
def isActive(self):
return self.active
def isGrowing(self):
return self.growing
def isDrawBG(self):
if self.draw_background == None:
return False
else:
return self.draw_background
def setActive(self):
width = self.window.get_width()
height = self.window.get_height()
self.background = image.frombuffer(image.tostring(self.window,"RGB"),(width,height),"RGB")
self.ttype = randint(1,self.TOTALTYPES)
self.active = True
def setInactive(self):
self.active = False
def setBackground(self,bg):
self.background = bg
def setDrawBackground(self,bg):
self.draw_background = bg
def setGrowing(self,boolval):
self.growing = boolval
#
# GETTERS
#
def getBG(self):
return self.background
def getRects(self):
return self.rects
def getType(self):
return self.ttype
def getRadius(self):
return self.radius
#
# LOGIC
#
def logic_update(self):
if self.isActive():
if self.ttype==1:
self.logic_update_1()
elif self.ttype==2:
self.logic_update_2()
def logic_update_1(self):
if self.isGrowing():
for f in self.rects: f.inflate_ip(1,1)
fr_curr_width = self.rects[0][2]
if fr_curr_width == self.rw:
self.setGrowing(False)
self.setDrawBackground(False)
else:
for f in self.rects: f.inflate_ip(-1,-1)
fr_curr_width = self.rects[0][2]
if fr_curr_width == 0:
self.setInactive()
self.setGrowing(True)
self.setDrawBackground(True)
def logic_update_2(self):
width = self.window.get_width()
height = self.window.get_height()
if self.isGrowing():
self.radius += self.step
if self.radius >= max(width/2,height/2):
self.setGrowing(False)
self.setDrawBackground(False)
else:
self.radius -= self.step
if self.radius <= 0:
self.setInactive()
self.setGrowing(True)
self.setDrawBackground(True)
def draw_transition(self):
if self.isActive():
if self.isDrawBG():
self.window.blit(self.getBG(),self.getBG().get_rect())
if self.getType() == self.SQUARES:
for r in self.getRects():
draw.rect(self.window,black,r)
elif self.getType() == self.CIRCLE:
width = self.window.get_width()
height = self.window.get_height()
draw.circle(self.window, black, (width/2,height/2), self.getRadius())
self.logic_update()