forked from openPSTD/openPSTD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.py
109 lines (82 loc) · 3.66 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
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
########################################################################
# #
# This file is part of openPSTD. #
# #
# openPSTD is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# openPSTD is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with openPSTD. If not, see <http://www.gnu.org/licenses/>. #
# #
########################################################################
__author__ = 'michiel'
import abc
import numpy as np
class Colors:
black = (0, 0, 0, 1)
white = (1, 1, 1, 1)
red = (1, 0, 0, 1)
green = (0, 1, 0, 1)
blue = (0, 0, 1, 1)
yellow = (1, 1, 0, 1)
lightBlue = (0, 1, 1, 1)
purple = (1, 0, 1, 1)
transparent = (0, 0, 0, 0)
class BaseColorGradient:
__metaclass__ = abc.ABCMeta
def CalculateColor(self, value):
return Colors.white
def create_color_map(self, start, stop, count):
colormap = np.ones((count, 4)).astype(np.float32)
for i, f in enumerate(np.linspace(start, stop, count)):
colormap[i] = self.CalculateColor(f)
return colormap
class MultiColorGradient(BaseColorGradient):
def __init__(self, colorPositions, colors):
self.colorPositions = colorPositions
self.colors = [[],[],[],[]]
for color in colors:
for i in range(0, 4):
self.colors[i].append(color[i])
def CalculateColor(self, value):
return self._ip(value, 0), self._ip(value, 1), self._ip(value, 2), self._ip(value, 3)
def _ip(self, value, index):
return np.interp(value, self.colorPositions, self.colors[index])
class TwoColorGradient(MultiColorGradient):
def __init__(self, colorZero, colorOne):
super(TwoColorGradient, self).__init__([0, 1], [colorZero, colorOne])
self.colorZero = colorZero
self.colorOne = colorOne
class BaseColorScheme:
__metaclass__ = abc.ABCMeta
def editorBackgroundColor(self):
return Colors.white
def editorLineColor(self):
return Colors.white
def editorLineAbsoptionColorGradient(self):
return BaseColorGradient
def editorDefualtDomainColor(self):
return Colors.white
def editorDomainSignalColorGradient(self):
return BaseColorGradient()
class StandardColorScheme(BaseColorScheme):
def editorBackgroundColor(self):
return Colors.white
def editorLineColor(self):
return Colors.black
def editorLineAbsoptionColorGradient(self):
return TwoColorGradient(Colors.blue, Colors.green)
def editorDefualtDomainColor(self):
return Colors.red
def editorDomainSignalColorGradient(self):
return MultiColorGradient([0, 0.10], [Colors.black, Colors.red])
def editorCreateDomainColor(self):
return Colors.red
activeColorScheme = StandardColorScheme()