From 1989c02b763a04d0f941114056f11bb96bdb2550 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 5 May 2021 01:50:12 -0400 Subject: Finally fix damaged ship gfx --- shipshape.pl | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 shipshape.pl (limited to 'shipshape.pl') diff --git a/shipshape.pl b/shipshape.pl new file mode 100644 index 0000000..89cfacd --- /dev/null +++ b/shipshape.pl @@ -0,0 +1,61 @@ +#!/usr/bin/perl -w + +# draws an ASCII art representation of the lorcha. + +use bytes; + +if(!@ARGV) { + push @ARGV, "LORCHA.DAT"; +} + +undef $/; +$_ = <>; +@shape = unpack "C*", $_; + +open $in, "; +close $in; + +@out = (); + +for($row = 0; $row < 7; $row++) { + for($col = 0; $col < 7; $col++) { + draw_tile($row, $col); + } +} + +for($row = 0; $row < @out; $row++) { + for($col = 0; $col < 7; $col++) { + print $out[$row][$col]; + } + print "\n"; +} + + +sub draw_tile { + my $row = shift; + my $col = shift; + my $tile = $shape[$row * 7 + $col]; + my $reverse = 0; + my $i; + my $j; + my $y = $row * 8; + #$out[$row][$col] = sprintf(" %03x", $tile); + + if($tile > 127) { + $tile -= 128; + $reverse = 1; + } + for($i = 0; $i < 8; $i++) { + my $data = sprintf "%08b", ord substr($f, $tile * 8 + $i, 1); + if($reverse) { + $data =~ s/0/X/g; + $data =~ s/1/ /g; + } else { + $data =~ s/1/X/g; + $data =~ s/0/ /g; + } + + $out[$y + $i][$col] = $data; + } +} -- cgit v1.2.3