Coder Social home page Coder Social logo

deck-of-cards / deck-of-cards Goto Github PK

View Code? Open in Web Editor NEW
3.1K 100.0 465.0 6.41 MB

Deck of Cards (old version)

Home Page: https://deck.of.cards/old

License: Other

CSS 29.93% JavaScript 51.35% HTML 4.41% Stylus 12.66% Pug 1.64%
game javascript html5 card deck css playing-cards

deck-of-cards's Introduction

HTML5 Deck of Cards

Financial Contributors on Open Collective Gitter

NEW VERSION COMING UP!

The new multiplayer Deck of Cards is released at https://deck.of.cards, but will have its cards library open sourced soon here!

Old version

Pure vanilla JS (+ CSS3) – no dependencies, by Juha Lindstedt & contributors.

https://deck.of.cards/old

Install from Google Chrome Web Store

Frontside card graphics are slightly modified from Chris Aguilar's awesome Vector Playing Card Graphics Set.

Also check out my RE:DOM and HTML5 Node Garden projects!

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

LGPL if you use Chris Aguilar's vector playing cards. Otherwise MIT.

Download

Installation from npm

npm install deck-of-cards

Then add in your html file

  • In <head>:
<link rel="stylesheet" href="node_modules/deck-of-cards/example/example.css">
  • At the end of the <body>:
<script src="node_modules/deck-of-cards/dist/deck.min.js"></script>

Usage

Full example

<html>
    <head>
        <title>Cards</title>

        <link rel="stylesheet" href="node_modules/deck-of-cards/example/example.css">
    </head>
    <body>
        <script src="node_modules/deck-of-cards/dist/deck.min.js"></script>

        <div id="container"></div>

        <script>
            var $container = document.getElementById('container');

            // create Deck
            var deck = Deck();

            // add to DOM
            deck.mount($container);

            deck.cards.forEach(function (card, i) {
                card.setSide(Math.random() < 0.5 ? 'front' : 'back');

                // explode
                card.animateTo({
                    delay: 1000 + i * 2, // wait 1 second + i * 2 ms
                    duration: 500,
                    ease: 'quartOut',

                    x: Math.random() * window.innerWidth - window.innerWidth / 2,
                    y: Math.random() * window.innerHeight - window.innerHeight / 2
                });
            });
        </script>
    </body>
</html>

Available on JsFiddle: http://jsfiddle.net/x0gjood1/

Javascript API

Deck

// Instantiate a deck
var deck = Deck();

// display it in a html container
var $container = document.getElementById('container');
deck.mount($container);

Deck example: http://jsfiddle.net/ec4kcx1k/

// Flip all cards in deck
deck.flip();

// Sort cards
deck.sort();

// Shuffle
deck.shuffle();

// Display fan
deck.fan();

// Remove deck from html container, hide it
deck.unmount();

Shuffle cards and fan: http://jsfiddle.net/favbdkta/

Deck with jokers:

// Instantiate a deck with jokers
var deck = Deck(true);

Card

// Select the first card
var card = deck.cards[0];

// Add it to an html container
card.mount($container);

// Allow to move/drag it
card.enableDragging();
card.disableDragging();

// Allow to flip it
card.enableFlipping();
card.disableFlipping();

// Flip card
card.flip();

// Display card front or back
card.setSide('front');
card.setSide('back');

Draggable and flippable card: http://jsfiddle.net/cgz9mjts/

Card in deck

Remove a card from a deck

var deck = Deck();

// Remove 10 cards starting from the 6th
var removedCards = deck.cards.splice(5, 10);

removedCards.forEach(function (removedCard) {
    removedCard.unmount();
});

Deck without Clubs: http://jsfiddle.net/L25facxj/

Build instructions

npm install
npm start

(starts watching for changes..)

Latest changes

  • 0.1.4 card.animateTo() -method added –> simplier modules! Simple example of usage
  • 0.1.3 JS animations (instead of CSS transitions)
  • 0.1.2 Backside graphics + setRankSuit (+ card.value -> card.rank!)
  • 0.1.1 Better organized modules + Chrome app
  • 0.1.0 Realistic face graphics, notice change of license for now..
  • 0.0.4 winning mode, simpler shuffling, CSS box-shadow change
  • 0.0.3 big refactoring – code now easier to follow and in smaller pieces
  • 0.0.2 made intro shorter & added "poker"
  • 0.0.1 initial version

Where's what?

css/ - CSS source (stylus + nib) of the example

chrome/ - Chrome Web Store app source

dist/ - deck.js & deck.min.js

example/ - https://deck-of-cards.js.org

lib/ - JS (ES6) source of dist/deck.js - deck.js is also the main file

views/ - HTML source of the example

Note to self: todo

  • Make z-index temporary by reordering DOM elements between actions
  • Enhance API, make more flexible

Featured on

deck-of-cards's People

Contributors

alcalyn avatar ceautery avatar demondragong avatar gregfrench avatar hubdotcom avatar jansegre avatar joequery avatar mizzao avatar mjkaufer avatar monkeywithacupcake avatar pakastin avatar settsu avatar vinceau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deck-of-cards's Issues

make another card image

Can I create a card with a different number of image files?
ex ) tarot card, game decks etc.

new version

Hi Juha,

Thanks for sharing your work, looks really good. I would love to use your module in my project which is in the development right now, but I found couple of comments where you referring that new version is coming out soon. Do you have any idea when that can happen?

Thanks, Vlad

Jokers

I love the app but please add Jokers back into the new version. Thank you!

Make cards rotate

Allow cards to be rotated around the z-axis. Consider adding support for two-finger rotation of card being hovered over (with highest z-index).

Use real z coordinate

Right now 3d-rendering is made in 2d with x & y.
Make a function with a fallback to 2d for older browsers and use real css3d.

Ability to shuffle specific piles of cards

I love this site! It's clean, and directly to the point.

One improvement that would make this great for games like Euchre that require a subset of cards is the ability to shuffle a specific pile of cards. E.g. I take out all the non-Euchre cards, pile Euchre cards near each other, then right click or some sort of similar interaction, and it shuffles that subset pile of cards.

Thanks!

translate3d or translateZ(0)

For better perf, you should switch to using translate3d or add translateZ(0) to your transform string. Really consider using the "3d" equivalents for each of the transforms, to force the GPU to do the heavy lifting. Not sure in this example it will be a huge win, but a good thing to keep in mind.

TCG use?

This would be amazing to use as a base for online TCG unfortunately I don't know How to code very well yet and would have a very difficult time trying to implement it.

All you would really need to add/change is make it easy to change the Number of card and look of the cards as well as make it possible To Create randomized decks. (with some kinda of 2 player function)

~Gr33n

P.S. i really like this wish i new how to cod i tried changing the .svg files to change the images and it didn't work

Cool. Might want to make numbers bigger (and suit icon count based on card value)

Hi, nice work.
If I were to use this for a game, I know I would want the card number image bigger and would really prefer the suit icon to be shown the number of times that matches the card value (i.e. 7 of spades should show seven spades, not just one. When I drew a poker hand, my first reaction was "What? Two Ace of spades in one hand?")
The value and suit upside down on the bottom is a nice realistic touch. Totally not needed for a virtual deck that can auto-rotate correctly, but cool.

Make it easier to create a deck of other than 55 or 52 cards

Currently, because of all the functions in the closure of deck.js, it is hard to create a deck of anything other than the default size. It is possible to render individual cards using Deck.Card, but then there is no logical deck containing them that can be shuffled, sorted, fanned, etc. since the nice animation functions using queue and observable aren't accessible.

Since some games don't use all cards, would it be possible to specify a Deck constructor that takes an array of values from [0, ..., 54] and then use this to construct a deck with a subset of the cards?

Make it easier to change card sizes

Right now the card sizes (including font) can be only be changed by setting html { font-size: 200% }, etc. This is because of the rem units used to determine the card size, which are relative to the document root.

It seems that this could be fixed by simply using em units; then one could insert cards to a div.deck or something like that and just set .deck { font-size: whatever } using CSS. Is there anything else that might need to be changed for this?

Originally mentioned at #8 (comment).

Abnormal dragging behaviour

If you first press mouse button one to drag a card and while dragging you press mouse button two, the card sort of warps to another location. After this if you try to drag the same card normally it warps again. Third time it works normally.

Cards flip to top- and backside randomely

Hey there,

When you use shuffle or sort, and move the cards, they randomely flip to top and backside. Is that meant to happen?

Cheers, Tom

Ps. I wanna use this in a schoolproject. Is that alright?

Biased Shuffling

It looks like your shuffling algorithm is pretty biased. In particular, this bit:

    cards.sort(function () {
      return Math.random() * 100 - 50
    })

This is a random comparator sort, and this page shows a bias matrix for this algorithm by default.

Shuffling lists is a pretty surprisingly subtle problem. I'd recommend the Fisher-Yates algorithm, which helpfully has a demo javascript implementation on the bias matrix page.

It's also worth noting that most implementations of Math.random() do not have enough bits of state to access all possible shuffled decks. You need about 226 bits for a 52 card deck, but Firefox (for example) has 48.

SUGGESTION: Removing cards from deck before shuffle

Some card games require you to remove cards from the deck prior to shuffling. e.g. When all cards have to be dealt out evenly to all players.

It would be good to nominate which cards (including suit) should be removed from the deck.

How can I know which card I clicked?

I have been able to test the project and that's great, thank u but I haven't been able to show in console the card that I flipped
I really appreciate ur support, thanks

please clarify move to GPL

You've mentioned that you moved to GPL in order to respect Chris Aguilar's http://sourceforge.net/projects/vector-cards/.

IMHO, you need not do that:
First, only your svg changes are derivative, so you can just release those separately under LGPL (can include it in a different repo to be more clear about that)
Second, Chris Aguilar's lib is LGPL so even if you thought it applies for all you code for some reason, you only need to license as LGPL.

Source link in app

I gather the "source" link in the Android application is a link to the old (single-user?) version?

I'd like to get access to the new code as well to hopefully contribute. Thanks.

Why does poker() not return the cards that were dealt?

Also, why is there not an easy toString() representation of a card? If I want to generate a URL to my hand, or send the dealt cards to the server, etc. All this is very difficult without any information on the cards.

Also, it would be extra nice if there was an overload of poker() that took the dealt cards. poker(['8h', '2s', '10s', '3c', 'Ah']). This way my server could be in charge of the dealt cards, and this library could be in charge of animating the hand.

Ideally, poker() should return a similar array as above. And card should have an overload or a getter with a display name and suite.

Z-index

Make it so the last card has the highest index then decrease all other cards that had a higher z-index with 1

Rotation information is lost after second rotation

If you rotate a card and then rotate it a second time, the original rotation information is lost (it goes back to 0, instead of rotating from the original position). I might have fixed this and might link to this issue from a commit soon

Italian Version deck

@ginnocenti I can add italian version as option to deck.of.cards

Originally posted by @pakastin in #55 (comment)

This is a package contains the edits that i made on my local version in the example.
It contains a list of png of the 40 cards of the deck.
In the js files i removed 12 cards from the original deck and in the css file I linked the cards to the new png.
If you need something more let me know.

https://drive.google.com/file/d/1AKznR509d4CY3DMW-dp0Jbq2JDdOVC5E/view?usp=sharing

SVG only cards - https://cardmeister.github.io/

I am not sure if I mentioned this in this Repo before.

Last year I re-worked all 52 SVG cards into a 16KB* Custom Element/WebComponent : https://cardmeister.github.io/

I only did the graphics for 52 cards; did not do any card-game logic, no Joker either.

Deck-of-cards:
image

with a lot of HTML/SVG/PNG

becomes:
image

with one HTML tag: <card-t cid="Jd"></card-t> (generating a lot of SVG into an IMG)

  • 16 KB in the I-cheated-version, full version is 64KB for all 52 cards

https://cardmeister.github.io/

Using the Custom Elements API, so no IE support out-of-the-box (polyfill should work)

But the technique doesn't strictly require Custom Elements. It is all about generating SVG and using that in a IMG tag.

Change Card Size and Position

Hi,

Can you please point to me how I can change the card sizes and position?
I have tried editing the .card class width and height in example.css but the cards overlap on deal(more pronounced with Poker and By Suit display).

Thanks

Alternative card faces

Why do you use the card faces from [1] when there is also [2]?

[1] is under the LGPL 3.0 and offers exceptions "on a negotiated fee basis".

[2] is in the public domain.

In fact, both are so similar that ...

  • one must be the copy of the other one
  • or
  • they must share a common original work that they're based on (which might be here)

Anyway, it seems [2] was there first.

[1] https://code.google.com/p/vectorized-playing-cards/
[2] https://code.google.com/p/vector-playing-cards/

API documentation

Hi, searching for an HTML5 playing card module I could use to develop card games, this one is the best I've found.

The Simple example of usage is cool and learns a lot of how I could use it.

But is there an API documentation that would explain many things like:

  • Make a card as draggable
  • Reveal or hide programmatically a card
  • Prevent a card to be revealed
  • Creating a fan with a subset of a deck
  • How to use shuffle or sort modules
  • Adding or removing a card in a deck...

Can I create a different deck?

The game I want to play is a variant of D&D that uses cards, it's called Dragonlance 5th age.

The Fate Deck is 82 cards, each with unique graphics.
There are 9 suits; Shields, Arrows, Helms, Swords, Moons, Orbs, Hearts, Crowns, Dragons.

Is it possible to change the number of cards in the deck and to swap out the graphics?

University offer

Hello!
Five university student is looking for an open source project. Our task in the university is find an open source project on git and help to make it better. We are really interested in this project, but our teacher says we have to work on an active project.
Firstly we would do the issues of course but we have a lot of idea to make this project better. We are thinking about that some AI make this project better to play poker or any other game.

Write back if you are interested in this concept.

card.flip is not a function

The documentation lists that the Card class has a flip function. It looks like this would be quite easy to add, and I'm happy to do it if needed, but at the moment, there is no "flip" function for a card.

Multiplayer shuffle of double deck produces consistient deck result

Hi, first off, thanks for creating this! Early on in the pandemic, I had the idea to create the same thing, and gladly found yours instead.

My issue is that shuffling seems to be broken in multiplayer when using 2 decks. I haven't tested this with a single deck, but it's repeatable for me in Firefox 83.0 on Win10.

One potential thought I had was to re-implement the fisher-yates shuffle, something like this: https://bost.ocks.org/mike/shuffle/

Steps to Reproduce:

  1. create new multiplayer deck
  2. add an additional deck
  3. shuffle
  4. draw cards:
  • 2 jokers
  • King of Diamonds
  • Queen of Diamonds
  • Jack of Diamonds
  • ...(and so forth)

Deck of Cards — Mozilla Firefox 2020-12-14 15-13-03
on Win10.

Thank you

Just wanted to say you have a beautiful coding style! Very inspiring!

Typescript import

Hello,

I'm trying to use your plugin into an Ionic app (version 2).

I used NPM and save into dependencies.

Then I import into my file home.ts

import { Component, ElementRef, OnInit } from '@angular/core';
import { NavController } from 'ionic-angular';
import * as Deck from 'deck-of-cards';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage implements OnInit {
  public container :any;

  constructor(public navCtrl: NavController, public el: ElementRef) {
    console.log(Deck);
  }

  ngOnInit() {
    this.container = this.el.nativeElement.querySelector('#container');
    console.log(this.container);
  }

}

The console log return a empty object

Is it possible to use deck.js as a module?

Forgive me if this question is not well worded but I would like to import the use of deck.js instead of having to include the script tag in my html file. Is there a way to support this? I couldn't follow based upon the descriptions below.

Ionic 2 use

Hi,

Is it possible to use this library with an Ionic 2 project ?

Thanks

Corner numbers of face-down cards visible initially

If I comment out deck.intro() in example.js:183 leaving only sorting after the creation and mounting of the deck, the corner numbers of cards are still visible even if they are supposed to be face down.

The numbers disappear upon flipping them over and over again (clicking by mouse two times), but they are visible in the intial view.

In both Chrome 57 and Firefox 52 (Linux versions).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.