Root/tornado/fw/txt/xbm2gp

1#!/usr/bin/perl
2$I = 50; # inner radius (50 cm)
3$O = 80; # outer radius (80 cm)
4#$Y = 64; # image heights (pixels)
5#$X = 256; # image width (pixels)
6
7
8sub ang
9{
10    local ($r) = @_;
11
12# (O-I)/Y = r*arc(a)
13# arc
14    return ($O-$I)/$Y/$r;
15}
16
17
18if ($ARGV[0] eq "-r") {
19    shift @ARGV;
20    $rect = 1;
21}
22
23while (<>) {
24    chop;
25    if (/#define\s+\S+_width\s+(\d+)/) {
26        $X = $1;
27        next;
28    }
29    if (/#define\s+\S+_height\s+(\d+)/) {
30        $Y = $1;
31        next;
32    }
33    next unless /\s*0x/;
34    s/^\s*//;
35    s/(,|};)$//;
36    push(@p, split /,/);
37}
38
39for ($x = 0; $x != $X; $x++) {
40    for ($y = 0; $y != $Y; $y++) {
41        $i = $x+$y*$X;
42        $p = ((hex $p[$i >> 3]) >> ($i & 7)) & 1;
43        next unless $p;
44        if ($rect) {
45            print "$x ", $Y-$y-1, "\n";
46        } else {
47            $r = ($Y-$y-1)/$Y*($O-$I)+$I;
48            $a = &ang($O)*($x-$X/2);
49            print $r*sin($a), " ", $r*cos($a), "\n";
50        }
51    }
52}
53

Archive Download this file

Branches:
master
tornado-v1



interactive