From: Ian Jackson Date: Thu, 4 Feb 2016 19:31:30 +0000 (+0000) Subject: commitid.scad.pl: more wip X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=commitdiff_plain;h=23fa78caadadc497688db91a01f1c2348eb46f30 commitid.scad.pl: more wip --- diff --git a/commitid.scad.pl b/commitid.scad.pl index 72ab714..a6ef9a5 100755 --- a/commitid.scad.pl +++ b/commitid.scad.pl @@ -3,9 +3,24 @@ 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 a scaling factor +# +# $Commitid_pixelsz = 0.4; +# $Commitid_depth = 1.5; // in pixels +# +# For each form we have +# +# module Commitid_Form_2D(pixelsz=0.4) +# module Commitid_Form(pixelsz=0.4, depth=pixelsz) +# +# function Commitid_Form_size(pixelsz=$Commitid_pixelsz) => [ xsz, ysz ] +# +# +# We can generate these forms: # # Tiny3: # Tiny4: @@ -25,6 +40,13 @@ $SIG{__WARN__} = sub { die @_; }; # Tiny4Q 10 # 70 # +# Git4 +# Git6 +# Git8 +# git-rev-parse HEAD +# eg +# Git6 82f2a2 + # Small4 # Small6 # Small8 @@ -34,9 +56,12 @@ $SIG{__WARN__} = sub { die @_; }; # Small6 1070 # 82f2a2 +sub p { print @_ or die $!; } + sub parsefont () { my %cellmap; - while () { + for (;;) { + $_ = // die; last if %cellmap && !m/\S/; next unless m/\S/; chomp; @@ -48,16 +73,17 @@ sub parsefont () { next unless m/\S/; 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 +92,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*4000 + $&*2001 /ge; + $f =~ s/\d\b/ sprintf '%05d', $row*4000 + $&*2001 /ge; push @{ $chrpolys{$chr} }, [ split / /, $f ]; } else { die "$_ ?"; @@ -77,18 +103,47 @@ sub parsefont () { die "$_ ?" if m{\S}; } } - - use Data::Dumper; - print Dumper(\%chrpolys); + + my @demo; + my $democols = 6; + foreach my $chr (sort keys %chrpolys) { + my $chrx = sprintf '%#x', ord $chr; + my $mod = "Commitid__chr_$chrx"; + 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"; + } + p "}\n"; + my $px = @demo % $democols; + my $py = int(@demo / $democols); + push @demo, " translate([$px * 1.600, $py * 2.400]) $mod ();\n"; + } + 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 @@ -96,17 +151,17 @@ R 20 22 02 0 1 2 3 4 5 6 7 8 9 -/#\ # ##\ ##\ # # ### /## ### /#\ /#\ -# # # # # # # # # # # # # # -# # # /#/ ### ### ##\ ##\ // >#< \## +/#\ r /#\ ##\ # # ### // ### /#\ /#\ +# # /# # # # # # # # # # # # +#r# # /#/ ##< \## ##\ ##\ // >#< \## # # # # # # # # # # # # # -\#/ # ### ##/ # ##/ \#/ # \#/ ##/ +\#/ /#\ ### ##/ # ##/ \#/ # \#/ ##/ a b c d e f # # /## -/## ##\ /## /## /## # -# # # # # # # # # ### +/## ##\ /## /## /#\ # +# # # # # # # #r/ ### # # # # # # # #/ # -\## ##/ \## \## ### # +\## ##/ \## \## \#/ #