S'identifier - S'inscrire - Contact

CommunityWiki
Jam session in wikilandia

old-school-hex.pl

Source :

#!/usr/bin/perl # data goes where the first empty line is $doc = q{<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 1600 1200" xmlns:xlink="http://www.w3.org/1999/xlink"> <desc>Old School Hex Map</desc> <defs> <polygon fill="none" stroke="black" stroke-width="1" id="empty" title="empty" points="0,50 0,150 86.6,200 173.2,150 173.2,50 86.6,0" /> <g id="grass" title="grass"> <use xlink:href="#empty" /> <path d="M 66.703995,86.605057 C 71.368579,94.022991 71.631096,105.2659 76.582428,112.64703 C 73.327772,115.31728 70.073115,122.11355 66.818459,126.84682 C 64.780376,117.76193 62.508957,105.09879 56.497963,101.22669 C 58.943112,96.408453 63.343876,91.229859 66.703995,86.605057 z " /> <path d="M 90.757301,68.787796 C 89.459656,80.54745 88.976531,94.312796 91.408322,106.4201 C 86.668674,110.61514 84.876184,115.39962 81.610115,119.88938 C 82.242675,107.25477 81.964916,95.739677 80.453026,83.759868 C 80.931325,78.610948 87.616802,74.400108 90.757301,68.787796 z " /> <path d="M 112.11098,99.247017 C 101.14287,106.99923 104.20963,105.79044 94.713402,118.55906 C 98.032942,103.9313 107.0408,91.516225 119.27269,83.113624 C 117.22268,88.380805 114.49987,93.966887 112.11098,99.247017 z " /> </g> </defs>

</svg> };

# Example data: # <use x="0" y="0" xlink:href="#empty" /> # <use x="173.2" y="0" xlink:href="#grass" /> # <use x="86.6" y="150" xlink:href="#empty" />

%char = ( '"' => 'grass', '.' => 'empty', );

# Example input: # " " " " # " " . # " " . . # " " .

$y = 0; while (<STDIN>) { for ($i=0; $i < length($_)/2; $i++) { $type = $char{substr($_, $i * 2 + $y % 2, 1)}; if ($type) { $data .= sprintf(qq{ <use x="%.1f" y="%.1f" xlink:href="#%s" />\n}, (2 * $i + $y % 2) / 2 * 173.2, $y * 150, $type); } } $y++; } $doc =~ s/\n\n/\n$data/; print $doc;

le 02.06.07 à 20:29 dans Mind - Version imprimable
Article précédent - Commenter - Article suivant -