chiark / gitweb /
quacks-ingredients: wip counts
[reprap-play.git] / quacks-ingredients-counts
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Data::Dumper;
6 use POSIX;
7
8 $_=<DATA>; chomp or die;
9 our @names = split /\t/, $_;
10
11 our %count;
12
13 foreach my $nspots (qw(1 2 3 4)) {
14     $_=<DATA>; chomp or die;
15     my @l = split /\t/, $_;
16     foreach my $i (0..$#names) { $count{$names[$i]}{$nspots} = $l[$i] || 0; }
17 }
18
19 $_ = Dumper(\%count);
20 s{^}{// }mg;
21
22 our $name;
23
24 sub wrtoplevel () {
25     print "module $name(){ ////toplevel\n";
26     my $cs = $count{$name};
27     my $total = 0; $total += $_ foreach values %$cs;
28     my $rowsz = ceil(sqrt($total));
29     my $nrows = ceil($total / $rowsz);
30     my $ix = 0;
31     print "// total=$total, rowsz=$rowsz, nrows=$nrows\n";
32     foreach my $ndots (sort keys %$cs) {
33         my $c = $cs->{$ndots};
34         print <<END;
35   union(){
36     \$ndots = $ndots;
37 END
38         while ($c--) {
39             my $xy = sprintf "[ %5.1f, %5.1f ]",
40                 $ix / $nrows - 0.5 * $rowsz,
41                 $ix % $nrows - 0.5 * $nrows;
42             print "    translate(token_pitch * $xy) Token_L();\n";
43             $ix++;
44         }
45         print <<END;
46   };
47 END
48     }
49     print "}\n";
50 }
51
52 foreach $name (sort keys %count) {
53     wrtoplevel();
54 }
55
56 STDOUT->error and die $!;
57
58 __DATA__
59 White   Green   Blue    Red     Yellow  Purple  Black   Orange
60 20      15      14      12      13      15      18      20
61 8       10      10      8       6
62 4
63         13      10      10      10