sub render($self) { my $lastfgcolor = ''; my $lastbgcolor = ''; my $out = '' . $self->{home}; my ($r, $g, $b); # Color vars for(my $y = 0; $y < $self->{rows}; $y+=2) { for(my $x = 0; $x < $self->{cols}; $x++) { # Foreground color ($r,$g,$b) = @{$self->{img}->[$x + ($y * $self->{cols})]}; my $newfgcolor = "\e[38;2;" . join(';', $r, $g, $b) . "m"; if($newfgcolor ne $lastfgcolor) { $lastfgcolor = $newfgcolor; $out .= $newfgcolor; } # Background color my $lowy = $y + 1; if($lowy == $self->{rows}) { # End of image. need a black half-line ($r, $g, $b) = (0, 0, 0); } else { ($r,$g,$b) = @{$self->{img}->[$x + ($lowy * $self->{cols})]}; } my $newbgcolor = "\e[48;2;" . join(';', $r, $g, $b) . "m"; if($newbgcolor ne $lastbgcolor) { $lastbgcolor = $newbgcolor; $out .= $newbgcolor; } $out .= $halfblock; #print utf8::encode("\N{FULL BLOCK}"); } ($r, $g, $b) = (0, 0, 0); $lastfgcolor = "\e[38;2;" . join(';', 255, 255, 255) . "m"; $lastbgcolor = "\e[48;2;" . join(';', 0, 0, 0) . "m"; $out .= $lastfgcolor . $lastbgcolor . "\n"; } my $now = time; my $fps = 0; if($self->{lastrender}) { $fps = (int((1 / ($now - $self->{lastrender})) * 100)/100); } $self->{lastrender} = $now; # Status line my ($pre, $post) = split/\./o, $fps; if(!defined($post)) { $post = '00'; } while(length($pre) < 4) { $pre = ' ' . $pre; } while(length($post) < 2) { $post .= '0'; } $fps = 'FPS: ' . $pre . '.' . $post; $fps .= ' ' x (18 - length($fps)); $out .= $fps; $out .= $self->{statustext}; if($self->{info} ne '') { $out .= $self->{info}; $out .= ' ' x (220 - length($self->{info})); } elsif($self->{progress} == -1) { $out .= ' ' x 220; } elsif($self->{info} ne '') { $out .= $self->{info}; $out .= ' ' x (220 - length($self->{info})); } else { $out .= $fullblock; my $full = int(218 * $self->{progress}); $out .= $darkshade x $full; $out .= $lightshade x (218-$full); $out .= $fullblock; } print $out; my $key = ReadKey(-1); if(defined($key)) { $key = ord($key); #croak("\n\n\n ** $key **\n"); if($key == 32) { return 1; } elsif($key == 27 || $key == 113) { return -1; } } return 0; }