Skip to content

Instantly share code, notes, and snippets.

@jpf91 jpf91/kitColor.d
Last active Jun 27, 2017

Embed
What would you like to do?
// Run at https://dpaste.dzfl.pl/861b8e5dd07b
// https://intranet.kit.edu/gestaltungsrichtlinien.php
// https://intranet.kit.edu/downloads/2_Gestaltungsgrundlagen.pdf
import std.stdio, std.string, std.array, std.algorithm, std.conv, std.range, std.math;
string input = "KIT-Schwarz
0 C
0 R
0 M
0 G
0 Y
0 B
100 K
KIT-Grün exklusiv
100 C
0 R
0 M
150 G
60 Y
130 B
0 K
KIT-Blau exklusiv
80 C
70 R
50 M
100 G
0 Y
170 B
0 K
KIT-Maigrün
60 C
140 R
0 M
182 G
100 Y
60 B
0 K
KIT-Gelb
0 C
252 R
5 M
229 G
100 Y
0 B
0 K
KIT-Orange
0 C
223 R
45 M
155 G
100 Y
27 B
0 K
KIT-Braun
35 C
167 R
50 M
130 G
100 Y
46 B
0 K
KIT-Rot
25 C
162 R
100 M
34 G
100 Y
35 B
0 K
KIT-Lila
25 C
163 R
100 M
16 G
0 Y
124 B
0 K
KIT-Cyan-Blau
90 C
35 R
5 M
161 G
0 Y
224 B
0 K
";
struct Color
{
string name;
size_t R, G, B;
size_t C, M, Y, K;
}
Color parseColor(string[] data)
{
Color result;
result.name = data[0].strip();
result.C = parse!size_t(data[1]);
assert(data[1].canFind('C'));
result.R = parse!size_t(data[2]);
assert(data[2].canFind('R'));
result.M = parse!size_t(data[3]);
assert(data[3].canFind('M'));
result.G = parse!size_t(data[4]);
assert(data[4].canFind('G'));
result.Y = parse!size_t(data[5]);
assert(data[5].canFind('Y'));
result.B = parse!size_t(data[6]);
assert(data[6].canFind('B'));
result.K = parse!size_t(data[7]);
assert(data[7].canFind('K'));
return result;
}
void printOriginal(Color c)
{
writeln(c.name);
writefln("original RGB: %s, %s, %s CMYK: %s, %s, %s, %s", c.R, c.G, c.B, c.C, c.M, c.Y, c.K);
writeln();
}
void printLatex(Color c)
{
string name = c.name.replace("ü", "ue").replace(" exklusiv", "").replace("-", "");
writefln("\\definecolor{%s}{rgb/cmyk}{%s,%s,%s/%s,%s,%s,%s}", name,
c.R/255.0, c.G/255.0, c.B/255.0, c.C/100.0, c.M/100.0, c.Y/100.0, c.K/100.0);
}
void printFull(Color c)
{
auto lightenRGB(size_t value, double factor)
{
// white is 255,255,255
// Rounding in KIT document is inconsistent
return cast(size_t)round(value * factor + 255 * (1-factor));
}
writeln(c.name);
writeln("---------------------------------------");
auto lighten = [1, 0.7, 0.5, 0.3, 0.15];
foreach(per; lighten)
{
writefln("%s%%", per*100);
writefln("CMYK: %s, %s, %s, %s", c.C*per, c.M*per, c.Y*per, c.K*per);
auto c2 = c;
c2.R = lightenRGB(c2.R, per);
c2.G = lightenRGB(c2.G, per);
c2.B = lightenRGB(c2.B, per);
writefln("RGB: %s, %s, %s\t#%.2x%.2x%.2x", c2.R, c2.G, c2.B, c2.R, c2.G, c2.B);
writeln("---------------------------------------");
}
writeln();
}
void main()
{
auto colors = input.lineSplitter()
.chunks(8)
.map!(x => parseColor(x.array))
.array;
colors.each!printOriginal;
writeln("\\usepackage{xcolor}");
writeln("% Lightened versions are 100%, 70%, 50%, 30% 15%");
writeln("% Use KITGruen!15 for 15% green");
colors.each!printLatex;
writeln();
colors.each!printFull;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.