use strict; use warnings; use 5.032; # chained comparison use Term::ANSIScreen; use GD; use if $^O eq 'MSWin32', 'Win32::Console'; my $OUT; if ( $^O eq 'MSWin32' ) { $OUT = Win32::Console-> new( STD_OUTPUT_HANDLE ); $OUT-> OutputCP( 65001 ); $OUT-> Mode( $OUT-> Mode | 4 ); } my @shades = ( "\N{SPACE}", "\N{LIGHT SHADE}", "\N{MEDIUM SHADE}", "\N{DARK SHADE}", "\N{FULL BLOCK}" ); utf8::encode( $_ ) for @shades; my @hues = ; my @chars; my $source = GD::Image-> new( 'rose.png' ) or die; my $dest = GD::Image-> new( 1, 1 ) or die; BLOCK1: # 5 neutral grays for my $s ( 0 .. $#shades ) { $dest-> colorAllocate(( 255 / $#shades * $s ) x 3 ); push @chars, colored( $shades[ $s ], 'white' ) } BLOCK2: # 24 = (6 hues) * (4 shades) for my $h ( 0 .. $#hues ) { for my $s ( 1 ..$#shades ) { $dest-> colorAllocate( map { $_ / $#shades * $s * 255 } ( 0 <= $h <= 1 || $h == 5 ), # R ( 1 <= $h <= 3 ), # G ( 3 <= $h <= 5 ) # B ); push @chars, colored( $shades[ $s ], $hues[ $h ]) } } for my $y ( 0 .. $source-> height - 1 ) { for my $x ( 0 .. $source-> width - 1 ) { my $rgb = $source-> getPixel( $x, $y ); my ( $r, $g, $b ) = $source-> rgb( $rgb ); print $chars[ $dest-> colorClosestHWB( $r, $g, $b )] } print "\n" }