It will surprise few, if any, of you, that I had a go at recreating this with PDL. Some moderately neat things that came out of this: The latter two problems have been fixed on PDL git master and will be released soon(ish), once I've finished updating PDL::Graphics::Simple to support the needs of various main-PDL demos (and adding/fixing any PDL deficiencies that result from that), after which I will be generating web-output versions of all the PDL demos and put them on the website. In the meantime, if you have the lust for life to use PDL on git master, you can run the script below to make various sizes and orientations of XBMs fading about the place!
#!/usr/bin/env perl use 5.032; use warnings; use autodie ':all'; use Path::Tiny; use PDL; use PDL::GSL::RNG; die "Usage: $0 name\n" unless @ARGV == 1; my $name = $ARGV[0]; my ($base, $size, $orient) = split /_/, $name; my %bits_for = (s => 16, m => 32, l => 48, b => 96); die "Unknown size '$size'" unless exists $bits_for{$size}; my $bits = $bits_for{$size}; my $matrix = create_matrix($bits); my $oriented = orient_matrix($orient, $matrix); my $filename = get_filename($name, $bits); write_xbm($filename, $oriented); sub create_matrix { my ($bits) = @_; my $ones = ones(byte, ($bits+1)*$bits/2)->tritosquare; my $rng = PDL::GSL::RNG->new('mt19937'); $rng->ran_shuffle_1d($ones); $ones; } my %DISPATCH_TABLE; BEGIN { %DISPATCH_TABLE = ( n => sub { $_[0]->copy }, s => sub { $_[0]->slice(',-1:0')->sever }, e => sub { $_[0]->transpose->sever }, w => sub { $_[0]->slice(',-1:0')->transpose->sever }, ); } sub orient_matrix { my ($orient, $matrix) = @_; my $code = $DISPATCH_TABLE{$orient} or die "Unknown orientation '$orient'"; return $code->($matrix); } sub write_xbm { my ($filename, $matrix) = @_; $matrix->wpic($filename); } sub get_filename { my ($name, $size) = @_; my $dir = '.'; my @files = do { opendir(my $dh, $dir) or die "$dir: $!"; grep /^\Q$name\E_\d{4}/, readdir $dh; }; my $index = '0000'; if (@files) { $index = (sort { $b cmp $a } map /^\Q$name\E_(\d{4})/, @files) +[0]; ++$index; } my $indexed_name = $name . '_' . $index; my $xbm_file = $indexed_name . '.xbm'; return path($dir, $xbm_file); }

In reply to Re: Creating X BitMap (XBM) images with directional gradients by etj
in thread Creating X BitMap (XBM) images with directional gradients by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.