]> mj.ucw.cz Git - misc.git/commitdiff
Digit: Kreslitko
authorMartin Mares <mj@ucw.cz>
Thu, 1 Sep 2011 10:29:45 +0000 (12:29 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 1 Sep 2011 10:29:45 +0000 (12:29 +0200)
ucw/digit.c
ucw/draw-digit [new file with mode: 0755]

index 17267c2a57cfdb746bd5f8fbf70af959e3015b2d..6331782901ba67e8ef6a0fc9103926075941adc0 100644 (file)
@@ -38,6 +38,21 @@ static void print(conf c)
   // putchar('\n');
 }
 
   // putchar('\n');
 }
 
+static void print_matches(conf c)
+{
+  printf("@@");
+  for (int i=0; i<SIZE; i++)
+    for (int j=1-i%2; j<SIZE; j+=2)
+      if (c[i][j])
+       {
+         if (i%2)
+           printf(" (%d,%d)-(%d,%d)", i/2, j/2, i/2+1, j/2);
+         else
+           printf(" (%d,%d)-(%d,%d)", i/2, j/2, i/2, j/2+1);
+       }
+  putchar('\n');
+}
+
 static void norm(conf from, conf to)
 {
   int ii=SIZE, jj=SIZE;
 static void norm(conf from, conf to)
 {
   int ii=SIZE, jj=SIZE;
@@ -191,7 +206,9 @@ static void generate(void)
                  to[i][j] = 0;
                }
        }
                  to[i][j] = 0;
                }
        }
-      printf("Degree: %d in, %d out, from=%d\n\n", s->indegree, s->outdegree, s->from);
+      printf("Degree: %d in, %d out, from=%d\n", s->indegree, s->outdegree, s->from);
+      print_matches(s->c);
+      putchar('\n');
     }
 }
 
     }
 }
 
diff --git a/ucw/draw-digit b/ucw/draw-digit
new file mode 100755 (executable)
index 0000000..6dbc4a0
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Cairo;
+
+my $u = 72/4;
+my $s = Cairo::PdfSurface->create('digit.pdf', 7*$u, 7*$u);
+my $c = Cairo::Context->create($s);
+my $n = 0;
+
+$c->set_line_width(2);
+$c->set_line_cap('round');
+$c->set_source_rgb(0, 0, 0);
+
+while (<>) {
+       s/^@@ // or next;
+       chomp;
+       my @r = split /\s+/;
+       @r == 5 or next;
+
+       for my $r (@r) {
+               my ($x1,$y1,$x2,$y2) = $r =~ /^\((\d+),(\d+)\)-\((\d+),(\d+)\)$/ or die;
+               $c->move_to((.9*$x1+.1*$x2)*$u, (.9*$y1+.1*$y2)*$u);
+               $c->line_to((.9*$x2+.1*$x1)*$u, (.9*$y2+.1*$y1)*$u);
+               $c->stroke;
+       }
+
+       $c->show_page;
+       $n++;
+}
+
+print "Output $n pages.\n";