X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=tools%2Fgen-styles;h=785ece60b1a90aed5924850fe8b8da63a99c7670;hb=3467ccc6b19c7a97088d5719772b05c73372bb39;hp=0012d5d52921b190123fa36ae409d7a7ec782e27;hpb=de26fb7861045ed3b7c07b804866b3da5a846afc;p=mobile-ledger-staging.git
diff --git a/tools/gen-styles b/tools/gen-styles
index 0012d5d5..785ece60 100644
--- a/tools/gen-styles
+++ b/tools/gen-styles
@@ -1,10 +1,19 @@
#!/usr/bin/perl
-use strict; use warnings; use utf8;
+use strict; use warnings; use utf8::all;
use autodie;
use Math::Trig;
use File::Basename qw(basename dirname);
use File::Temp qw(tempfile);
+use Getopt::Long;
+
+my $opt_night;
+
+GetOptions(
+ 'night!' => \$opt_night,
+) or exit 1;
+
+my $DEFAULT_HUE = 261.2245;
sub hexTuple {
my ($r, $g, $b) = @_;
@@ -84,7 +93,7 @@ sub hexToHSL {
my $hexTriplet = shift;
my ($r,$g,$b) = hexToRGB($hexTriplet);
- warn "$hexTriplet -> $r:$g:$b";
+ #warn "$hexTriplet -> $r:$g:$b";
for ($r, $g, $b ) { $_ = $_ / 255.0 }
@@ -116,11 +125,11 @@ sub hexToHSL {
return( $H, $S, $L );
}
-my $baseColorHSV = [ hexToHSL('#935ff2') ];
+my $baseColor = '#935ff2';
+my $baseColorHSV = [ hexToHSL($baseColor) ];
my $baseColorHue = $baseColorHSV->[0];
-warn sprintf( 'H:%1.4f S:%1.4f V:%1.4f', @$baseColorHSV );
-warn sprintf( 'H:%1.4f S:%1.4f L:%1.4f', hexToHSL('#3e148c') );
-my @target = hexToRGB('#935ff2');
+warn sprintf( '%s â H:%1.4f S:%1.4f V:%1.4f', $baseColor, @$baseColorHSV );
+my @target = hexToRGB($baseColor);
my ($best, $min_dist);
for (my $s = 0.50; $s < 0.90; $s += 0.001) {
for ( my $l = 0.50; $l <= 0.80; $l += 0.001 ) {
@@ -135,10 +144,10 @@ for (my $s = 0.50; $s < 0.90; $s += 0.001) {
}
}
}
-warn sprintf( 's%1.3f, l%1.3f -> %s',
+warn sprintf( 's%1.3f, l%1.3f â %s',
@$best );
-my $baseTheme = "AppTheme.NoActionBar";
+my $baseTheme = "AppTheme";
use constant STEP_DEGREES => 5;
@@ -152,7 +161,6 @@ use constant STEP_DEGREES => 5;
# hsvHex($hue/360.0, 0.86, 0.55);
# printf " - #%s
\n",
# hsvHex(($hue-4)/360.0, 0.72, 0.82);
-# printf " - #ffffffff
\n";
# printf " - #28%s
\n",
# hsvHex($hue/360.0, 0.65, 0.83);
# printf " - #28%s
\n",
@@ -166,7 +174,8 @@ use constant STEP_DEGREES => 5;
sub outputThemes {
my $out = shift;
my $baseIndent = shift;
- $out->print(hslStyleForHue($baseColorHue, undef, $baseIndent));
+ $out->print("\n");
+ $out->print(hslStyleForHue($DEFAULT_HUE, $baseTheme, $baseIndent, 'default'));
for( my $hue = 0; $hue < 360; $hue += STEP_DEGREES ) {
$out->print("\n");
$out->print(hslStyleForHue($hue, $baseTheme, $baseIndent));
@@ -177,49 +186,58 @@ sub hslStyleForHue {
my $hue = shift;
my $base = shift;
my $baseIndent = shift // '';
-
- my $blueL = 0.665;
- my $yellowL = 0.350;
-
- my $blueL2 = 0.350;
- my $yellowL2 = 0.500;
-
- # $y == 0 for yellow
- my $y = $hue - 60;
- $y += 360 if $y < 0;
- # $q == 0 for yellow, 1 for blue
- my $q = cos(deg2rad(abs($y-180)/2.0));
- my $l1 = $yellowL + ($blueL - $yellowL) * $q;
- my $l2 = 0.250 + 0.250 * $q;
- my $l3 = 0.950;
- my $l4 = 0.980;
+ my $subTheme = shift // sprintf('%03d', $hue);
+
+ my %lQ = (
+ 0 => 0.450, # red
+ 60 => 0.400, # yellow
+ 120 => 0.400, # green
+ 180 => 0.390, # cyan
+ 240 => 0.745, # blue
+ 300 => 0.505, # magenta
+ );
+ $lQ{360} = $lQ{0};
+
+ my ($x0, $x1, $y0, $y1);
+ $x0 = (int( $hue / 60 ) * 60) % 360;
+ $x1 = $x0 + 60;
+ $y0 = $lQ{$x0};
+ $y1 = $lQ{$x1};
+
+ # linear interpolation
+ my $l1 = $y0 + 1.0 * ( $hue - $x0 ) * ( $y1 - $y0 ) / ( $x1 - $x0 );
+
+ my $l2 = $l1 * 0.80;
+ my $l3 = $opt_night ? 0.200 : 0.950;
+ my $l4 = $opt_night ? 0.100 : 0.980;
my $result = "";
my $indent = "$baseIndent ";
if ($base) {
- $result .= sprintf "$baseIndent\n";
return $result;
@@ -231,6 +249,7 @@ if ($xml) {
my $start_marker = '';
my $end_marker = '';
my ($fh, $filename) = tempfile(basename($0).'.XXXXXXXX', DIR => dirname($xml));
+ $fh->binmode(':utf8');
open(my $in, '<', $xml);
my $base_indent = '';
my $state = 'waiting-for-start-marker';