X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=commitid.scad.pl;h=dcebd26a5c1cd9bf853294d9ec3a63c1e86db7d6;hb=f0820c19256946b5b9bf6af9543b6e60b15037d4;hp=e1caf36d28b3858d8228713f5a0ab3878f24c59b;hpb=5c7ecbf56066a938bdb4635ef274af12d8ca788b;p=reprap-play.git diff --git a/commitid.scad.pl b/commitid.scad.pl index e1caf36..dcebd26 100755 --- a/commitid.scad.pl +++ b/commitid.scad.pl @@ -3,9 +3,27 @@ use strict; $SIG{__WARN__} = sub { die @_; }; +# xxx much of the comment below is TODO + # We generate a physical indication of which commit was used. # -# We can generate three forms: +# We provide for scaling factors with dynamic variables: +# $Commitid_pixelsz if not set, we use 0.4 } multiplied +# $Commitid_scale if not set, we use 1.0 } together +# $Commitid_depth if not set, we use xy pixel size from above +# $Commitid_depth_scale if not set, we use 1.0 (multiplies depth above) +# +# For each form we have +# +# module Commitid_Form_2D(.4) +# module Commitid_Form() +# +# And we provide +# +# function Commitid_pixelsz() // $Commitid_pixelsz * $Commitid_scale +# function Commitid_depth() // see above +# +# We can generate these forms: # # Tiny3: # Tiny4: @@ -25,6 +43,13 @@ $SIG{__WARN__} = sub { die @_; }; # Tiny4Q 10 # 70 # +# Git4 +# Git6 +# Git8 +# git-rev-parse HEAD +# eg +# Git6 82f2a2 + # Small4 # Small6 # Small8 @@ -34,9 +59,29 @@ $SIG{__WARN__} = sub { die @_; }; # Small6 1070 # 82f2a2 +sub p { print @_ or die $!; } + +p <<'END'; +function Commitid_pixelsz() = + ($Commitid_pixelsz ? $Commitid_pixelsz : 0.4) * + ($Commitid_scale ? $Commitid_scale : 1.0); +function Commitid_depth() = + ($Commitid_depth ? $Commitid_depth : Commitid_pixelsz()) * + ($Commitid_depth_scale ? $Commitid_depth_scale : 1.0); +function Commitid__scale() = + Commitid_pixelsz() / 0.1; +END + +sub chrmodname ($) { + my ($chr) = @_; + my $chrx = sprintf '%#x', ord $chr; + return "Commitid__chr_$chrx"; +} + sub parsefont () { my %cellmap; - while () { + for (;;) { + $_ = // die; last if %cellmap && !m/\S/; next unless m/\S/; chomp; @@ -46,18 +91,20 @@ sub parsefont () { my %chrpolys; while () { next unless m/\S/; + chomp; my @chrs = split / /, $_; !~ m/\S/ or die; - foreach my $row (0..4) { + foreach my $row (reverse 0..4) { $_ = ; chomp; s{^}{ }; - $_ .= ' ' x (@chrs * 4); + $_ .= ' ' x 8; m{\S/\S} and die; s{/(?=\s)}{L}g; s{/(?=\S)}{r}g; s{\\(?=\s)}{l}g; s{\\(?=\S)}{R}g; + p "// $_\n"; foreach my $chr (@chrs) { s{^ }{} or die "$chr $_ ?"; foreach my $col (0..2) { @@ -66,8 +113,8 @@ sub parsefont () { } elsif (s{^\S}{}) { my $f = $cellmap{$&}; die unless $f; - $f =~ s/\b\d/ sprintf '%x', $col*2 + $& /ge; - $f =~ s/\d\b/ sprintf '%x', $row*2 + $& /ge; + $f =~ s/\b\d/ sprintf '%05d', $col*2000 + $&*1025 /ge; + $f =~ s/\d\b/ sprintf '%05d', $row*2000 + $&*1025 /ge; push @{ $chrpolys{$chr} }, [ split / /, $f ]; } else { die "$_ ?"; @@ -77,45 +124,47 @@ sub parsefont () { die "$_ ?" if m{\S}; } } - foreach my $polys (values %chrpolys) { - my %edges; - foreach my $p (@$polys) { - foreach my $ei (0..$#$p) { - my $e = $p->[$ei].$p->[($ei+1) % @$p]; - die if $edges{$e}; - $edges{$e} = [ $p, $ei ]; - } - } - AGAIN: { - foreach my $pa (@$polys) { - foreach my $eai (0..$#$pa) { - my $ear = $pa->[ ($eai+1) % @$pa ].$pa->[$eai]; - my $ebi = $edges{$ear}; - next unless $ebi; - my $pb; - ($pb, $ebi) = @$ebi; -# print "# merging $eai $ebi\n"; - splice @$pb, $ebi, 1; - splice @$pa, $eai, 1, @$pb; - @$pb = ( ); - next AGAIN; - } + + my @demo; + my $democols = 6; + foreach my $chr (sort keys %chrpolys) { + my $mod = chrmodname $chr; + p "module $mod () {\n"; + foreach my $poly (@{ $chrpolys{$chr} }) { + p " polygon(["; + my $delim = ""; + foreach my $pt (@$poly) { + p $delim; + $pt =~ s{\d{5}}{$&,}; + $pt =~ s{\b\d}{$&.}g; + p "[$pt]"; + $delim = ','; } + p "]);\n"; } -# @$polys = grep { @$_ } @$polys; + p "}\n"; + my $px = @demo % $democols; + my $py = int(@demo / $democols); + push @demo, " scale( Commitid__scale() ) translate([$px * 0.800, $py * 1.200]) + $mod ();\n"; } - - use Data::Dumper; - print Dumper(\%chrpolys); + p "module Commitid_FontDemo(){\n"; + p $_ foreach @demo; + p "}\n"; + +# use Data::Dumper; +# print Dumper(\%chrpolys); } parsefont(); +#p "Commitid_FontDemo();\n"; + __DATA__ # 00 20 22 02 -l 00 20 22 -r 00 20 02 +l 00 20 02 +r 00 20 22 L 00 22 02 R 20 22 02 > 00 20 22 02 11 @@ -123,17 +172,17 @@ R 20 22 02 0 1 2 3 4 5 6 7 8 9 -/#\ # ##\ ##\ # # ### /## ### /#\ /#\ -# # # # # # # # # # # # # # -# # # /#/ ### ### ##\ ##\ // >#< \## +/#\ r /#\ ##\ # # ### // ### /#\ /#\ +# # /# # # # # # # # # # # # +# # # /#/ ##< \## ##\ ##\ // >#< \## # # # # # # # # # # # # # -\#/ # ### ##/ # ##/ \#/ # \#/ ##/ +\#/ /#\ ### ##/ # ##/ \#/ # \#/ ##/ a b c d e f # # /## -/## ##\ /## /## /## # -# # # # # # # # # ### + # /## # /#\ # +/## ##\ # /## #r# ### # # # # # # # #/ # -\## ##/ \## \## ### # +\## ##/ \## \## \#/ #