-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolormaps.py
More file actions
37 lines (25 loc) · 1001 Bytes
/
colormaps.py
File metadata and controls
37 lines (25 loc) · 1001 Bytes
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
import json
from color import *
from colormap import *
class ColorMaps:
def __init__(self):
self.maps = {}
# Read all the color maps from the json file.
json_file = open('colormaps.json')
colormapsJSON = json.load(json_file)
# Parse the json into a map of color map objects
for colormapJSON in colormapsJSON:
new_colormap = ColorMap()
# Add all the colors to the current color map.
for point in colormapJSON['points']:
new_colormap.add_color(point['position'],Color(point['color']['r'],point['color']['g'],point['color']['b']))
self.maps[colormapJSON['name']] = new_colormap
def get_color_map(self, name: str):
# Try and get the color map from the map
c = self.maps[name]
# If the map doesn't exist, return an empty color map.
if c == None:
return ColorMap()
return c
def load():
return ColorMaps()