X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=tools%2Fgen-styles;h=23920c54bd29fcf3ac02d22295894b0aebdcbf1c;hb=e7a2fe989ab244998347c82c002e281246916186;hp=0b8759c2942e9b5b9bdf68dc700952e3918c011a;hpb=fbaaba448b36e6f43d357c7651acef6746670f6e;p=mobile-ledger.git diff --git a/tools/gen-styles b/tools/gen-styles index 0b8759c2..23920c54 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,7 +144,7 @@ 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"; @@ -165,6 +174,8 @@ use constant STEP_DEGREES => 5; sub outputThemes { my $out = shift; my $baseIndent = shift; + $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)); @@ -175,14 +186,15 @@ sub hslStyleForHue { my $hue = shift; my $base = shift; my $baseIndent = shift // ''; + my $subTheme = shift // sprintf('%03d', $hue); my %lQ = ( 0 => 0.450, # red 60 => 0.400, # yellow 120 => 0.400, # green - 180 => 0.400, # cyan - 240 => 0.750, # blue - 300 => 0.500, # magenta + 180 => 0.390, # cyan + 240 => 0.745, # blue + 300 => 0.505, # magenta ); $lQ{360} = $lQ{0}; @@ -196,34 +208,38 @@ sub hslStyleForHue { my $l1 = $y0 + 1.0 * ( $hue - $x0 ) * ( $y1 - $y0 ) / ( $x1 - $x0 ); my $l2 = $l1 * 0.80; - my $l3 = 0.950; - my $l4 = 0.980; + my $l3 = $opt_night ? 0.150 : 0.950; + my $l4 = $opt_night ? 0.100 : 0.980; my $result = ""; my $indent = "$baseIndent "; if ($base) { - $result .= sprintf "$baseIndent\n"; return $result; @@ -235,6 +251,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';