Function Repository Resource:

PlayingCardGraphic

Source Notebook

Create graphic displaying standard playing cards

Contributed by: Jon McLoone

ResourceFunction["PlayingCardGraphic"][n]

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

ResourceFunction["PlayingCardGraphic"][n,suit]

displays the nth card in a specific suit where "♠", "♡", "♢" and "♣" 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 (1) 

Display a playing card:

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

Scope (3) 

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 (5) 

"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[8]=

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

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

Applications (1) 

Deal a random poker hand:

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

Publisher

Jon McLoone

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 15 February 2019

License Information