-
Notifications
You must be signed in to change notification settings - Fork 1
/
legocolor.py
182 lines (169 loc) · 8.61 KB
/
legocolor.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
#'''http://www.ldraw.org/library/official/ldconfig.ldr'''
legocolor={
#CODE:(NAME, VALUE , EDGE , ALPHA),
0:("Black", [0x05, 0x13, 0x1D], [0x59, 0x59, 0x59]),
1:("Blue", [0x00, 0x55, 0xBF], [0x33, 0x33, 0x33]),
2:("Green", [0x25, 0x7A, 0x3E], [0x33, 0x33, 0x33]),
3:("Dark_Turquoise", [0x00, 0x83, 0x8F], [0x33, 0x33, 0x33]),
4:("Red", [0xC9, 0x1A, 0x09], [0x33, 0x33, 0x33]),
5:("Dark_Pink", [0xC8, 0x70, 0xA0], [0x33, 0x33, 0x33]),
6:("Brown", [0x58, 0x39, 0x27], [0x1E, 0x1E, 0x1E]),
7:("Light_Grey", [0x9B, 0xA1, 0x9D], [0x33, 0x33, 0x33]),
8:("Dark_Grey", [0x6D, 0x6E, 0x5C], [0x33, 0x33, 0x33]),
9:("Light_Blue", [0xB4, 0xD2, 0xE3], [0x33, 0x33, 0x33]),
10:("Bright_Green", [0x4B, 0x9F, 0x4A], [0x33, 0x33, 0x33]),
11:("Light_Turquoise", [0x55, 0xA5, 0xAF], [0x33, 0x33, 0x33]),
12:("Salmon", [0xF2, 0x70, 0x5E], [0x33, 0x33, 0x33]),
13:("Pink", [0xFC, 0x97, 0xAC], [0x33, 0x33, 0x33]),
14:("Yellow", [0xF2, 0xCD, 0x37], [0x33, 0x33, 0x33]),
15:("White", [0xFF, 0xFF, 0xFF], [0x33, 0x33, 0x33]),
17:("Light_Green", [0xC2, 0xDA, 0xB8], [0x33, 0x33, 0x33]),
18:("Light_Yellow", [0xFB, 0xE6, 0x96], [0x33, 0x33, 0x33]),
19:("Tan", [0xE4, 0xCD, 0x9E], [0x33, 0x33, 0x33]),
20:("Light_Violet", [0xC9, 0xCA, 0xE2], [0x33, 0x33, 0x33]),
22:("Purple", [0x81, 0x00, 0x7B], [0x33, 0x33, 0x33]),
23:("Dark_Blue_Violet", [0x20, 0x32, 0xB0], [0x1E, 0x1E, 0x1E]),
25:("Orange", [0xFE, 0x8A, 0x18], [0x33, 0x33, 0x33]),
26:("Magenta", [0x92, 0x39, 0x78], [0x33, 0x33, 0x33]),
27:("Lime", [0xBB, 0xE9, 0x0B], [0x33, 0x33, 0x33]),
28:("Dark_Tan", [0x95, 0x8A, 0x73], [0x33, 0x33, 0x33]),
29:("Bright_Pink", [0xE4, 0xAD, 0xC8], [0x33, 0x33, 0x33]),
30:("Medium_Lavender", [0xAC, 0x78, 0xBA], [0x33, 0x33, 0x33]),
31:("Lavender", [0xE1, 0xD5, 0xED], [0x33, 0x33, 0x33]),
68:("Very_Light_Orange", [0xF3, 0xCF, 0x9B], [0x33, 0x33, 0x33]),
69:("Light_Purple", [0xCD, 0x62, 0x98], [0x33, 0x33, 0x33]),
70:("Reddish_Brown", [0x58, 0x2A, 0x12], [0x59, 0x59, 0x59]),
71:("Light_Bluish_Grey", [0xA0, 0xA5, 0xA9], [0x33, 0x33, 0x33]),
72:("Dark_Bluish_Grey", [0x6C, 0x6E, 0x68], [0x33, 0x33, 0x33]),
73:("Medium_Blue", [0x5C, 0x9D, 0xD1], [0x33, 0x33, 0x33]),
74:("Medium_Green", [0x73, 0xDC, 0xA1], [0x33, 0x33, 0x33]),
77:("Light_Pink", [0xFE, 0xCC, 0xCF], [0x33, 0x33, 0x33]),
78:("Light_Flesh", [0xF6, 0xD7, 0xB3], [0x33, 0x33, 0x33]),
84:("Medium_Dark_Flesh", [0xCC, 0x70, 0x2A], [0x33, 0x33, 0x33]),
85:("Dark_Purple", [0x3F, 0x36, 0x91], [0x1E, 0x1E, 0x1E]),
86:("Dark_Flesh", [0x7C, 0x50, 0x3A], [0x33, 0x33, 0x33]),
89:("Blue_Violet", [0x4C, 0x61, 0xDB], [0x33, 0x33, 0x33]),
92:("Flesh", [0xD0, 0x91, 0x68], [0x33, 0x33, 0x33]),
100:("Light_Salmon", [0xFE, 0xBA, 0xBD], [0x33, 0x33, 0x33]),
110:("Violet", [0x43, 0x54, 0xA3], [0x33, 0x33, 0x33]),
112:("Medium_Violet", [0x68, 0x74, 0xCA], [0x33, 0x33, 0x33]),
115:("Medium_Lime", [0xC7, 0xD2, 0x3C], [0x33, 0x33, 0x33]),
118:("Aqua", [0xB3, 0xD7, 0xD1], [0x33, 0x33, 0x33]),
120:("Light_Lime", [0xD9, 0xE4, 0xA7], [0x33, 0x33, 0x33]),
125:("Light_Orange", [0xF9, 0xBA, 0x61], [0x33, 0x33, 0x33]),
151:("Very_Light_Bluish_Grey", [0xE6, 0xE3, 0xE0], [0x33, 0x33, 0x33]),
191:("Bright_Light_Orange", [0xF8, 0xBB, 0x3D], [0x33, 0x33, 0x33]),
212:("Bright_Light_Blue", [0x86, 0xC1, 0xE1], [0x33, 0x33, 0x33]),
216:("Rust", [0xB3, 0x10, 0x04], [0x33, 0x33, 0x33]),
226:("Bright_Light_Yellow", [0xFF, 0xF0, 0x3A], [0x33, 0x33, 0x33]),
232:("Sky_Blue", [0x56, 0xBE, 0xD6], [0x33, 0x33, 0x33]),
272:("Dark_Blue", [0x0D, 0x32, 0x5B], [0x1E, 0x1E, 0x1E]),
288:("Dark_Green", [0x18, 0x46, 0x32], [0x59, 0x59, 0x59]),
308:("Dark_Brown", [0x35, 0x21, 0x00], [0x59, 0x59, 0x59]),
313:("Maersk_Blue", [0x54, 0xA9, 0xC8], [0x33, 0x33, 0x33]),
320:("Dark_Red", [0x72, 0x0E, 0x0F], [0x33, 0x33, 0x33]),
321:("Dark_Azure", [0x14, 0x98, 0xD7], [0x33, 0x33, 0x33]),
322:("Medium_Azure", [0x3E, 0xC2, 0xDD], [0x33, 0x33, 0x33]),
323:("Light_Aqua", [0xBD, 0xDC, 0xD8], [0x33, 0x33, 0x33]),
326:("Yellowish_Green", [0xDF, 0xEE, 0xA5], [0x33, 0x33, 0x33]),
330:("Olive_Green", [0x9B, 0x9A, 0x5A], [0x33, 0x33, 0x33]),
335:("Sand_Red", [0xD6, 0x75, 0x72], [0x33, 0x33, 0x33]),
351:("Medium_Dark_Pink", [0xF7, 0x85, 0xB1], [0x33, 0x33, 0x33]),
366:("Earth_Orange", [0xFA, 0x9C, 0x1C], [0x33, 0x33, 0x33]),
373:("Sand_Purple", [0x84, 0x5E, 0x84], [0x33, 0x33, 0x33]),
378:("Sand_Green", [0xA0, 0xBC, 0xAC], [0x33, 0x33, 0x33]),
379:("Sand_Blue", [0x59, 0x71, 0x84], [0x33, 0x33, 0x33]),
450:("Fabuland_Brown", [0xB6, 0x7B, 0x50], [0x33, 0x33, 0x33]),
462:("Medium_Orange", [0xFF, 0xA7, 0x0B], [0x33, 0x33, 0x33]),
484:("Dark_Orange", [0xA9, 0x55, 0x00], [0x33, 0x33, 0x33]),
503:("Very_Light_Grey", [0xE6, 0xE3, 0xDA], [0x33, 0x33, 0x33]),
47:("Trans_Clear", [0xFC, 0xFC, 0xFC], [0xC3, 0xC3, 0xC3], 128),
40:("Trans_Black", [0x63, 0x5F, 0x52], [0x17, 0x13, 0x16], 128),
36:("Trans_Red", [0xC9, 0x1A, 0x09], [0x88, 0x00, 0x00], 128),
38:("Trans_Neon_Orange", [0xFF, 0x80, 0x0D], [0xBD, 0x24, 0x00], 128),
57:("Trans_Orange", [0xF0, 0x8F, 0x1C], [0xA4, 0x5C, 0x28], 128),
54:("Trans_Neon_Yellow", [0xDA, 0xB0, 0x00], [0xC3, 0xBA, 0x3F], 128),
46:("Trans_Yellow", [0xF5, 0xCD, 0x2F], [0x8E, 0x74, 0x00], 128),
42:("Trans_Neon_Green", [0xC0, 0xFF, 0x00], [0x84, 0xC3, 0x00], 128),
35:("Trans_Bright_Green", [0x56, 0xE6, 0x46], [0x9D, 0xA8, 0x6B], 128),
34:("Trans_Green", [0x23, 0x78, 0x41], [0x1E, 0x62, 0x39], 128),
33:("Trans_Dark_Blue", [0x00, 0x20, 0xA0], [0x00, 0x00, 0x64], 128),
41:("Trans_Medium_Blue", [0x55, 0x9A, 0xB7], [0x19, 0x69, 0x73], 128),
43:("Trans_Light_Blue", [0xAE, 0xE9, 0xEF], [0x72, 0xB3, 0xB0], 128),
39:("Trans_Very_Light_Blue", [0xC1, 0xDF, 0xF0], [0x85, 0xA3, 0xB4], 128),
44:("Trans_Light_Purple", [0x96, 0x70, 0x9F], [0x5A, 0x34, 0x63], 128),
52:("Trans_Purple", [0xA5, 0xA5, 0xCB], [0x28, 0x00, 0x25], 128),
37:("Trans_Dark_Pink", [0xDF, 0x66, 0x95], [0xA3, 0x2A, 0x59], 128),
45:("Trans_Pink", [0xFC, 0x97, 0xAC], [0xA8, 0x71, 0x8C], 128),
79:("Milky_White", [0xFF, 0xFF, 0xFF], [0xC3, 0xC3, 0xC3], 224),
21:("Glow_In_Dark_Opaque", [0xE0, 0xFF, 0xB0], [0xA4, 0xC3, 0x74], 250),
294:("Glow_In_Dark_Trans", [0xBD, 0xC6, 0xAD], [0x81, 0x8A, 0x71], 250),
114:("Glitter_Trans_Dark_Pink", [0xDF, 0x66, 0x95], [0x9A, 0x2A, 0x66], 128),
117:("Glitter_Trans_Clear", [0xFF, 0xFF, 0xFF], [0xC3, 0xC3, 0xC3], 128),
129:("Glitter_Trans_Purple", [0x64, 0x00, 0x61], [0x28, 0x00, 0x25], 128),
66:("Rubber_Trans_Yellow", [0xCA, 0xB0, 0x00], [0x8E, 0x74, 0x00], 128),
67:("Rubber_Trans_Clear", [0xFF, 0xFF, 0xFF], [0xC3, 0xC3, 0xC3], 128),
16:("Main_Colour", [0x7F, 0x7F, 0x7F], [0x33, 0x33, 0x33]),
24:("Edge_Colour", [0x7F, 0x7F, 0x7F], [0x33, 0x33, 0x33]),
32:("Trans_Black_IR_Lens", [0x00, 0x00, 0x00], [0x33, 0x33, 0x33], 200),
}
def legocolor2rgba(color):
#CODE:(NAME, VALUE , EDGE , ALPHA),
#print('color', color)
if color.upper().startswith('0X2'):
## print ('color[3:5]', color[3:5])
## print ('color[5:7]', color[5:7])
## print ('color[7:9]', color[7:9])
r=int( color[3:5], 16)/255.0
g=int( color[5:7], 16)/255.0
b=int( color[7:9], 16)/255.0
a=1.0
else:
try:
colorIdx=int(color)
colorRGB=legocolor[colorIdx][1]
r,g,b=[i/255.0 for i in colorRGB]
except:
r,g,b=0.5, 0.5, 0.5
if len(legocolor[colorIdx])==4:
a=legocolor[colorIdx][3]/255.0
else:
a=1
return r, g, b, a
def legocolor2name(color):
if color.upper().startswith('0X2'):
return 'LEGO_RGB_%s' % (color.upper()[3:])
else:
try:
colorIdx=int(color)
colorName=legocolor[colorIdx][0]
r, g, b=legocolor[colorIdx][1]
if len(legocolor[colorIdx])==4:
a=legocolor[colorIdx][3]
return 'LEGO_%s_RGBA_%s' %(colorName, ''.join(['%02X' % r, '%02X' % g, '%02X' % b, '%02X' % a]))
else:
return 'LEGO_%s_RGB_%s' %(colorName, ''.join(['%02X' % r, '%02X' % g, '%02X' % b]))
except:
return 'LEGO_COLOR_%03X' % colorIdx
# ==================================
# ==== Color ====
# ==================================
def realcolor(color):
'''
convert the color in LDRAW DAT file to blender
'''
## print('color=', color, 'type(color)=', type(color))
#~ if color.upper().startswith(b'0X2'):
#~ R, G, B=int(color[3:5]), int(color[5:7]), int(color[7:])
#~ return int(color[3:], 16)
if color==24: #a complement colour
return 24
pass
elif color==16: #current colour
return 16
pass
else:
return color
if __name__=='__main__':
color='1'
print(legocolor2name(color))