-
Notifications
You must be signed in to change notification settings - Fork 21
/
colors.py
executable file
·63 lines (48 loc) · 1.59 KB
/
colors.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
class EmptyObject:
def __init__(self):
pass
greyscale = EmptyObject()
greyscale.BLACK = 0
greyscale.WHITE = 255
greyscale.MID_GREY = 127
WHITE = (255, 255, 255)
LIGHT_GREY = (191, 191, 191)
MID_GREY = (127, 128, 128)
DARK_GREY = (63, 63, 63)
BLACK = (0, 0, 0)
BLUE = (255, 0, 0)
CYAN = (255, 255, 0)
GREEN = (0, 255, 0)
LIME_GREEN = (0, 255, 102)
YELLOW = (0, 255, 255)
BURNT_YELLOW = (0, 223, 255)
ORANGE = (0, 127, 255)
RED = (0, 0, 255)
MAGENTA = (255,0,255)
PURPLE = (191, 0, 191)
class cycle:
def __init__(self, *colors):
self.colors = colors
self.index = 0 # this will continually loop through self.colors
def next(self):
color = self.colors[self.index]
self.index = (self.index+1) % len(self.colors)
return color
def __iter__(self, limit=None):
class Iterator():
def __init__(self, colors, limit):
self.colors = colors
self.index = 0 # this will continually loop through self.colors
self.limit = limit
self.iterCounter = 0 # this will continually count upwards (it won't loop around)
def __iter__(self):
return self
def next(self):
if self.limit != None and self.limit > self.iterCounter:
raise StopIteration
else:
color = self.colors[self.index]
self.index = (self.index+1) % len(self.colors)
self.iterCounter += 1
return color
return Iterator(self.colors, limit)