Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am not sure how to find out what all is included as curated data. For example, are the individual images of each of the 52 cards in a standard deck of playing cards included?

If not, is there a way to systematically access these from web images?

share
    
have you checked the help item howto/UseCuratedData? That lists the available curated data. –  PatoCriollo Dec 11 '12 at 18:15
    
I'm not sure if standard images of a deck of cards is included in the curated data, but you should be able to "Import" if you can find the images you want. –  cartonn Dec 11 '12 at 18:18
    
A google search yielded this. You would need to import it, then partition the image. –  VF1 Dec 11 '12 at 18:26
    
@DiegoZviovich: Yes, I always try to find things myself before asking. However, some of the categories/classes listed are vague, e.g., ExampleData. I hunted but could not find playing cards and thought someone might know if/where they might be hiding before trying to manually construct such a thing. –  JohnD Dec 11 '12 at 18:27

5 Answers 5

up vote 15 down vote accepted

You can get some nice vector playing cards from this site, licensed under GNU LGPL (read more here). Download this folder to your computer and then try the following:

(* replace with your download dir *)
files = Flatten@With[{dir = "~/Downloads/Chrome/mma/SVG_and_EPS_Vector_Playing_Cards_Version_1.3/EPS_Vector_Playing_Cards_Version_1.3/52-Individual-Vector-Playing-Cards-1.2_(EPS-Format)/"},
    FileNames["*.eps", dir, 2]];

Clear@CardData
SetAttributes[CardData, Listable]
StringCases[Last@FileNameSplit@#, card__ ~~ ".eps" :> 
    (CardData[card] = ImageCrop@Import@#)] & /@ files;

You can then use this like any other curated data:

GraphicsRow[CardData@{"2C", "KH", "AS", "QD", "JC"}]


Random hand generator:

You can extend this further and also create a random hand generator using Mathematica as follows:

deck = Flatten@With[
    {
        ranks = CharacterRange["2", "9"] ~Join~ {"10", "J", "Q", "K", "A"}, 
        suits = {"C", "S", "H", "D"}
    },
    Outer[StringJoin, ranks, suits]
];
dealHand[n_Integer] /; 1 ≤ n ≤ 52 := CardData@RandomSample[deck, n]

Use this to deal a hand as dealHand[5], for instance. You'll have to modify this a bit to deal randomly and exhaust the deck at the same time (as you would in a game). There was a question on this previously on this site and I gave an answer based on Internal`Bag[] that will be useful here (along with some of the other answers there).

share
    
Thanks, this is certainly the realistic looking effect I was after (and hence is very useful for me since I can finish my task). It would be great to have a complete set of realistic looking playing cards accessible via built-in curated data. Maybe in the future? –  JohnD Dec 11 '12 at 19:45
    
Thanks for your input, just used that to create a simple math lesson on introductory probability, and this was just what I needed to make it work! –  Tom De Vries Apr 17 '13 at 17:41

Not super high quality, but this might do for some purposes:

cards = Join[
  Table[ToString[k], {k, 2, 10}],
  {"Jack", "Queen", "King", "Ace"}];
suits = {"hearts", "diamonds", "clubs", "spades"};
deck = Flatten[Outer[#2 <> " of " <> #1 &, suits, cards]];
images = Table[
  WolframAlpha[card, {{"Image", 1}, "Content"}], {card, deck}];
Grid[Partition[images, 13]]

enter image description here

In terms of your real question, namely "how to find out what all is included as curated data", I had no clue if playing card images were included or not. I simply asked Wolfram Alpha via a query like so:

enter image description here

Choosing "Subpod content" as shown, I learned that the command to access the image is

WolframAlpha["4 of clubs", {{"Image", 1}, "Content"}]

I couldn't figure out how to access the whole deck at once, but from here I was able to put the whole thing together programmatically.

share
1  
Thanks! This really answers my larger question: how to determine if a certain piece of data I'm after is even accessible (in curated form) within Mathematica, and if so, how to access it. –  JohnD Dec 11 '12 at 18:50
1  
So, are these cards really somewhere on my hard drive within the MMA files or are they just in some WolframAlpha server? –  VF1 Dec 11 '12 at 18:54
    
@VF1 My guess is that the images are not just on your hard drive, rather they're globally accessible via WolframAlpha's servers. I guess I don't know for sure, since WolframAlpha uses many of Mathematica's built in Data Paclets. –  Mark McClure Dec 11 '12 at 19:06

It is not entirely clear to me whether the playing cards in your question are just an example of what you want to find or the actual target. Since the other answers already provide you with the latter I'll provide a way to explore ExampleData.

The following two lines of code will build a complete overview of what's hidden in there. Running it may take a bit of time as most of the data will have to be transfered from the Wolfram server to your local paclet store for the first time.

switchedDisplay[stuff_] :=  
   DynamicModule[{x=False}, 
       Row[{"Show:  ", Checkbox[Dynamic[x]], "    ", 
             Dynamic[If[x, ExampleData@stuff, stuff], SynchronousUpdating -> False]}]
   ]
TabView[# -> TabView[switchedDisplay /@ ExampleData[#]] & /@ ExampleData[]]

Mathematica graphics Mathematica graphics Mathematica graphics Mathematica graphics

MacOS

MacOs doesn't seem to like long TabViews, so the code may have to be changed a little bit.

This adds another layer of TabViews where necessary:

MacMax = 30;
TabView[# -> 
    TabView[If[Length@ExampleData[#] > MacMax, 
      TabView /@ Partition[switchedDisplay /@ ExampleData[#], MacMax],
       switchedDisplay /@ ExampleData[#]]] & /@ ExampleData[]]

MacOS user MarkMcClure reports that ControlPlacement -> {Top, Left} in TabView also prevents problems from occurring.

share
    
I am indeed interested in whether the deck of cards, specifically, is internally curated by Wolfram. However, this led naturally to a more general question: how can I get an inventory of all Wolfram-curated data? It seems that this is a good, separate questions which others might search for. I don't know the protocol here, but should this be spun off as a separate, stand-alone question (with your answer of course)? Please advise. –  JohnD Dec 11 '12 at 20:21
    
@JohnD I don't think that's necessary. Perhaps, you could just edit the title to emphasize the "curated data" aspect, rather than the "playing card" aspect. The latter is in the question anyway. –  Mark McClure Dec 11 '12 at 20:24
    
@MarkMcClure: I see your point, but with two "real" questions here, I am conflicted on what to accept as "the" answer. –  JohnD Dec 11 '12 at 20:28

I don't know if this question is specifically asking about finding images in MMA's data, but if the end goal is to get playing card images, then using an online image and partition seems to work great. Link to image

ImagePartition[
     Import["http://www.milefoot.com/math/discrete/counting/images/cards.png"],{73, 98}] // Grid

enter image description here

Edit: The lack of a top outline over the third row of cards is an artifact of the pdf I saved the image as, not the actual MMA output. Also, the slightly thicker right side outline is a property of the image, which is supposed to have a shadow. This can be removed programmatically if needed.

Finally, I suppose that the way I went about extracting the individual card images from the imported image could have been more elegant than what I did, but I don't think there's an issue with trial and error for finding the card dimensions if it's just as effective as whatever the more elegant code is.

share
    
My first question was if it were accessible in some Wolfram-curated form (see Mark McClure's answer above). But then if not, how to bring in "external" data from the web and go to work using it. Your reply helps me with the latter (although I'm not sure how to slice up this single image into the relevant subimages I'd need). –  JohnD Dec 11 '12 at 18:52
    
@JohnD I sliced it up for you. If you remove the //Grid, then it will become a 2-dimensional array of playing card images. The Grid was there for display purposes. Mark's answer does more directly address what you asked for, though. I just think mine looks cooler. –  VF1 Dec 11 '12 at 18:55
    
Yours is indeed very cool! –  JohnD Dec 11 '12 at 20:23

Did you see Mathematica Package for Texas Hold'em from Sal Mangano. It's a Poker Simulation Library in Mathematica from http://www.mathematicacookbook.com. The code covers parsing cards, monte carlo simulation, a game engine as well as visual interface with cards. You can access also the images of cards from this link of same library.

share

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .