File indexing completed on 2024-12-22 03:52:53
0001 #!/usr/bin/perl 0002 # 0003 # This script generates an SVG card deck suitable for KDE 0004 # card games. 0005 # Based on the xskat deck. 0006 # 0007 0008 use MIME::Base64; 0009 0010 my $year = 2009; 0011 my $author = "Luciano Montanaro <mikelima@cirulla.net>"; 0012 0013 # Width and height of the card board 0014 my $boardwidth = 1024; 0015 my $boardheight = 804; 0016 0017 # Width and height of each card 0018 my $width = 144; 0019 my $height = 224; 0020 0021 # corner radius 0022 my $cradius = 9; 0023 0024 # offset from card border to pattern border 0025 my $off = 6; 0026 0027 my $xoff1 = 2 * $off; 0028 my $yoff = $off * 5; 0029 my $ioff = $off * 2.5; 0030 my $xoff2 = $width - $xoff1; 0031 0032 # width and height of card figure 0033 my $figwidth = $width - 2 * $off; 0034 my $figheight = $height - 2 * $off; 0035 my $figradius = $cradius - 2; 0036 0037 my $centerx = $width / 2; 0038 my $centery = $height / 2 - 1; 0039 0040 my @suits = ("heart", "diamond", "spade", "club"); 0041 0042 # A Skat deck only has cards down to 7. The Ace is really the Queen, King is 0043 # itself, queen is high knave, jack is low knave. I guess. 0044 my @cardnames = ("1", "king", "queen", "jack", "10", "9", "8", "7", "6", "5", "4", "3", "2"); 0045 0046 my $viewwidth = @cardnames * $width; 0047 my $viewheight = (1 + @suits) * $height; 0048 0049 my $ratiox = 1; 0050 my $ratioy = 1; 0051 0052 my $suitsize = 16; 0053 my $spacing = 7.4; 0054 0055 my @column = ( 0056 $centerx - 2 * ($suitsize + 3) - $off, 0057 $centerx - ($suitsize - 2) - $off, 0058 $centerx - $off, 0059 $centerx + ($suitsize - 2)- $off, 0060 $centerx + 2 * ($suitsize + 3) - $off); 0061 my @row = ( 0062 2 + $off + $spacing, 0063 2 + $off + 2 * $spacing, 0064 2 + $off + 3 * $spacing, 0065 2 + $off + 4 * $spacing, 0066 2 + $off + 5 * $spacing, 0067 2 + $off + 6 * $spacing, 0068 2 + $off + 7 * $spacing, 0069 2 + $off + 8 * $spacing, 0070 2 + $off + 9 * $spacing, 0071 2 + $off + 10 * $spacing, 0072 2 + $off + 11 * $spacing, 0073 ); 0074 0075 # Rows for "branched" suits. 0076 my $bspacing = 14; 0077 0078 my @brow = ( 0079 $off + $bspacing, 0080 $off + 2 * $bspacing, 0081 $off + 3 * $bspacing, 0082 $off + 4 * $bspacing, 0083 $off + 5 * $bspacing, 0084 $off + $figwidth / 2, 0085 ); 0086 0087 sub generate_court_images() 0088 { 0089 for ($i = 0; $i < 4; $i++) { 0090 for ($j = 1; $j < 4; $j++) { 0091 my $pngname = 1 + $j * 4 + $i; 0092 my $offsetx = $j * $width; 0093 my $offsety = $i * $height; 0094 my $cardid = "$cardnames[$j]_$suits[$i]"; 0095 open(CARD, "<images/$cardid.png"); 0096 binmode(CARD); 0097 my @card_data = <CARD>; 0098 my $card_encoded = encode_base64(join("", @card_data)); 0099 print <<EOF; 0100 <g id="img_$cardid" transform="scale(1) translate(-64,-98)" > 0101 <image width="113" height="93" xlink:href="data:image/png;base64,$card_encoded" /> 0102 </g> 0103 EOF 0104 } 0105 } 0106 } 0107 0108 sub generate_groups($$) 0109 { 0110 my $suit = shift; 0111 my $image = shift; 0112 my $delta = $row[7] - $row[2]; 0113 my $delta2 = 2 * $delta; 0114 my $deltah = $delta / 2; 0115 0116 if ($suit eq "diamond" || $suit eq "heart") { 0117 print <<EOF; 0118 <g id="g2g-$suit" transform="translate(0,-$deltah)"> 0119 <use x="0" y="$delta" xlink:href="#${image}" / > 0120 <use x="0" y="0" xlink:href="#${image}" / > 0121 </g