in reply to Re^2: Ordering colors for contrast (luma)
in thread [OT] Ordering colors

Ha, there are four lumas, ( 2.996, 3.7112 , 2.7834, 3.4986, ) ... yaytk

#!/usr/bin/perl -- ## ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## #!/usr/bin/perl -- use strict; use warnings; use Tk; Main( @ARGV ); exit( 0 ); sub Main { my @set = qw/ 2 6 A E/; my $mw = tkinit( -title => "Print out the canvas" ); my $dad = $mw; Feh( $dad, [qw/-row 0 -column 0/], colorsFromSet( @set ) ); Feh( $dad, [qw/-row 0 -column 1/], Lumated( @set ) ); Feh( $dad, [qw/-row 1 -column 0/], Fudgy( @set ) ); Feh( $dad, [qw/-row 1 -column 1/], FudgyLum( @set ) ); $mw->MainLoop; } ## end sub Main sub Feh { my( $mw, $popt, @feh ) = @_; my $canvas = $mw->Canvas( -background => '#ffffff', )->grid( @$pop +t ); for my $i ( 1 .. @feh ) { my $color = $feh[ -1 + $i ]; drLine( $canvas, $i, $color ); } } ## end sub Feh sub Lumated { my @colors = colorsFromSet( @_ ); return map { $$_[1] } sort { $$a[0] <=> $$b[0] } map { [ luma( $_ ), $_ ]; } @colors; } ## end sub Lumated sub FudgyLum { my @final; my @them = Lumated( @_ ); while( my @dd = splice @them, 0, 16 ) { my @new; while( @dd ) { push @new, shift @dd; push @new, pop @dd; } push @final, @new; } @final; } ## end sub FudgyLum sub Fudgy { my @final; my @them = colorsFromSet( @_ ); while( my @dd = splice @them, 0, 16 ) { my @new; while( @dd ) { push @new, shift @dd; push @new, pop @dd; } push @final, @new; } @final; } ## end sub Fudgy sub drLine { my( $canvas, $x, $color ) = @_; my $x1 = $x * 5; my $y1 = 0; my $x2 = $x1 + 180; my $y2 = 420; $canvas->createLine( $x1, $y1, $x2, $y2, -fill => $color, -arrow => 'first', -smooth, 1, -splinesteps, 9999, -arrowshape => [ $y2, 25, 1 ] ); } ## end sub drLine sub colorsFromSet { my @set = @_; my @colors; for my $r ( @set ) { for my $g ( @set ) { for my $b ( @set ) { push @colors, "#$r$g$b"; } } } return @colors; } ## end sub colorsFromSet sub contraColor { my( $color ) = @_; return( luma( $color ) >= 165 ) ? '000' : 'fff'; } ## end sub contraColor sub hexToRgb { my( $color ) = @_; my( $rr, $gg, $bb ) = $color =~ m{^#?(.?.?)(.?.?)(.?.?)}; no warnings 'numeric'; $_ = int unpack 'HH', $_ for( $rr, $gg, $bb ); #~ return [ $rr, $gg, $bb ]; return $rr, $gg, $bb; } ## end sub hexToRgb sub luma { my( $color ) = @_; my @rgb = ref $color ? @$color : hexToRgb( $color ); ## // SMPTE C, Rec. 709 weightings return( 0.2126 * $rgb[0] ) + ( 0.7152 * $rgb[1] ) + ( 0.0722 * $rg +b[2] ); } ## end sub luma __END__

Replies are listed 'Best First'.
Re^4: Ordering colors for contrast (swap tk)
by BrowserUk (Patriarch) on May 06, 2015 at 06:58 UTC

    Taking note of the interleaving done in your fudgy examples, and looking at the results, I wondered what the result would look like if I did the Luma sort followed by a full interleave (rather than your 4 partial interleaves) and I was very pleasantly surprised by the result.

    Whilst the color-blind compatible stuff is good for small sets (<=12), I've a need for a greater range and I think this luma-sorted & interleaved is pretty good for up to 64 colors on black or white backgrounds.

    Thanks for the cluebats.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked