aboutsummaryrefslogtreecommitdiff
path: root/shipshape.pl
blob: 89cfacd086a83c8b5ae0b0a550748cd8aa32a37b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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, "<taifont" or die $!;
$f = <$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;
	}
}