User:3247's Image Wizard/Scripts/braille8.pl

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
 #!/usr/bin/perl
 #
 # braille.pl - Create Braille 8 symbols
 # Copyright (C) 2005 Claus Faerber <claus@faerber.name>
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by the
 # Free Software Foundation; either version 2 of the License, or (at your
 # option) any later version.
 # 
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 # Public License for more details.
 # 
 # You should have received a copy of the GNU General Public License along
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 # As a special exception, permission is granted to include the source code
 # of this program into a document and copy, distribute and/or modify that
 # document under the terms of the GNU Free Documentation License, Version
 # 1.2 or any later version published by the Free Software Foundation; with
 # no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. 
 #
 # If you write modifications of your own for this software, it is your
 # choice whether to permit this exception to apply to your modifications.
 # If you do not wish that, delete this exception notice.
 #
 
 my $x = 154;
 my $y = 275;
 my $r = 15;
 my $str = 1;
 
 open FILES, ">files.txt";
 
 my @map = ( 1, 4, 2, 5, 3, 6, 7, 8 );
 
 for ($j = 0; $j <= 255; $j++) {
   my $n = (join '', map { $map[$_] } grep { $j & (2**($_)) } ( 0, 1, 2, 3, 4, 5, 6, 7, ));
   $n = $n ? "Dots-$n" : "Blank";
   open STDOUT, ">Braille8_$n.svg";
 
   printf FILES ">Braille8_$n.svg\n";
   printf FILES "{{English}} 8 dot Braille letter/symbol %s (Unicode U+28%02X).\n\nCreated by [[User:3247|]] using [[User:3247/braille8.pl|braille8.pl]].\n\n{{PD-self}}\n", $n, $j;
   printf FILES "[[Category: Braille letters (8 dots)|Braille_%08b]]\n", $j;
 
   print "<?xml version=\"1.0\" standalone=\"no\"?>\n";
   print "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
   printf "<svg width=\"%d\" height=\"%d\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", $x, $y;
   printf "<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"white\" stroke-width=\"1\" stroke=\"black\" />\n", $x, $y;
 
   for( $i=0; $i<8; $i++ )
   {
     my $xp = ($i % 2);
     my $yp = int($i/2);
 
     printf "<circle cx=\"%f\" cy=\"%f\"",
       ($x-4*$r)/3 * (1+$xp) + (2*$xp+1)*$r,
       ($y-8*$r)/5 * (1+$yp) + (2*$yp+1)*$r;
 
     if( $j & (2**$i) )
     {
       printf " r=\"%f\"", $r;
       printf " fill=\"black\"";
     } else {
       printf " r=\"%f\"", $r-$str/2;
       printf " stroke=\"black\" stroke-width=\"%d\" fill=\"none\"", $str;
     }
     print " />\n";
   }
   print "</svg>";
 };