Skip to content

Instantly share code, notes, and snippets.

@stqism
Created September 2, 2013 13:02
Show Gist options
  • Save stqism/6412620 to your computer and use it in GitHub Desktop.
Save stqism/6412620 to your computer and use it in GitHub Desktop.
l = 0
cdefine = ''
cint = ''
with open("color.def.src") as f:
for line in f:
n = 2
hex = [line[i:i+n] for i in range(0, len(line), n)]
val1 = str(int(hex[0],16) * 3.90625).split('.', 1)[0]
val2 = str(int(hex[1],16) * 3.90625).split('.', 1)[0]
val3 = str(int(hex[2],16) * 3.90625).split('.', 1)[0]
cdefine += '#define COLOR_' + line.rstrip('\n').upper() + ' %d' % (l) + '\n'
cint += 'init_color(' + line.rstrip('\n').upper() + ', ' + val1 + ', ' + val2 + ', ' + val3 + ');' + '\n'
l += 1
print cdefine + cint
#define COLOR_000000 0
#define COLOR_800000 1
#define COLOR_008000 2
#define COLOR_808000 3
#define COLOR_000080 4
#define COLOR_800080 5
#define COLOR_008080 6
#define COLOR_C0C0C0 7
#define COLOR_808080 8
#define COLOR_FF0000 9
#define COLOR_00FF00 10
#define COLOR_FFFF00 11
#define COLOR_0000FF 12
#define COLOR_FF00FF 13
#define COLOR_00FFFF 14
#define COLOR_FFFFFF 15
#define COLOR_000000 16
#define COLOR_00005F 17
#define COLOR_000087 18
#define COLOR_0000AF 19
#define COLOR_0000D7 20
#define COLOR_0000FF 21
#define COLOR_005F00 22
#define COLOR_005F5F 23
#define COLOR_005F87 24
#define COLOR_005FAF 25
#define COLOR_005FD7 26
#define COLOR_005FFF 27
#define COLOR_008700 28
#define COLOR_00875F 29
#define COLOR_008787 30
#define COLOR_0087AF 31
#define COLOR_0087D7 32
#define COLOR_0087FF 33
#define COLOR_00AF00 34
#define COLOR_00AF5F 35
#define COLOR_00AF87 36
#define COLOR_00AFAF 37
#define COLOR_00AFD7 38
#define COLOR_00AFFF 39
#define COLOR_00D700 40
#define COLOR_00D75F 41
#define COLOR_00D787 42
#define COLOR_00D7AF 43
#define COLOR_00D7D7 44
#define COLOR_00D7FF 45
#define COLOR_00FF00 46
#define COLOR_00FF5F 47
#define COLOR_00FF87 48
#define COLOR_00FFAF 49
#define COLOR_00FFD7 50
#define COLOR_00FFFF 51
#define COLOR_5F0000 52
#define COLOR_5F005F 53
#define COLOR_5F0087 54
#define COLOR_5F00AF 55
#define COLOR_5F00D7 56
#define COLOR_5F00FF 57
#define COLOR_5F5F00 58
#define COLOR_5F5F5F 59
#define COLOR_5F5F87 60
#define COLOR_5F5FAF 61
#define COLOR_5F5FD7 62
#define COLOR_5F5FFF 63
#define COLOR_5F8700 64
#define COLOR_5F875F 65
#define COLOR_5F8787 66
#define COLOR_5F87AF 67
#define COLOR_5F87D7 68
#define COLOR_5F87FF 69
#define COLOR_5FAF00 70
#define COLOR_5FAF5F 71
#define COLOR_5FAF87 72
#define COLOR_5FAFAF 73
#define COLOR_5FAFD7 74
#define COLOR_5FAFFF 75
#define COLOR_5FD700 76
#define COLOR_5FD75F 77
#define COLOR_5FD787 78
#define COLOR_5FD7AF 79
#define COLOR_5FD7D7 80
#define COLOR_5FD7FF 81
#define COLOR_5FFF00 82
#define COLOR_5FFF5F 83
#define COLOR_5FFF87 84
#define COLOR_5FFFAF 85
#define COLOR_5FFFD7 86
#define COLOR_5FFFFF 87
#define COLOR_870000 88
#define COLOR_87005F 89
#define COLOR_870087 90
#define COLOR_8700AF 91
#define COLOR_8700D7 92
#define COLOR_8700FF 93
#define COLOR_875F00 94
#define COLOR_875F5F 95
#define COLOR_875F87 96
#define COLOR_875FAF 97
#define COLOR_875FD7 98
#define COLOR_875FFF 99
#define COLOR_878700 100
#define COLOR_87875F 101
#define COLOR_878787 102
#define COLOR_8787AF 103
#define COLOR_8787D7 104
#define COLOR_8787FF 105
#define COLOR_87AF00 106
#define COLOR_87AF5F 107
#define COLOR_87AF87 108
#define COLOR_87AFAF 109
#define COLOR_87AFD7 110
#define COLOR_87AFFF 111
#define COLOR_87D700 112
#define COLOR_87D75F 113
#define COLOR_87D787 114
#define COLOR_87D7AF 115
#define COLOR_87D7D7 116
#define COLOR_87D7FF 117
#define COLOR_87FF00 118
#define COLOR_87FF5F 119
#define COLOR_87FF87 120
#define COLOR_87FFAF 121
#define COLOR_87FFD7 122
#define COLOR_87FFFF 123
#define COLOR_AF0000 124
#define COLOR_AF005F 125
#define COLOR_AF0087 126
#define COLOR_AF00AF 127
#define COLOR_AF00D7 128
#define COLOR_AF00FF 129
#define COLOR_AF5F00 130
#define COLOR_AF5F5F 131
#define COLOR_AF5F87 132
#define COLOR_AF5FAF 133
#define COLOR_AF5FD7 134
#define COLOR_AF5FFF 135
#define COLOR_AF8700 136
#define COLOR_AF875F 137
#define COLOR_AF8787 138
#define COLOR_AF87AF 139
#define COLOR_AF87D7 140
#define COLOR_AF87FF 141
#define COLOR_AFAF00 142
#define COLOR_AFAF5F 143
#define COLOR_AFAF87 144
#define COLOR_AFAFAF 145
#define COLOR_AFAFD7 146
#define COLOR_AFAFFF 147
#define COLOR_AFD700 148
#define COLOR_AFD75F 149
#define COLOR_AFD787 150
#define COLOR_AFD7AF 151
#define COLOR_AFD7D7 152
#define COLOR_AFD7FF 153
#define COLOR_AFFF00 154
#define COLOR_AFFF5F 155
#define COLOR_AFFF87 156
#define COLOR_AFFFAF 157
#define COLOR_AFFFD7 158
#define COLOR_AFFFFF 159
#define COLOR_D70000 160
#define COLOR_D7005F 161
#define COLOR_D70087 162
#define COLOR_D700AF 163
#define COLOR_D700D7 164
#define COLOR_D700FF 165
#define COLOR_D75F00 166
#define COLOR_D75F5F 167
#define COLOR_D75F87 168
#define COLOR_D75FAF 169
#define COLOR_D75FD7 170
#define COLOR_D75FFF 171
#define COLOR_D78700 172
#define COLOR_D7875F 173
#define COLOR_D78787 174
#define COLOR_D787AF 175
#define COLOR_D787D7 176
#define COLOR_D787FF 177
#define COLOR_D7AF00 178
#define COLOR_D7AF5F 179
#define COLOR_D7AF87 180
#define COLOR_D7AFAF 181
#define COLOR_D7AFD7 182
#define COLOR_D7AFFF 183
#define COLOR_D7D700 184
#define COLOR_D7D75F 185
#define COLOR_D7D787 186
#define COLOR_D7D7AF 187
#define COLOR_D7D7D7 188
#define COLOR_D7D7FF 189
#define COLOR_D7FF00 190
#define COLOR_D7FF5F 191
#define COLOR_D7FF87 192
#define COLOR_D7FFAF 193
#define COLOR_D7FFD7 194
#define COLOR_D7FFFF 195
#define COLOR_FF0000 196
#define COLOR_FF005F 197
#define COLOR_FF0087 198
#define COLOR_FF00AF 199
#define COLOR_FF00D7 200
#define COLOR_FF00FF 201
#define COLOR_FF5F00 202
#define COLOR_FF5F5F 203
#define COLOR_FF5F87 204
#define COLOR_FF5FAF 205
#define COLOR_FF5FD7 206
#define COLOR_FF5FFF 207
#define COLOR_FF8700 208
#define COLOR_FF875F 209
#define COLOR_FF8787 210
#define COLOR_FF87AF 211
#define COLOR_FF87D7 212
#define COLOR_FF87FF 213
#define COLOR_FFAF00 214
#define COLOR_FFAF5F 215
#define COLOR_FFAF87 216
#define COLOR_FFAFAF 217
#define COLOR_FFAFD7 218
#define COLOR_FFAFFF 219
#define COLOR_FFD700 220
#define COLOR_FFD75F 221
#define COLOR_FFD787 222
#define COLOR_FFD7AF 223
#define COLOR_FFD7D7 224
#define COLOR_FFD7FF 225
#define COLOR_FFFF00 226
#define COLOR_FFFF5F 227
#define COLOR_FFFF87 228
#define COLOR_FFFFAF 229
#define COLOR_FFFFD7 230
#define COLOR_FFFFFF 231
#define COLOR_080808 232
#define COLOR_121212 233
#define COLOR_1C1C1C 234
#define COLOR_262626 235
#define COLOR_303030 236
#define COLOR_3A3A3A 237
#define COLOR_444444 238
#define COLOR_4E4E4E 239
#define COLOR_585858 240
#define COLOR_626262 241
#define COLOR_6C6C6C 242
#define COLOR_767676 243
#define COLOR_808080 244
#define COLOR_8A8A8A 245
#define COLOR_949494 246
#define COLOR_9E9E9E 247
#define COLOR_A8A8A8 248
#define COLOR_B2B2B2 249
#define COLOR_BCBCBC 250
#define COLOR_C6C6C6 251
#define COLOR_D0D0D0 252
#define COLOR_DADADA 253
#define COLOR_E4E4E4 254
#define COLOR_EEEEEE 255
init_color(000000, 0, 0, 0);
init_color(800000, 500, 0, 0);
init_color(008000, 0, 500, 0);
init_color(808000, 500, 500, 0);
init_color(000080, 0, 0, 500);
init_color(800080, 500, 0, 500);
init_color(008080, 0, 500, 500);
init_color(C0C0C0, 750, 750, 750);
init_color(808080, 500, 500, 500);
init_color(FF0000, 996, 0, 0);
init_color(00FF00, 0, 996, 0);
init_color(FFFF00, 996, 996, 0);
init_color(0000FF, 0, 0, 996);
init_color(FF00FF, 996, 0, 996);
init_color(00FFFF, 0, 996, 996);
init_color(FFFFFF, 996, 996, 996);
init_color(000000, 0, 0, 0);
init_color(00005F, 0, 0, 371);
init_color(000087, 0, 0, 527);
init_color(0000AF, 0, 0, 683);
init_color(0000D7, 0, 0, 839);
init_color(0000FF, 0, 0, 996);
init_color(005F00, 0, 371, 0);
init_color(005F5F, 0, 371, 371);
init_color(005F87, 0, 371, 527);
init_color(005FAF, 0, 371, 683);
init_color(005FD7, 0, 371, 839);
init_color(005FFF, 0, 371, 996);
init_color(008700, 0, 527, 0);
init_color(00875F, 0, 527, 371);
init_color(008787, 0, 527, 527);
init_color(0087AF, 0, 527, 683);
init_color(0087D7, 0, 527, 839);
init_color(0087FF, 0, 527, 996);
init_color(00AF00, 0, 683, 0);
init_color(00AF5F, 0, 683, 371);
init_color(00AF87, 0, 683, 527);
init_color(00AFAF, 0, 683, 683);
init_color(00AFD7, 0, 683, 839);
init_color(00AFFF, 0, 683, 996);
init_color(00D700, 0, 839, 0);
init_color(00D75F, 0, 839, 371);
init_color(00D787, 0, 839, 527);
init_color(00D7AF, 0, 839, 683);
init_color(00D7D7, 0, 839, 839);
init_color(00D7FF, 0, 839, 996);
init_color(00FF00, 0, 996, 0);
init_color(00FF5F, 0, 996, 371);
init_color(00FF87, 0, 996, 527);
init_color(00FFAF, 0, 996, 683);
init_color(00FFD7, 0, 996, 839);
init_color(00FFFF, 0, 996, 996);
init_color(5F0000, 371, 0, 0);
init_color(5F005F, 371, 0, 371);
init_color(5F0087, 371, 0, 527);
init_color(5F00AF, 371, 0, 683);
init_color(5F00D7, 371, 0, 839);
init_color(5F00FF, 371, 0, 996);
init_color(5F5F00, 371, 371, 0);
init_color(5F5F5F, 371, 371, 371);
init_color(5F5F87, 371, 371, 527);
init_color(5F5FAF, 371, 371, 683);
init_color(5F5FD7, 371, 371, 839);
init_color(5F5FFF, 371, 371, 996);
init_color(5F8700, 371, 527, 0);
init_color(5F875F, 371, 527, 371);
init_color(5F8787, 371, 527, 527);
init_color(5F87AF, 371, 527, 683);
init_color(5F87D7, 371, 527, 839);
init_color(5F87FF, 371, 527, 996);
init_color(5FAF00, 371, 683, 0);
init_color(5FAF5F, 371, 683, 371);
init_color(5FAF87, 371, 683, 527);
init_color(5FAFAF, 371, 683, 683);
init_color(5FAFD7, 371, 683, 839);
init_color(5FAFFF, 371, 683, 996);
init_color(5FD700, 371, 839, 0);
init_color(5FD75F, 371, 839, 371);
init_color(5FD787, 371, 839, 527);
init_color(5FD7AF, 371, 839, 683);
init_color(5FD7D7, 371, 839, 839);
init_color(5FD7FF, 371, 839, 996);
init_color(5FFF00, 371, 996, 0);
init_color(5FFF5F, 371, 996, 371);
init_color(5FFF87, 371, 996, 527);
init_color(5FFFAF, 371, 996, 683);
init_color(5FFFD7, 371, 996, 839);
init_color(5FFFFF, 371, 996, 996);
init_color(870000, 527, 0, 0);
init_color(87005F, 527, 0, 371);
init_color(870087, 527, 0, 527);
init_color(8700AF, 527, 0, 683);
init_color(8700D7, 527, 0, 839);
init_color(8700FF, 527, 0, 996);
init_color(875F00, 527, 371, 0);
init_color(875F5F, 527, 371, 371);
init_color(875F87, 527, 371, 527);
init_color(875FAF, 527, 371, 683);
init_color(875FD7, 527, 371, 839);
init_color(875FFF, 527, 371, 996);
init_color(878700, 527, 527, 0);
init_color(87875F, 527, 527, 371);
init_color(878787, 527, 527, 527);
init_color(8787AF, 527, 527, 683);
init_color(8787D7, 527, 527, 839);
init_color(8787FF, 527, 527, 996);
init_color(87AF00, 527, 683, 0);
init_color(87AF5F, 527, 683, 371);
init_color(87AF87, 527, 683, 527);
init_color(87AFAF, 527, 683, 683);
init_color(87AFD7, 527, 683, 839);
init_color(87AFFF, 527, 683, 996);
init_color(87D700, 527, 839, 0);
init_color(87D75F, 527, 839, 371);
init_color(87D787, 527, 839, 527);
init_color(87D7AF, 527, 839, 683);
init_color(87D7D7, 527, 839, 839);
init_color(87D7FF, 527, 839, 996);
init_color(87FF00, 527, 996, 0);
init_color(87FF5F, 527, 996, 371);
init_color(87FF87, 527, 996, 527);
init_color(87FFAF, 527, 996, 683);
init_color(87FFD7, 527, 996, 839);
init_color(87FFFF, 527, 996, 996);
init_color(AF0000, 683, 0, 0);
init_color(AF005F, 683, 0, 371);
init_color(AF0087, 683, 0, 527);
init_color(AF00AF, 683, 0, 683);
init_color(AF00D7, 683, 0, 839);
init_color(AF00FF, 683, 0, 996);
init_color(AF5F00, 683, 371, 0);
init_color(AF5F5F, 683, 371, 371);
init_color(AF5F87, 683, 371, 527);
init_color(AF5FAF, 683, 371, 683);
init_color(AF5FD7, 683, 371, 839);
init_color(AF5FFF, 683, 371, 996);
init_color(AF8700, 683, 527, 0);
init_color(AF875F, 683, 527, 371);
init_color(AF8787, 683, 527, 527);
init_color(AF87AF, 683, 527, 683);
init_color(AF87D7, 683, 527, 839);
init_color(AF87FF, 683, 527, 996);
init_color(AFAF00, 683, 683, 0);
init_color(AFAF5F, 683, 683, 371);
init_color(AFAF87, 683, 683, 527);
init_color(AFAFAF, 683, 683, 683);
init_color(AFAFD7, 683, 683, 839);
init_color(AFAFFF, 683, 683, 996);
init_color(AFD700, 683, 839, 0);
init_color(AFD75F, 683, 839, 371);
init_color(AFD787, 683, 839, 527);
init_color(AFD7AF, 683, 839, 683);
init_color(AFD7D7, 683, 839, 839);
init_color(AFD7FF, 683, 839, 996);
init_color(AFFF00, 683, 996, 0);
init_color(AFFF5F, 683, 996, 371);
init_color(AFFF87, 683, 996, 527);
init_color(AFFFAF, 683, 996, 683);
init_color(AFFFD7, 683, 996, 839);
init_color(AFFFFF, 683, 996, 996);
init_color(D70000, 839, 0, 0);
init_color(D7005F, 839, 0, 371);
init_color(D70087, 839, 0, 527);
init_color(D700AF, 839, 0, 683);
init_color(D700D7, 839, 0, 839);
init_color(D700FF, 839, 0, 996);
init_color(D75F00, 839, 371, 0);
init_color(D75F5F, 839, 371, 371);
init_color(D75F87, 839, 371, 527);
init_color(D75FAF, 839, 371, 683);
init_color(D75FD7, 839, 371, 839);
init_color(D75FFF, 839, 371, 996);
init_color(D78700, 839, 527, 0);
init_color(D7875F, 839, 527, 371);
init_color(D78787, 839, 527, 527);
init_color(D787AF, 839, 527, 683);
init_color(D787D7, 839, 527, 839);
init_color(D787FF, 839, 527, 996);
init_color(D7AF00, 839, 683, 0);
init_color(D7AF5F, 839, 683, 371);
init_color(D7AF87, 839, 683, 527);
init_color(D7AFAF, 839, 683, 683);
init_color(D7AFD7, 839, 683, 839);
init_color(D7AFFF, 839, 683, 996);
init_color(D7D700, 839, 839, 0);
init_color(D7D75F, 839, 839, 371);
init_color(D7D787, 839, 839, 527);
init_color(D7D7AF, 839, 839, 683);
init_color(D7D7D7, 839, 839, 839);
init_color(D7D7FF, 839, 839, 996);
init_color(D7FF00, 839, 996, 0);
init_color(D7FF5F, 839, 996, 371);
init_color(D7FF87, 839, 996, 527);
init_color(D7FFAF, 839, 996, 683);
init_color(D7FFD7, 839, 996, 839);
init_color(D7FFFF, 839, 996, 996);
init_color(FF0000, 996, 0, 0);
init_color(FF005F, 996, 0, 371);
init_color(FF0087, 996, 0, 527);
init_color(FF00AF, 996, 0, 683);
init_color(FF00D7, 996, 0, 839);
init_color(FF00FF, 996, 0, 996);
init_color(FF5F00, 996, 371, 0);
init_color(FF5F5F, 996, 371, 371);
init_color(FF5F87, 996, 371, 527);
init_color(FF5FAF, 996, 371, 683);
init_color(FF5FD7, 996, 371, 839);
init_color(FF5FFF, 996, 371, 996);
init_color(FF8700, 996, 527, 0);
init_color(FF875F, 996, 527, 371);
init_color(FF8787, 996, 527, 527);
init_color(FF87AF, 996, 527, 683);
init_color(FF87D7, 996, 527, 839);
init_color(FF87FF, 996, 527, 996);
init_color(FFAF00, 996, 683, 0);
init_color(FFAF5F, 996, 683, 371);
init_color(FFAF87, 996, 683, 527);
init_color(FFAFAF, 996, 683, 683);
init_color(FFAFD7, 996, 683, 839);
init_color(FFAFFF, 996, 683, 996);
init_color(FFD700, 996, 839, 0);
init_color(FFD75F, 996, 839, 371);
init_color(FFD787, 996, 839, 527);
init_color(FFD7AF, 996, 839, 683);
init_color(FFD7D7, 996, 839, 839);
init_color(FFD7FF, 996, 839, 996);
init_color(FFFF00, 996, 996, 0);
init_color(FFFF5F, 996, 996, 371);
init_color(FFFF87, 996, 996, 527);
init_color(FFFFAF, 996, 996, 683);
init_color(FFFFD7, 996, 996, 839);
init_color(FFFFFF, 996, 996, 996);
init_color(080808, 31, 31, 31);
init_color(121212, 70, 70, 70);
init_color(1C1C1C, 109, 109, 109);
init_color(262626, 148, 148, 148);
init_color(303030, 187, 187, 187);
init_color(3A3A3A, 226, 226, 226);
init_color(444444, 265, 265, 265);
init_color(4E4E4E, 304, 304, 304);
init_color(585858, 343, 343, 343);
init_color(626262, 382, 382, 382);
init_color(6C6C6C, 421, 421, 421);
init_color(767676, 460, 460, 460);
init_color(808080, 500, 500, 500);
init_color(8A8A8A, 539, 539, 539);
init_color(949494, 578, 578, 578);
init_color(9E9E9E, 617, 617, 617);
init_color(A8A8A8, 656, 656, 656);
init_color(B2B2B2, 695, 695, 695);
init_color(BCBCBC, 734, 734, 734);
init_color(C6C6C6, 773, 773, 773);
init_color(D0D0D0, 812, 812, 812);
init_color(DADADA, 851, 851, 851);
init_color(E4E4E4, 890, 890, 890);
init_color(EEEEEE, 929, 929, 929);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment