Playing Cards

card[{suit_,val_},list_]:=Graphics[Locator[If[list,{Position[cardlist,{suit,val}][[1,2]]*1.14,-Position[cardlist,{suit,val}][[1,1]]*2},{1.15,0.1}],Graphics[{{White,EdgeForm[Black],Rectangle[{-0.5,-0.75},{0.5,0.75}]},{Inset[Style[Column[{ToString[val],Style[ToString[suit],30]},Spacings->0,Alignment->Center],24,Bold,Switch[suit,♡,Darker[Red,0.2],♢,Darker[Red,0.2],♣,Black,♠,Black],"Label",18],{0,-0.1}]}},ImageSize->35],ImageSize->50]];

valuelist=Flatten[Map[({{♡,#},{♣,#},{♢,#},{♠,#}})&,Join[Table[i,{i,2,10}],{J,Q,K,A}]],1];

Manipulate[SeedRandom[seed];
Deploy[

drawlist={};
newcardlist={};
nc=1;

cardlist=If[numbertodeal==0,{},Partition[RandomSample[valuelist,numbertodeal*numberofhands],numbertodeal]];
unusedcards=If[numbertodeal==0,RandomSample[valuelist],If[numbertodeal*numberofhands==52,{},RandomSample[Complement[valuelist,Flatten[cardlist,1]]]]];

Show[
If[numbertodeal==0,{},
MapAt[(card[#,True])&,cardlist,Evaluate[Flatten[Table[{i,j},{i,1,numberofhands},{j,1,numbertodeal}],1]]]],

Map[(card[#,False])&,unusedcards],

Graphics[Raster[Partition[Flatten[Table[{{0,0,1},{1,1,1}},{40}],1],7],{{0.75,-0.55},{1.55,0.75}}]],
Background->Darker[Green,0.6],Frame->True,FrameTicks->None,PlotRange->{{0,16},{-10,1.2}},FrameStyle->{Thickness[0.01],Darker[Brown,0.6]},ImageSize->510]
],
{{numbertodeal,1,"number to deal"},{0,1,2,3,4,5,10,13}},
{{numberofhands,1,"number of hands"},{1,2,3,4}},{{seed,1},ControlType->None},
Button["deal again",seed=RandomInteger[{1,10000}],ImageSize->{100,30}],
Delimiter,"click and drag the edge of the stack to draw a new card",
TrackedSymbols:>{deal,numbertodeal,numberofhands,seed},SaveDefinitions->True,AutorunSequencing->{1,2}
]

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Playing Cards" from The Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/PlayingCards/

Contributed by: Abby Brown

A full-function Wolfram Mathematica 6 system is required to edit this notebook.
GET WOLFRAM MATHEMATICA 6 »

© The Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »