-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdesign.py
185 lines (157 loc) · 6.42 KB
/
design.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
176
177
178
179
180
181
182
183
184
185
import pygame
pygame.init()
import random as r
import colors as c
class Background:
def __init__(self,window,pop= 100,style = 1):
self.squares = []
self.squares = []
self.population = pop
self.maxsize = 150
self.choice = [-1,1]
self.style = style
self.reset_bg(window)
def reset_bg(self,window):
if self.style ==1:
self.reset_bg1(window)
if self.style ==2:
self.reset_bg2(window)
if self.style ==3:
self.reset_bg3(window)
if self.style ==4:
self.reset_bg4(window)
def reset_bg4(self,window):
if self.squares:
for a in range(self.population):
self.squares.pop()
newlist = c.colorlist[2:4]
for a in range(self.population):
coo = (r.randint(0,window.get_width()),r.randint(0,window.get_height()))
coloro = r.choice(newlist)
raa = r.randint(0,100)/1000
raa = r.choice(self.choice) * raa
self.squares.append(Square(coo,r.randint(10,self.maxsize-50),coloro,raa))
def reset_bg2(self,window):
if self.squares:
for a in range(self.population):
self.squares.pop()
for a in range(self.population):
neon = r.randint(10,20)
coo = (r.randint(0,window.get_width()),r.randint(0,window.get_height()))
coloro = (0,neon,neon)
raa = r.randint(0,10)/1000
raa = r.choice(self.choice) * raa
self.squares.append(Square(coo,r.randint(30,self.maxsize-100),coloro,raa,1))
def reset_bg3(self,window):
if self.squares:
for a in range(self.population):
self.squares.pop()
for a in range(self.population):
neon = r.randint(30,60)
coo = (r.randint(0,window.get_width()),r.randint(0,window.get_height()))
coloro = (0,neon,neon)
raa = r.randint(0,100)/200
self.squares.append(Square(coo,r.randint(5,self.maxsize-100),coloro,raa))
def reset_bg1(self,window):
if self.squares:
for a in range(self.population):
self.squares.pop()
newlist = c.colorlist[2:8]
for a in range(self.population):
# neon = r.randint(30,90)
coo = (r.randint(0,window.get_width()),r.randint(0,window.get_height()))
coloro = r.choice(newlist)
raa = r.randint(0,100)/1000
raa = r.choice(self.choice) * raa
self.squares.append(Square(coo,r.randint(10,self.maxsize-50),coloro,raa,True))
def special_draw(self,mouse,window):
window.fill(c.colorlist[0])
for a in self.squares:
a.attract(mouse,window)
a.draw(window)
def draw(self,window):
window.fill(c.colorlist[0])
for a in self.squares:
a.move(window)
a.draw(window)
class Square:
def __init__(self,coords,l,color,ra,flag = False):
self.l = l
self.color = color
self.coords = coords
self.x = self.coords[0]
self.y = self.coords[1]
self.angle = 100
self.surface = pygame.Surface((self.l,self.l),pygame.SRCALPHA)
self.surface.set_alpha(10)
self.RotationalSpeed = ra
self.attractflag = flag
speed = 10
self.speed = speed
self.directionVector = (r.randint(-speed,speed)/r.randint(10,100),r.randint(speed,speed)/r.randint(10,100))
def attract(self,target,screen = None):
self.coords = (self.x,self.y)
if self.x >= target[0]:
self.x -= r.randint(1,self.speed)/r.randint(10,500)
elif self.x <= target[0]:
self.x+= r.randint(1,self.speed )/r.randint(10,500)
if self.y <= target[1]:
self.y += r.randint(1,self.speed)/r.randint(10,500)
elif self.y >= target[1]:
self.y -= r.randint(1,self.speed)/r.randint(10,500)
if -20 <= self.x - target[0] <= 30 and -20 <= self.y - target[1] <= 30:
self.x = r.randint(0,screen.get_width())
self.y = r.randint(0,screen.get_height())
def move(self,screen):
self.x += self.directionVector[0]
self.y += self.directionVector[1]
self.coords = (self.x,self.y)
if self.x >= screen.get_width():
self.directionVector = (self.directionVector[0]*-1,self.directionVector[1])
if self.x <= 0:
self.directionVector = (self.directionVector[0]*-1,self.directionVector[1])
if self.y <= 0 :
self.directionVector = (self.directionVector[0],self.directionVector[1]*-1)
if self.y >= screen.get_height():
self.directionVector = (self.directionVector[0],self.directionVector[1]*-1)
def draw(self, screen):
square_surface = pygame.Surface((self.l, self.l), pygame.SRCALPHA)
square_surface.fill(self.color)
rotated_surface = pygame.transform.rotate(square_surface, self.angle)
rect = rotated_surface.get_rect(center=self.coords)
screen.blit(rotated_surface, rect.topleft)
self.angle += self.RotationalSpeed
def updateCoord(self,coords):
self.coords = coords
def rotate(self,):
pass
class Trailsquare:
def __init__(self,size,):
self.size = size
self.trail = {}
self.maxsize = 20
self.createTrail()
def update(self,mouse):
keeys = list(self.trail.keys())
previous = mouse
for a in keeys:
curr = self.trail[a]
self.trail[a] = previous
previous = curr
def resetTrail(self):
d = {}
self.trail = d
self.createTrail()
def createTrail(self):
choice = [-1.1]
newlist = c.colorlist[3:11]
for a in range(self.size):
coo = (0,0)
coloro = r.choice(newlist)
raa = r.randint(0,100)/1000
raa = r.choice(choice) * raa
self.trail[Square(coo,r.randint(0,self.maxsize),coloro,raa)] = (0,0)
def draw(self, screen):
for a in self.trail:
a.updateCoord(self.trail[a])
a.draw(screen)