#!/usr/bin/env perl ## # https://www.perlmonks.org/?node_id=11104262 # # 100 simultaneous supernovae collapse into a supermassive blackhole! # This makes a pretty picture by incrementing the sigma values on the # sample data resulting in an animated GIF. Please feel free to hack # it up and post your version! ## use strict; use warnings; use Imager::Heatmap; use MCE; my $filename = 'heatmapa.gif'; my @insert = sample_data(); my @images = (); $| = 1; print "Generating GIF frame "; my @data; MCE->new( max_workers => 20, input_data => [ 1 .. 90 ], chunk_size => 1, init_relay => '', gather => sub { my ($chunk_id) = @_; $data[ $chunk_id - 1 ] = $_[1]; }, user_func => sub { my $x = $_; my $hmap = Imager::Heatmap->new( xsize => 300, ysize => 300, xsigma => $x, ysigma => $x, ); $hmap->insert_datas(@insert); $hmap = $hmap->draw; my $data; $hmap->write(data => \$data, type => 'tiff'); # calling relay so orderly print output MCE::relay { print "$x "; MCE->gather(MCE->chunk_id, $data); }; } )->run; print "done!\n"; Imager->write_multi({ file => $filename, transp => 'none', gif_loop => 0, }, map { Imager->read_multi(data => \$_) } @data); print "Saved $filename\n"; sub sample_data { my @insert = (); while () { chomp; push @insert, [ split /\s/ ] } return @insert } __DATA__ ...