#!/usr/bin/perl -w # halftone.pl - Don Yang (uguu.org) # # Drop every other character. # # 2019-02-24 die "$0 \n" unless $#ARGV >= 0; my $ratio = shift @ARGV; ($ratio =~ /^\d+$/ && $ratio > 0) or die "Invalid ratio: $ratio\n"; my $y = 0; while( my $line = <> ) { chomp $line; my $x = 0; my $output = ""; foreach my $c (map {chr} unpack 'C*', $line) { if( ($x + $y) % $ratio == 0 ) { $output .= $c; } else { $output .= " "; } $x++; } print $output, "\n"; # Tweak to change the halftone direction. If we simply did $y++, # the dots will appear in a diagonal pattern '/', but it seems more # pleasant to have the diagonal patterns look like '\'. $y = ($y + $ratio - 1); }