-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAbstract.py
222 lines (182 loc) · 5.1 KB
/
Abstract.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import random
import time
import pygame
from pygame.locals import *
from Colors import *
from Coordinate import *
colors = Colors()
coordinate = Coordinate()
class Abstract:
"""Abstract Logo class for creating object shape on the screen"""
def __init__(self):
self.x = 0
self.y = 0
self.oldx = 0
self.oldy = 0
self.speed = []
self.length = []
self.deg = []
self.startpos = 0
self.rainbow = 0
"""Rangom object shape generator
Arguments:
speed {integer} -- drawing speed, by default 100
length {integer} -- size of the shape, by default 10
ranges {integer} -- ranges, by default 3
Keyword Arguments: None
Raises: None
Returns: None
"""
def random(self, speed=100, length=10, ranges=3):
random.seed(round(time.time() * 200))
self.speed = [round((round(random.random()) * 2 - 1) * (random.random() * (speed - 1) + 1)) for x in range(ranges)]
self.length = [round((round(random.random()) * 2 - 1) * (random.random() * (length - 1) + 1)) for x in range(ranges)]
self.deg = [0 for x in range(ranges)]
"""New position
Arguments: None
Keyword Arguments: None
Raises: None
Returns: None
"""
def new(self):
self.deg = [0 for x in range(len(self.deg))]
self.getPosition()
self.oldx = self.x
self.oldy = self.y
self.startpos = (self.x, self.y)
"""Load postion
Argumets:
speed {integer} -- drawing speed
length {integer} -- size of the shape
Keyword Arguments: None
Raises: None
Return: None
"""
def load(self, speed = 100, length = 10):
self.speed = speed
self.length = length
self.deg = [0 for x in range(len(length))]
"""Save current position
Argumets: None
Keyword Arguments: None
Reises: None
Returns:
{integer} -- returns current speed and length
"""
def save(self):
return (self.speed, self.length)
"""Private function for keeping default values of X and Y __drawTheShape and __moveTheRainbow
Arguments:
rainbow {Integer}
Keyword Arguments: None
Reises: None
Returns:
{intger} -- return current value of rainbow
"""
def __defaultValueOfXY(self, rainbow = 0):
self.new()
self.x = 0
self.y = 0
return rainbow
"""Private function old sets of X and Y coordinats __drawTheShape and __moveTheRainbow
Arguments: None
Keyword Arguments: None
Reises: None
Returns: None
"""
def __oldSetsOfXY(self):
self.oldx = self.x
self.oldy = self.y
self.getPosition()
"""Private function to draw shape for __drawTheShape and __moveTheRainbow
Arguments
rainbow {Integer} -- for moving color on the shape
coordinats {Integer} -- coordinats for color
screen {Tuple} -- screen size
Keyword Arguments: None
Reises: None
Returns:
{Integer} -- for activating color moving
"""
def __rainbowDrawing(self, rainbow = 0, coordinats = 0, screen = 0):
if rainbow:
pygame.draw.line(screen, colors.color(coordinats), (self.oldx, self.oldy), (self.x, self.y), 5)
rainbow = 1
return rainbow
"""Private function for drawing shape for draw()
Arguments:
screen {Tuple} -- screen size
Keyword Arguments: None
Reises: None
Returns: None
"""
def __drawTheShape(self, screen = 0):
rainbow = self.__defaultValueOfXY()
while not self.startpos == (self.x , self.y):
self.__oldSetsOfXY()
value = (self.x + self.y) / 2
rainbow = self.__rainbowDrawing(rainbow=rainbow, coordinats=value, screen=screen)
"""Privaet function for move rainbow for draw()
Arguments:
screen {Tuple} -- screen size
Keyword Arguments: None
Reises: None
Returns: None
"""
def __moveTheRainbow(self, screen = 0):
rainbow = self.__defaultValueOfXY()
while not self.startpos == (self.x, self.y):
self.rainbow += 0.005
self.__oldSetsOfXY()
value = ((self.x + self.y) / 2) + self.rainbow
rainbow = self.__rainbowDrawing(rainbow=rainbow, coordinats=value, screen=screen)
"""Draw new image
Arguments:
pygame {Class} -- pygame class for working pygame screen
screen {Tuple} -- screen size
play {Boolean} -- for running game none stop
Keyword Arguments: None
Reises: None
Returns: None
"""
def draw(self, pygame, screen = 0, play=False):
if not play:
self.__drawTheShape(screen=screen)
else:
self.__moveTheRainbow(screen=screen)
"""Private function to calculate coordinats for getPosition()
Arguments: None
Keyword Arguments: None
Reises: None
Returns: None
"""
def __calculateCordinatsXY(self):
v, h = pygame.display.get_surface().get_size()
self.x *= 10
self.y *= 10
self.x += v / 2
self.y += h / 2
"""Private function to calculate range of coordinats for getPosition()
Arguments: None
Keyword Arguments: None
Reises: None
Returns: None
"""
def __calculateRangeOfXY(self):
for x in range(len(self.length)):
self.deg[x] += self.speed[x]
if 360 < abs(self.deg[x]):
self.deg[x] += (-360 * (2 * (0 < self.deg[x]) - 1))
self.x += coordinate.sin(self.deg[x]) * self.length[x]
self.y += coordinate.cos(self.deg[x]) * self.length[x]
"""Get current postion
Arguments: None
Keyword Arguments: None
Reises: None
Returns: None
"""
def getPosition(self):
self.x = 0
self.y = 0
self.__calculateRangeOfXY()
self.__calculateCordinatsXY()