Zhang-Suen thinning algorithm: Difference between revisions

Content added Content deleted
(Added Perl example)
m (→‎{{header|Perl 6}}: removed DEBUG, in-lined source data)
Line 3,059: Line 3,059:


=={{header|Perl 6}}==
=={{header|Perl 6}}==
Takes the original image from a file that may be based on any characters whose low bits are 0 or 1 (which conveniently includes . and #).
Source image may be based on any characters whose low bits are 0 or 1 (which conveniently includes . and #).
<lang perl6>constant DEBUG = 1;
<lang perl6>my $source = qq:to/EOD/;
................................
.#########.......########.......
.###...####.....####..####......
.###....###.....###....###......
.###...####.....###.............
.#########......###.............
.###.####.......###....###......
.###..####..###.####..####.###..
.###...####.###..########..###..
................................
EOD


my @lines = ([.ords X+& 1] for lines); # The low bits Just Work.
my @lines = ([.ords X+& 1] for $source.split("\n")); # The low bits Just Work.
my \v = +@lines;
my \v = +@lines;
my \h = +@lines[0];
my \h = +@lines[0];
Line 3,092: Line 3,103:
@goners1 = seewhite (0,2,4), (2,4,6);
@goners1 = seewhite (0,2,4), (2,4,6);
@black[@goners1] = 0 xx *;
@black[@goners1] = 0 xx *;
say "Ping: {[+] @black} remaining after removing ", @goners1 if DEBUG;
say "Ping: {[+] @black} remaining after removing ", @goners1;


@goners2 = seewhite (0,2,6), (0,4,6);
@goners2 = seewhite (0,2,6), (0,4,6);
@black[@goners2] = 0 xx *;
@black[@goners2] = 0 xx *;
say "Pong: {[+] @black} remaining after removing ", @goners2 if DEBUG;
say "Pong: {[+] @black} remaining after removing ", @goners2;
}
}