User:3247's Image Wizard/Scripts/7segment.pl

From Wikimedia Commons, the free media repository
Jump to: navigation, search
 #!/usr/bin/perl
 #
 # 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.
 #
   @colours = (
   'black',
   'red',
   'green',
   'blue',
   'yellow',
   'white',
 );  
 
 %colour_map = (
   'green' => '#00CC00',
   'blue' => '#0000CC',
 );
 
 open FILES, ">files.txt";
 my $nr = 0;
 
 foreach my $colour_name (@colours) 
 {
   my $colour = $colour_map{$colour_name} || $colour_name;
   $nr++;
        
   for ($digit = 0; $digit < 10; ++$digit) 
   {
     my $file = "seven segment display $digit digit ($colour_name).svg";
     open SVG, ">$file";
 
     print FILES ">$file\n";
     print FILES "{{English}} seven segment display - digit $digit ($colour_name)\n";
     print FILES "Created by [[User:3247|3247]] using [[User:3247/7segment.pl|7segment.pl]].\n{{PD-self}}\n";
     printf FILES "[[Category:seven segment display|%01d%s_%s]]\n\n", $digit, chr($nr+ord('@')), $colour_name;
          
     print SVG "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
     print SVG "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"320\" height=\"600\">\n";
     print SVG "<path fill=\"$colour\" d=\"M22 19.5L42 0L278 0L298 19.5L278 39L42 39Z\" />\n"                       if grep { $_ == $digit } (0,2,3,5,6,7,8,9);
     print SVG "<path fill=\"$colour\" d=\"M22 299.5L42 280L278 280L298 299.5L278 319L42 319Z\" />\n"               if grep { $_ == $digit } (2,3,4,5,6,8,9);
     print SVG "<path fill=\"$colour\" d=\"M22 579.5L42 560L278 560L298 579.5L278 599L42 599Z\" />\n"               if grep { $_ == $digit } (0,2,3,5,6,8,9);
     print SVG "<path fill=\"$colour\" d=\"M 19.5 22L0 42L0 277.5L19.5 297.5L39 277.5L39 42Z\" />\n"                if grep { $_ == $digit } (0,4,5,6,7,8,9);
     print SVG "<path fill=\"$colour\" d=\"M299.5 22L280 42L280 277.5L299.5 297.5L319 277.5L319 42Z\" />\n" if grep { $_ == $digit } (0,1,2,3,4,7,8,9);
     print SVG "<path fill=\"$colour\" d=\"M 19.5 302L0 322L0 557.5L19.5 577.5L39 557.5L39 322Z\" />\n"             if grep { $_ == $digit } (0,2,6,8);
     print SVG "<path fill=\"$colour\" d=\"M299.5 302L280 322L280 557.5L299.5 577.5L319 557.5L319 322Z\" />\n"      if grep { $_ == $digit } (0,1,3,4,5,6,7,8,9);
     print SVG "</svg>\n";
   }
 }