3 use strict; use warnings; use utf8;
7 return sprintf('%02x%02x%02x', int(255*$r+0.5), int(255*$g+0.5), int(255*$b+0.5));
10 my ($hue, $sat, $val ) = @_;
11 my $h = int($hue * 6);
12 my $f = $hue * 6 - $h;
13 my $p = $val * (1 - $sat);
14 my $q = $val * ( 1 - $f * $sat);
15 my $t = $val * ( 1 - (1-$f) * $sat);
17 return hexTuple($val, $t, $p) if $h == 0 or $h == 6;
18 return hexTuple($q, $val, $p) if $h == 1;
19 return hexTuple($p, $val, $t) if $h == 2;
20 return hexTuple($p, $q, $val) if $h == 3;
21 return hexTuple($t, $p, $val) if $h == 4;
22 return hexTuple($val, $p, $q) if $h == 5;
27 # https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSL
29 my ($hue, $sat, $lig ) = @_;
31 my $c = (1 - abs(2.0*$lig - 1)) * $sat;
32 my $h_mod_2 = $h - 2*int($h/2);
33 my $x = $c * (1 - abs($h_mod_2 - 1));
35 my $m = $lig - $c / 2.0;
37 return hexTuple($c + $m, $x + $m, 0 + $m) if $h < 1 or $h == 6;
38 return hexTuple($x + $m, $c + $m, 0 + $m) if $h < 2;
39 return hexTuple( 0 + $m, $c + $m, $x + $m) if $h < 3;
40 return hexTuple( 0 + $m, $x + $m, $c + $m) if $h < 4;
41 return hexTuple($x + $m, 0 + $m, $c + $m) if $h < 5;
42 return hexTuple($c + $m, 0 + $m, $x + $m) if $h < 6;
47 my @hexDigit = split //, '0123456789abcdef';
49 (lc($hexDigit[$_]) => $_, uc($hexDigit[$_]) => $_ ),
55 for (@_) { $min = $_ if $_ < $min }
63 for (@_) { $max = $_ if $_ > $max }
69 my $hexTriplet = shift;
70 my ( $r,$g,$b ) = $hexTriplet =~ /^#?(..)(..)(..)/;
73 $_ = 16 * $hexValue{$d[0]} + $hexValue{$d[1]};
76 warn "$hexTriplet -> $r:$g:$b";
78 for ($r, $g, $b ) { $_ = $_ / 255.0 }
80 my $M = max($r, $g, $b);
81 my $m = min($r, $g, $b);
98 else { die "$C, $M, $r, $g, $b"; }
101 my $L = ($M + $m) / 2;
103 my $S = ( $L <= 0.5 ) ? $C/(2*$L) : $C / (2-2*$L);
105 return( $H, $S, $L );
108 my $baseColorHSV = [ hexToHSL('#935ff2') ];
109 my $baseColorHue = $baseColorHSV->[0];
110 warn sprintf( 'H:%1.4f S:%1.4f L:%1.4f', @$baseColorHSV );
111 warn sprintf( 'H:%1.4f S:%1.4f L:%1.4f', hexToHSL('#3e148c') );
113 my $baseTheme = "AppTheme.NoActionBar";
116 # for( my $hue = 0; $hue < 360; $hue += 15 ) {
117 # printf "<style name=\"%s.%d\" parent=\"%s\">\n",
118 # $baseTheme, $hue, $baseTheme;
119 # printf " <item name=\"colorPrimary\">#%s</item>\n",
120 # hsvHex($hue/360.0, 0.61, 0.95);
121 # printf " <item name=\"colorPrimaryDark\">#%s</item>\n",
122 # hsvHex($hue/360.0, 0.86, 0.55);
123 # printf " <item name=\"colorAccent\">#%s</item>\n",
124 # hsvHex(($hue-4)/360.0, 0.72, 0.82);
125 # printf " <item name=\"drawer_background\">#ffffffff</item>\n";
126 # printf " <item name=\"table_row_dark_bg\">#28%s</item>\n",
127 # hsvHex($hue/360.0, 0.65, 0.83);
128 # printf " <item name=\"table_row_light_bg\">#28%s</item>\n",
129 # hsvHex($hue/360.0, 0.20, 1.00);
130 # printf " <item name=\"header_border\">#80%s</item>\n",
131 # hsvHex(($hue+6)/360.0, 0.86, 0.55);
132 # printf "</style>\n";
136 hslStyleForHue($baseColorHue);
137 for( my $hue = 0; $hue < 360; $hue += 15 ) {
138 hslStyleForHue($hue, $baseTheme);
146 printf "<style name=\"%s.%d\" parent=\"%s\">\n",
147 $baseTheme, $hue, $baseTheme;
150 printf "<style name=\"%s\">\n",
152 printf " <item name=\"windowActionBar\">false</item>\n";
153 printf " <item name=\"windowNoTitle\">true</item>\n";
154 printf " <item name=\"textColor\">#d0000000</item>\n";
156 printf " <item name=\"colorPrimary\">#%s</item>\n",
157 hslHex($hue/360.0, 0.60, 0.60);
158 printf " <item name=\"colorPrimaryTransparent\">#00%s</item>\n",
159 hslHex($hue/360.0, 0.60, 0.60);
160 printf " <item name=\"colorAccent\">#%s</item>\n",
161 hslHex($hue/360.0, 0.85, 0.50);
162 printf " <item name=\"drawer_background\">#ffffffff</item>\n";
163 printf " <item name=\"table_row_dark_bg\">#%s</item>\n",
164 hslHex($hue/360.0, 0.85, 0.95);
165 printf " <item name=\"table_row_light_bg\">#%s</item>\n",
166 hslHex($hue/360.0, 0.85, 0.98);