User:3247's Image Wizard/Scripts/fiav dots.pl

 #!/usr/bin/perl
 #
 # fiav_dots.pl - Create FIAV symbols
 # Copyright (C) 2006 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 $c = 3; my $r = 2; 
 my $w = 10; my $z = 100;
 
 my $cx = $c * $z + ($c-1) * $w;
 my $cy = $r * $z + ($r-1) * $w;
 
 open FILES, ">files.txt";
 
 @names = (
   'No attributes selected',
   'War ensign',
   'State ensign',
   'State and war ensign',
   'Civil ensign',
   'Civil ensign and war flag',
   'Civil and state ensign',
   'National ensign',
   'War flag',
   'War flag and ensign',
   'War flag and state ensign',
   'War flag and state and war ensign',
   'War flag and civil ensign',
   'War flag and civil and war ensign',
   'War flag and civil and state ensign',
   'War flag and national ensign',
   'State flag',
   'State flag and war ensign',
   'State flag and ensign',
   'State flag and state and war ensign',
   'State flag and civil ensign',
   'State flag and civil and war ensign',
   'State flag and state/civil ensign',
   'State flag and national ensign',
   'State and war flag',
   'State flag and war flag and ensign',
   'State flag and ensign and war flag',
   'State/War flag and ensign',
   'State/War flag and civil ensign',
   'State/War flag and civil and war ensign',
   'State and war flag, civil and state ensign',
   'State and war flag and national ensign',
   'Civil flag',
   'Civil flag/war ensign',
   'Civil flag and state ensign',
   'Civil flag, state and war ensign',
   'Civil flag and ensign',
   'Civil flag/ensign and war ensign',
   'Civil flag and ensign, state ensign',
   'Civil flag and national ensign',
   'Civil and war flag',
   'Civil flag and war flag and ensign',
   'Civil and war flag and state ensign',
   'Civil and war flag, state and war ensign',
   'Civil and war flag and civil ensign',
   'Civil and war flags and ensigns',
   'Civil and war flag and civil and state ensign',
   'Civil and war flag and national ensign',
   'Civil and state flag',
   'Civil and state flag and war ensign',
   'Civil/State flag and state ensign',
   'Civil and state flag, state and war ensign',
   'Civil and state flag and civil ensign',
   'Civil and state flag, civil and war ensign',
   'Civil and state flags and ensigns',
   'Civil and state flag and national ensign',
   'National flag on land',
   'National flag and war ensign',
   'National flag and state ensign',
   'National flag, state and war ensign',
   'National flag and civil ensign',
   'National flag and civil and war ensign',
   'National flag and civil and state ensign',
   'National flag and ensign', );
 
 for(my $x=0;$x < (1<<($c*$r)); $x++)
 {
   my $fn = sprintf "FIAV_%06b.svg",$x;
 
   print STDERR "$fn\n" unless -f $fn;
   open STDOUT, ">$fn";
 
   print FILES ">$fn\n";
   print FILES "* Vexillological Symbol according to FIAV / W. Smith: ", $names[$x], "\n";
 
   print FILES ":* [[Image:FIAV_000001.svg|23px]] military sea use\n" if $x & 1;
   print FILES ":* [[Image:FIAV_001000.svg|23px]] military land use\n" if $x & 8;
   print FILES ":* [[Image:FIAV_000010.svg|23px]] public sea use\n" if $x & 2;
   print FILES ":* [[Image:FIAV_010000.svg|23px]] public land use\n" if $x & 16;
   print FILES ":* [[Image:FIAV_000100.svg|23px]] private sea use\n" if $x & 4;
   print FILES ":* [[Image:FIAV_100000.svg|23px]] private land use\n" if $x & 32;
 
   print FILES "* Generated by [[User:3247|]] using [[User:3247's Image Wizard/Scripts/fiav_dots.pl|fiav_dots.pl]]\n";
   print FILES "\n{{PD-ineligible}}\n";
   print FILES "[[Category:Vexillological Symbols]]\n";
 
   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";
   print "<svg width=\"$cx\" height=\"$cy\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
   
   for (my $yy=1; $yy < $r; $yy++) { print "<rect x=\"0\" y=\"".($yy*$z+($yy-1)*$w)."\" width=\"$cx\" height=\"$w\" fill=\"black\" />\n"; }
   for (my $xx=1; $xx < $c; $xx++) { print "<rect y=\"0\" x=\"".($xx*$z+($xx-1)*$w)."\" width=\"$w\" height=\"$cy\" fill=\"black\" />\n"; }
 
   for( $i=0; $i<$c*$r; $i++ )
   {
     my $xp = $c - ($i % $c) - 1;
     my $yp = $r - int($i/$c) - 1;
 
     if((1 << $i) & $x)  
     {
       printf "<circle cx=\"%d\" cy=\"%d\"",
         ($xp + .5) * $z + $xp * $w,
 	($yp + .5) * $z + $yp * $w;
       printf " r=\"%f\"", 100.0/3,
       printf " fill=\"black\"";
       print " />\n";
     }
   }
   print "</svg>";
 };