#!/usr/bin/perl # # This script generates an SVG card deck suitable for KDE # card games. # Currently developed to generate a deck for lskat from a public domain image. # my $year = 2009; my $author = "Luciano Montanaro "; # Width and height of the card board my $boardwidth = 1024; my $boardheight = 804; # Width and height of each card my $width = 128; my $height = 201; # corner radius my $cradius = 7; # offset from card border to pattern border my $xoff = 5; my $yoff = 6; # width and height of card figure my $figwidth = $width - 2 * $xoff; my $figheight = $height - 2 * $yoff; # The source image my $image = $ARGV[0]; my @suits = ("heart", "diamond", "spade", "club"); # A Skat deck only has cards down to 7. The Ace is really the Queen, King is # itself, queen is high knave, jack is low knave. I guess. my @cardnames = ("1", "king", "queen", "jack", "10", "9", "8", "7"); my $viewwidth = @cardnames * $width; my $viewheight = (1 + @suits) * $height; my $ratiox = 1; my $ratioy = 1; print < EOF # generate all patterns: for each suit and each card name generate a pattern # based on the card board. for ($j = 0; $j < @suits; $j++) { for ($i = 0; $i < @cardnames; $i++) { my $cardid = "$suits[$j]_$cardnames[$i]"; my $x = $i * $width + $xoff; my $y = $j * $height + $yoff; print "\n"; print "patternTransform=\"translate(-$x,-$y)\"/>\n"; } } print < EOF # generate all cards: for each suit and each card name generate a card for ($j = 0; $j < @suits; $j++) { print "\n"; for ($i = 0; $i < @cardnames; $i++) { my $cardid = "$suits[$j]_$cardnames[$i]"; print < EOF } } print < EOF # generate all suits (not strictly needed, but nice to see the cards when # loading the deck in an editor) for ($j = 0; $j < @suits; $j++) { print "\n"; for ($i = 0; $i < @cardnames; $i++) { my $cardid = "$suits[$j]_$cardnames[$i]"; my $x = $width * $i; print < EOF } print "\n"; } my $boff = 4; my $b2off = 6; my $bwidth = $width - 2 * $boff; my $bheight = $height - 2 * $boff; my $bradius = $cradius - $boff; my $b2width = $width - 2 * $b2off; my $b2height = $height - 2 * $b2off; my $b2radius = $cradius - $b2off; my $cx = $width / 2; my $cy = $height / 2; print < EOF # generate suits for display for ($j = 0; $j < @suits; $j++) { my $y = (0 + $height) * $j; print < EOF } my $y = $height * (@suits); print < EOF