my( $c, @lineSegs ) = 1; for my $x ( 0 .. $X - 2 ) { ++$c, next if $colors[ $x ] == $colors[ $x + 1 ]; push @lineSegs, [ $c, $colors[ $x ] ]; $c = 1; } push @lineSegs, [ $c, $colors[ - 1] ]; $Qout->enqueue( [ $y, \@lineSegs ] ); #### while( my $line = $Qresults->dequeue ) { my( $y, $l ) = @{ $line }; for( @$l ) { my( $count, $color ) = @{ $_ }; $i->line( $x, $y, $x + $count, $y, $color ); $x += $count; } #### ## calculate the Mandelbrot values for half the line my @colors; for my $x ( 0 .. $halfX - 1 ) { push( @colors, rgb2n( (0)x3 ) ), next if clip( $x, $y ); my $m = mandelbrot( ( $x - $halfX ) / $halfX, ( $y - $halfY ) / $halfY ); my $c = mapColors( $m ); push @colors, $m == 0 ? 0 : $c; } ## compress pixels to count/color pairs (line segments) my( $c, @lineSegs ) = 1; for my $x ( 0 .. $halfX - 2 ) { ++$c, next if $colors[ $x ] == $colors[ $x + 1 ]; push @lineSegs, [ $c, $colors[ $x ] ]; $c = 1; } push @lineSegs, [ $c, $colors[ - 1] ]; ## Queue back the line segments for half the line. $Qout->enqueue( [ $y, \@lineSegs ] ); #### while( my $line = $Qresults->dequeue ) { my( $y, $l ) = @{ $line }; my $x = 0; ## for all the line segments, and those same segments ( again in reverse order ) for( @$l, reverse @$l ) { ## extract the count and the color my( $count, $color ) = @{ $_ }; ## draw the line segment $i->line( $x, $y, $x + $count, $y, $color ); ## accumulating your current x position as you go. $x += $count; } }