Wolfram Research

PlayingCardGraphic

Contributed by: Jon McLoone

Source Notebook

Create graphic displaying standard playing cards

ResourceFunction["PlayingCardGraphic"][n]

displays the nth card in a standard deck of playing cards and where 0 represents a card which is face down.

ResourceFunction["PlayingCardGraphic"][n,suit]

displays the nth card in a specific suit where “♠”, “♡”, “♢”, “♣” represent the standard playing card suits.

ResourceFunction["PlayingCardGraphic"][{card1,card2,,cardn}]

displays a hand of playing cards where each card is represented as a number from 0 to 52 or as a list of the form {n,suit}.

Examples

Basic Examples

Display a playing card:

In[1]:=
ResourceFunction["PlayingCardGraphic"][1]
Out[1]=

Scope

Display several cards together:

In[2]:=
Rasterize@ResourceFunction["PlayingCardGraphic"][{1, 10, 11, 12, 13}]
Out[2]=

Display a card with a custom suit symbol:

In[3]:=
ResourceFunction["PlayingCardGraphic"][7, Graphics[{Red, Disk[]}]]
Out[3]=

Display a card face-down:

In[4]:=
ResourceFunction["PlayingCardGraphic"][0]
Out[4]=

Options

“CardColor” controls the color of the playing card:

In[5]:=
Rasterize@
 ResourceFunction["PlayingCardGraphic"][{1, 10, 11, 12, 13}, "CardColor" -> Lighter[Yellow]]
Out[5]=

FontFamily, FontColor and FontSize control the corner labels:

In[6]:=
Rasterize@
 ResourceFunction["PlayingCardGraphic"][{1, 10, 11, 12, 13}, FontColor -> Green, FontSize -> Scaled[0.2], FontFamily -> "Times"]
Out[6]=

RoundingRadius controls the card shape:

In[7]:=
Rasterize@
 ResourceFunction["PlayingCardGraphic"][{1, 10, 11, 12, 13}, RoundingRadius -> 0]
Out[7]=

“CardSpreadAngle” controls the amount of curvature in a hand:

In[8]:=
Rasterize@
 ResourceFunction["PlayingCardGraphic"][{1, 10, 11, 12, 13}, "CardSpreadAngle" -> 0.1]
Out[9]=

“CardOffset” controls how each card in a hand is separated from the next:

In[10]:=
Rasterize@
 ResourceFunction["PlayingCardGraphic"][{1, 10, 11, 12, 13}, "CardOffset" -> {0, 0}]
Out[10]=
In[11]:=
Rasterize@
 ResourceFunction["PlayingCardGraphic"][{1, 10, 11, 12, 13}, "CardOffset" -> {0.3, 0.3}, "CardSpreadAngle" -> 0]
Out[11]=
In[12]:=
Rasterize@
 ResourceFunction["PlayingCardGraphic"][{1, 10, 11, 12, 13}, "CardOffset" -> {0, -0.3}, "CardSpreadAngle" -> 0]
Out[12]=

Applications

Deal a random poker hand:

In[13]:=
Rasterize@
 ResourceFunction["PlayingCardGraphic"][
  Sort[RandomSample[Range[52], 5]]]
Out[13]=

Resource History