#! perl -slw use strict; use GD; use List::Util qw[ sum ]; sub rgb2n { unpack 'N', pack 'CCCC', 0, @_ } ## Gen some data my %counts; ++$counts{ int( rand( 5e3 ) + rand( 5e3 ) ) } for 1 .. 1e6; my @keys = sort{ $a <=> $b } keys %counts; my $gd = GD::Image->new( 10000, 2000, 1 ); for my $step ( reverse 1.. 10 ) { my $start = 0; my $last = 0; my $clr = 2**24 / $step; for( my $end = $start+$step-1; $end < $keys[ -1 ]; $end += $step ) { my $sum = sum( @counts{ grep( defined $counts{ $_ }, $start..$end ) } ) // 0; # printf "%4d - %4d : %d\n", $start, $end, $sum; $gd->line( $start, 2000-$last, $end, 2000-$sum, $clr ) if $last; $start = $end + 1; $last = $sum; } } open IMG, '>:raw', 'junk14.png' or die $!; print IMG $gd->png; close IMG; ## Display the graph in the default image viewer system 'junk14.png';