X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=commitid.scad.pl;h=863e04df260bf780ced52115f9b350d764c4a0df;hb=ac3a8531acd97d6c0f6a71059a6f304e986d68ca;hp=72ab7144ba3480bd6cd5a87346a9c67584797b9f;hpb=c6f6c39f218a0d9b64d0c82c61fa3fa11bd0b0df;p=reprap-play.git diff --git a/commitid.scad.pl b/commitid.scad.pl index 72ab714..863e04d 100755 --- a/commitid.scad.pl +++ b/commitid.scad.pl @@ -3,9 +3,32 @@ 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.8 } multiplied +# $Commitid_scale if not set, we use 1.0 } together +# $Commitid_depth if not set, we use xy pixel size from above / 2 +# $Commitid_depth_scale if not set, we use 1.0 (multiplies depth above) +# +# For each form we have +# +# module Commitid_Form_2D() { ... } +# module Commitid_Form() { ... } +# function Commitid_Form_sz() => [ x, y ] +# +# These have their origin in the bottom left corner. The 3D model +# is a positive, has its origin halfway through, and is twice the +# depth in height, so it can be added or subtracted. +# +# And we provide +# +# function Commitid_pixelsz() // $Commitid_pixelsz * $Commitid_scale +# function Commitid_depth() // see above +# +# We can generate these forms: # # Tiny3: # Tiny4: @@ -15,6 +38,7 @@ $SIG{__WARN__} = sub { die @_; }; # Tiny8: # git rev-list --first-parent --count HEAD # typically 3-4 characters but we allow for up to 6 +# padded with zeroes; if too long we reduce mod 10^n # eg # Tiny4 1070 # @@ -25,6 +49,13 @@ $SIG{__WARN__} = sub { die @_; }; # Tiny4Q 10 # 70 # +# Git4 Git4Q +# Git6 Git6Q +# Git8 Git8Q +# git-rev-parse HEAD (prefix of requested length) +# eg +# Git6 82f2a2 + # Small4 # Small6 # Small8 @@ -34,9 +65,61 @@ $SIG{__WARN__} = sub { die @_; }; # Small6 1070 # 82f2a2 +sub p { print @_ or die $!; } + +p <<'END'; +// *** AUTOGENERATED - DO NOT EDIT *** // +function Commitid_pixelsz() = + ($Commitid_pixelsz ? $Commitid_pixelsz : 0.8) * + ($Commitid_scale ? $Commitid_scale : 1.0); +function Commitid_depth() = + ($Commitid_depth ? $Commitid_depth : Commitid_pixelsz()/2) * + ($Commitid_depth_scale ? $Commitid_depth_scale : 1.0); +function Commitid__scale() = + Commitid_pixelsz() / 0.2; +END + +sub chrmodname ($) { + my ($chr) = @_; + my $chrx = sprintf '%#x', ord $chr; + return "Commitid__chr_$chrx"; +} + +sub gentextmodule ($@) { + my ($form, @lines) = @_; + my $modb = "Commitid_$form"; + p "module ${modb}_2D(){\n"; + p " // |$_|\n" foreach @lines; + p " scale(Commitid__scale()){\n"; + my $y = @lines; + my $cols = 1; + foreach my $line (@lines) { + $y--; + my $x = 0; + foreach my $chr (split //, $line) { + next if $chr !~ m/\S/; + p sprintf " translate([%d * 0.8, %d * 1.2]) %s();\n", + $x, $y, chrmodname $chr; + $x++; + } + $cols = $x if $x > $cols; + } + p " }\n"; + p "}\n"; + p "module ${modb}(){\n"; + p " d=Commitid_depth();\n"; + p " translate([0,0,-d]) linear_extrude(height=d*2) ${modb}_2D();\n"; + p "}\n"; + p sprintf "function %s_sz() = Commitid__scale() * 0.1 * [ %d, %d ];\n", + $modb, 2 * ($cols * 4 - 1), 2 * (@lines * 6 - 1); +} + +our @demo; + sub parsefont () { my %cellmap; - while () { + for (;;) { + $_ = // die; last if %cellmap && !m/\S/; next unless m/\S/; chomp; @@ -46,18 +129,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 +151,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,18 +162,42 @@ sub parsefont () { die "$_ ?" if m{\S}; } } - - use Data::Dumper; - print Dumper(\%chrpolys); + + 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"; + } + p "}\n"; + $demo .= $chr; + } + @demo = reverse $demo =~ m{.{1,$democols}}go; } parsefont(); +gentextmodule('FontDemo', @demo); + +flush STDOUT or die $!; +close STDOUT or die $!; + __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 +205,24 @@ R 20 22 02 0 1 2 3 4 5 6 7 8 9 -/#\ # ##\ ##\ # # ### /## ### /#\ /#\ -# # # # # # # # # # # # # # -# # # /#/ ### ### ##\ ##\ // >#< \## +/#\ r /#\ ##\ # # ### // ### /#\ /#\ +# # /# # # # # # # # # # # # +# # # /#/ ##< \## ##\ ##\ // >#< \## # # # # # # # # # # # # # -\#/ # ### ##/ # ##/ \#/ # \#/ ##/ +\#/ /#\ ### ##/ # ##/ \#/ # \#/ ##/ a b c d e f # # /## -/## ##\ /## /## /## # -# # # # # # # # # ### + # /## # /#\ # +/## ##\ # /## #r# ### # # # # # # # #/ # -\## ##/ \## \## ### # +\## ##/ \## \## \#/ # + ++ * + r + # ### +### # + # ### + L