Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

190 lines (185 sloc) 6.17 kb
import re
color_chart = """
Black,0x00,0x00,0x00
White,0xff,0xff,0xff
Red,0xff,0x00,0x00
Green,0x00,0xff,0x00
Blue,0x00,0x00,0xff
Yellow,0xff,0xff,0x00
Grey,0x80,0x80,0x80
Snow,0xff,0xfa,0xfa
Snow 2,0xee,0xe9,0xe9
Snow 3,0xcd,0xc9,0xc9
Snow 4,0x8b,0x89,0x89
Ghost White,0xf8,0xf8,0xff
White Smoke,0xf5,0xf5,0xf5
Gainsboro,0xdc,0xcd,0xc
Floral White,0xff,0xfa,0xf0
Old Lace,0xfd,0xf5,0xe6
Linen,0xfa,0xf0,0xe6
Antique White,0xfa,0xeb,0xd7
Antique White 2,0xee,0xdf,0xcc
Antique White 3,0xcd,0xc0,0xb0
Antique White 4,0x8b,0x83,0x78
Papaya Whip,0xff,0xef,0xd5
Blanched Almond,0xff,0xeb,0xcd
Bisque,0xff,0xe4,0xc4
Bisque 2,0xee,0xd5,0xb7
Bisque 3,0xcd,0xb7,0x9e
Bisque 4,0x8b,0x7d,0x6b
Peach Puff,0xff,0xda,0xb9
Peach Puff 2,0xee,0xcb,0xad
Peach Puff 3,0xcd,0xaf,0x95
Peach Puff 4,0x8b,0x77,0x65
Navajo White,0xff,0xde,0xad
Moccasin,0xff,0xe4,0xb5
Cornsilk,0xff,0xf8,0xdc
Cornsilk 2,0xee,0xe8,0xdc
Cornsilk 3,0xcd,0xc8,0xb1
Cornsilk 4,0x8b,0x88,0x78
Ivory,0xff,0xff,0xf0
Ivory 2,0xee,0xee,0xe0
Ivory 3,0xcd,0xcd,0xc1
Ivory 4,0x8b,0x8b,0x83
Lemon Chiffon,0xff,0xfa,0xcd
Seashell,0xff,0xf5,0xee
Seashell 2,0xee,0xe5,0xde
Seashell 3,0xcd,0xc5,0xbf
Seashell 4,0x8b,0x86,0x82
Honeydew,0xf0,0xff,0xf0
Honeydew 2,0xe0,0xee,0xe0
Honeydew 3,0xc1,0xcd,0xc1
Honeydew 4,0x83,0x8b,0x83
Mint Cream,0xf5,0xff,0xfa
Azure,0xf0,0xff,0xff
Alice Blue,0xf0,0xf8,0xff
Lavender,0xe6,0xe6,0xfa
Lavender Blush,0xff,0xf0,0xf5
Misty Rose,0xff,0xe4,0xe1
Dark Slate Gray,0x2f,0x4f,0x4f
Dim Gray,0x69,0x69,0x69
Slate Gray,0x70,0x80,0x90
Light Slate Gray,0x77,0x88,0x99
Gray,0xbe,0xbe,0xbe
Light Gray,0xd3,0xd3,0xd3
Midnight Blue,0x19,0x19,0x70
Navy,0x80,0x00,0x00
Cornflower Blue,0x64,0x95,0xed
Dark Slate Blue,0x48,0x3d,0x8b
Slate Blue,0x6a,0x5a,0xcd
Medium Slate Blue,0x7b,0x68,0xee
Light Slate Blue,0x84,0x70,0xff
Medium Blue,0x00,0x00,0xcd
Royal Blue,0x41,0x69,0x0
Dodger Blue,0x1e,0x90,0xff
Deep Sky Blue,0x00,0xbf,0xff
Sky Blue,0x87,0xce,0xeb
Light Sky Blue,0x87,0xce,0xfa
Steel Blue,0x46,0x82,0xb4
Light Steel Blue,0xb0,0xc4,0xde
Light Blue,0xad,0xd8,0xe6
Powder Blue,0xb0,0xe0,0xe6
Pale Turquoise,0xaf,0xee,0xee
Dark Turquoise,0x00,0xce,0xd1
Medium Turquoise,0x48,0xd1,0xcc
Turquoise,0x40,0xe0,0xd0
Cyan,0x00,0xff,0xff
Light Cyan,0xe0,0xff,0xff
Cadet Blue,0x5f,0x9e,0xa0
Medium Aquamarine,0x66,0xcd,0xaa
Aquamarine,0x7f,0xff,0xd4
Dark Green,0x64,0x00,0x00
Dark Olive Green,0x55,0x6b,0x2f
Dark Sea Green,0x8f,0xbc,0x8f
Sea Green,0x2e,0x8b,0x57
Medium Sea Green,0x3c,0xb3,0x71
Light Sea Green,0x20,0xb2,0xaa
Pale Green,0x98,0xfb,0x98
Spring Green,0x00,0xff,0x7f
Lawn Green,0x7c,0xfc,0x00
Chartreuse,0x7f,0xff,0x00
Medium Spring Green,0x00,0xfa,0x9a
Green Yellow,0xad,0xff,0x2f
Lime Green,0x32,0xcd,0x32
Yellow Green,0x9a,0xcd,0x32
Forest Green,0x22,0x8b,0x22
Olive Drab,0x6b,0x8e,0x23
Dark Khaki,0xbd,0xb7,0x6b
Khaki,0xf0,0xe6,0x8c
Pale Goldenrod,0xee,0xe8,0xaa
Light Goldenrod Yellow,0xfa,0xfa,0xd2
Light Yellow,0xff,0xff,0xe0
Gold,0xff,0xd7,0x00
Light Goldenrod,0xee,0xdd,0x82
Goldenrod,0xda,0xa5,0x20
Dark Goldenrod,0xb8,0x86,0x0b
Rosy Brown,0xbc,0x8f,0x8f
Indian Red,0xcd,0x5c,0x5c
Saddle Brown,0x8b,0x45,0x13
Sienna,0xa0,0x52,0x2d
Peru,0xcd,0x85,0x3f
Burlywood,0xde,0xb8,0x87
Beige,0xf5,0xf5,0xdc
Wheat,0xf5,0xde,0xb3
Sandy Brown,0xf4,0xa4,0x60
Tan,0xd2,0xb4,0x8c
Chocolate,0xd2,0x69,0x1e
Firebrick,0xb2,0x22,0x22
Brown,0xa5,0x2a,0x2a
Dark Salmon,0xe9,0x96,0x7a
Salmon,0xfa,0x80,0x72
Light Salmon,0xff,0xa0,0x7a
Orange,0xff,0xa5,0x00
Dark Orange,0xff,0x8c,0x00
Coral,0xff,0x7f,0x50
Light Coral,0xf0,0x80,0x80
Tomato,0xff,0x63,0x47
Orange Red,0xff,0x45,0x00
Hot Pink,0xff,0x69,0xb4
Deep Pink,0xff,0x14,0x93
Pink,0xff,0xc0,0xcb
Light Pink,0xff,0xb6,0xc1
Pale Violet Red,0xdb,0x70,0x93
Maroon,0xb0,0x30,0x60
Medium Violet Red,0xc7,0x15,0x85
Violet Red,0xd0,0x20,0x90
Violet,0xee,0x82,0xee
Plum,0xdd,0xa0,0xdd
Orchid,0xda,0x70,0xd6
Medium Orchid,0xba,0x55,0xd3
Dark Orchid,0x99,0x32,0xcc
Dark Violet,0x94,0x00,0xd3
Blue Violet,0x8a,0x2b,0xe2
Purple,0xa0,0x20,0xf0
Medium Purple,0x93,0x70,0xdb
Thistle,0xd8,0xbf,0xd8
"""
with open('color_chart.cpp', 'wb') as f:
f.write('#include <boost/bind.hpp>\n#include <boost/function.hpp>\n\n');
f.write('#include "asserts.hpp"\n#include "color_chart.hpp"\n\nnamespace graphics {\n\n')
f.write('namespace {\n\nstd::map<std::string,boost::function<const SDL_Color&()> >& get_color_cache()\n{\n\tstatic std::map<std::string,boost::function<const SDL_Color&()> > color_cache;\n\treturn color_cache;\n}\n\nvoid color_cache_init()\n{\n')
for color in color_chart.split('\n'):
if color != '':
name,rs,gs,bs = color.split(',')
name = name.replace(' ', '_').lower()
f.write('\tget_color_cache()["%s"] = boost::bind(graphics::color_%s);\n' % (name, name))
f.write('}\n\n}\n\n')
f.write('const SDL_Color& get_color_from_name(std::string name)\n{\n\tif(get_color_cache().empty()) {\n\t\tcolor_cache_init();\n\t}\n\tstd::map<std::string,boost::function<const SDL_Color&()> >::iterator it = get_color_cache().find(name);\n\tif(it != get_color_cache().end()) {\n\t\treturn it->second();\n\t}\n\tASSERT_LOG(false, "Color \\"" << name << "\\" not known!");\n\treturn color_black();\n}\n\n')
for color in color_chart.split('\n'):
if color != '':
name,rs,gs,bs = color.split(',')
name = name.replace(' ', '_').lower()
r = int(rs, 16); g = int(gs, 16); b = int(bs, 16)
f.write('const SDL_Color& color_%s()\n{\n\tstatic SDL_Color res = {0x%02x, 0x%02x, 0x%02x, 0xff};\n\treturn res;\n}\n\n' % (name,r,g,b))
f.write('}\n')
with open('color_chart.hpp', 'wb') as f:
f.write('#pragma once\n#ifndef COLOR_CHART_HPP_INCLUDED\n#define COLOR_CHART_HPP_INCLUDED\n\n')
f.write('#include <map>\n\n#include "graphics.hpp"\n\nnamespace graphics {\n\n')
f.write('const SDL_Color& get_color_from_name(std::string name);\n\n')
for color in color_chart.split('\n'):
if color != '':
name,rs,gs,bs = color.split(',')
name = name.replace(' ', '_').lower()
r = int(rs, 16); g = int(gs, 16); b = int(bs, 16)
f.write('const SDL_Color& color_%s();\n' % name)
f.write('\n}\n\n#endif\n')
Jump to Line
Something went wrong with that request. Please try again.