4 $SIG{__WARN__} = sub { die @_; };
6 # xxx much of the comment below is TODO
8 # We generate a physical indication of which commit was used.
10 # We provide for scaling factors with dynamic variables:
11 # $Commitid_pixelsz if not set, we use 0.4 } multiplied
12 # $Commitid_scale if not set, we use 1.0 } together
13 # $Commitid_depth if not set, we use xy pixel size from above
14 # $Commitid_depth_scale if not set, we use 1.0 (multiplies depth above)
16 # For each form we have
18 # module Commitid_Form_2D() { ... }
19 # module Commitid_Form() { ... }
21 # These have their origin in the bottom left corner. The 3D model
22 # is a positive, has its origin halfway through, and is twice the
23 # depth in height, so it can be added or subtracted.
27 # function Commitid_pixelsz() // $Commitid_pixelsz * $Commitid_scale
28 # function Commitid_depth() // see above
30 # We can generate these forms:
38 # git rev-list --first-parent --count HEAD
39 # typically 3-4 characters but we allow for up to 6
40 # padded with zeroes; if too long we reduce mod 10^n
47 # same but in two lines eg
54 # git-rev-parse HEAD (prefix of requested length)
61 # git-rev-list --first-parent --count HEAD
67 sub p { print @_ or die $!; }
70 // *** AUTOGENERATED - DO NOT EDIT *** //
71 function Commitid_pixelsz() =
72 ($Commitid_pixelsz ? $Commitid_pixelsz : 0.4) *
73 ($Commitid_scale ? $Commitid_scale : 1.0);
74 function Commitid_depth() =
75 ($Commitid_depth ? $Commitid_depth : Commitid_pixelsz()) *
76 ($Commitid_depth_scale ? $Commitid_depth_scale : 1.0);
77 function Commitid__scale() =
78 Commitid_pixelsz() / 0.1;
83 my $chrx = sprintf '%#x', ord $chr;
84 return "Commitid__chr_$chrx";
87 sub gentextmodule ($@) {
88 my ($form, @lines) = @_;
89 my $modb = "Commitid_$form";
90 p "module ${modb}_2D(){\n";
91 p " scale(Commitid__scale()){\n";
94 foreach my $line (@lines) {
97 foreach my $chr (split //, $line) {
98 next if $chr !~ m/\S/;
99 p sprintf " translate([%d * 0.8, %d * 1.2]) %s();\n",
100 $x, $y, chrmodname $chr;
103 $cols = $x if $x > $cols;
107 p "module ${modb}(){\n";
108 p " d=Commitid_depth();\n";
109 p " translate([0,0,-d]) linear_extrude(height=d*2) ${modb}_2D();\n";
111 p sprintf "function %s_sz() = Commitid__scale() * 0.1 * [ %d, %d ];\n",
112 $modb, 2 * (@lines * 6 - 1), 2 * ($cols * 4 - 1);
121 last if %cellmap && !m/\S/;
131 my @chrs = split / /, $_;
132 <DATA> !~ m/\S/ or die;
133 foreach my $row (reverse 0..4) {
144 foreach my $chr (@chrs) {
145 s{^ }{} or die "$chr $_ ?";
146 foreach my $col (0..2) {
150 my $f = $cellmap{$&};
152 $f =~ s/\b\d/ sprintf '%05d', $col*2000 + $&*1025 /ge;
153 $f =~ s/\d\b/ sprintf '%05d', $row*2000 + $&*1025 /ge;
154 push @{ $chrpolys{$chr} }, [ split / /, $f ];
166 foreach my $chr (sort keys %chrpolys) {
167 my $mod = chrmodname $chr;
168 p "module $mod () {\n";
169 foreach my $poly (@{ $chrpolys{$chr} }) {
172 foreach my $pt (@$poly) {
174 $pt =~ s{\d{5}}{$&,};
175 $pt =~ s{\b\d}{$&.}g;
184 @demo = reverse $demo =~ m{.{1,$democols}}go;
189 gentextmodule('FontDemo', @demo);
203 /#\ r /#\ ##\ # # ### // ### /#\ /#\
204 # # /# # # # # # # # # # # #
205 # # # /#/ ##< \## ##\ ##\ // >#< \##
206 # # # # # # # # # # # # #
207 \#/ /#\ ### ##/ # ##/ \#/ # \#/ ##/
213 /## ##\ # /## #r# ###
215 \## ##/ \## \## \#/ #