r/javascript • • Sep 02 '15

HTML5 Deck of Cards. 100% vanilla JS.

http://pakastin.github.io/deck-of-cards/
368 Upvotes

185 comments sorted by

37

u/papers_ Sep 02 '15

Huge up vote for using ES6 here. Good job man!

13

u/pkstn Sep 02 '15

Yeah! I just love the small bundles by rollup. No way going back to browserify :)

10

u/arcticblue Sep 03 '15

Great, another bundler.

4

u/pkstn Sep 03 '15

Same thing with cars: there's Toyota, Volkswagen, Hyundai, Ford, Nissan, Fiat, Honda, Suzuki, Renault, BMW, Mazda... They all have four wheels. And every year they release a new model, can you imagine?

Wouldn't it be better to just stick with current models and not invent anything new? And better yet, only one manufacturer..?

Where's: "Great, another Tesla."?

11

u/kokomo42 Sep 03 '15

Now imagine every new model of car have a totally new way to drive.

2

u/pkstn Sep 03 '15 edited Sep 03 '15

Well, not every year we change how to define modules.

And if you think about Tesla for example: at least for me the way throttle pedal works is a whole new way to drive. You control the "brakes" with lifting throttle.

I like innovations. I'm not afraid of change.

1

u/pkstn Sep 03 '15

Better than previous ones - nothing wrong about that.

Rollup is used by the big players as well, even Google: https://github.com/google/incremental-dom/blob/master/package.json#L45

1

u/arcticblue Sep 03 '15

There are more than enough in existence already. If existing ones are deficient in a certain area, I'd rather see effort put in to improving it rather than re-inventing the wheel...again. Someone re-invents the wheel, a few know-it-all bloggers make "You've been doing X wrong. Start using Y now!" posts on Medium, and then I'm required to re-learn my job again when I just got comfortable with existing tools. It's fucking exhausting.

3

u/pkstn Sep 03 '15

Well, you can continue to use X if you like ;)

I think it's good to have options, and innovations moving things forward.

1

u/arcticblue Sep 03 '15

You're right, it is good to have options. I just wish things would slow down a bit...I'm getting too old to keep up with all this.

3

u/pkstn Sep 03 '15

I just turned 30 myself, but I feel like I'm just getting started :D But I recognize the issue, that's why I've started to create vanilla JS, so that I'd be framework-free :)

Here's my minimal framework, which I think never finishes, because it gets smaller and smaller. Now I feel that even having own framework slows developing down, so I might remove the whole project: http://frzr.js.org/example/with_reordering.html http://frzr.js.org/example/without_reordering.html

..the performance is something else when everything's minimal.

1

u/KalimasPinky Sep 03 '15

New does not mean innovation. Quite often it is just spun differently.

Either way all this has been done from a language perspective. Import from looks like Python, and Python looks like older stuff.

0

u/[deleted] Sep 03 '15

[deleted]

3

u/pkstn Sep 03 '15 edited Sep 03 '15

Rollup only bundles ES6 modules. There are lots of other bundlers for that also. Even browserify does that. So I don't worry at all.

Grunt is not needed, when there's chokidar and npm scripts. Much easier like that.

Coffeescript will gradually fade out with ES6 taking place, at least I predict so.

But you can use whatever you like. I've tried them also, but I have my own ways.

2

u/mattdesl Sep 03 '15

It would be cool if this feature was just built into browserify/webpack (or through a plugin), so that we can stop fragmenting the ecosystem further than it already is... :)

1

u/pkstn Sep 03 '15

I just don't see the place for CommonJS modules in the front end since we have ES6 modules. For me browserify is more of CommonJS and rollup for next-gen ES6 modules.

And when using chokidar + npm it's really easy to switch between builders, if must..

1

u/[deleted] Sep 03 '15

Well, to be fair browserify supports small bundles too. The problem is the library you are using has to be structured in some way. For example I can include underscore.strings humanize function like this:

var humanize = require('underscore.string/humanize');

Which will only include that humanize function and nothing else.

The problem is that a lot of libraries do not actually have that structure, so it does not work everywhere. But it's not true that browserify does not support small bundles :)

1

u/pkstn Sep 03 '15

What I meant by "small bundles", was that rollup doesn't add any bloat like browserify – instead it removes unneeded stuff and produces very clean output:

http://pakastin.github.io/deck-of-cards/dist/deck.js

https://github.com/rollup/rollup/wiki

https://github.com/esperantojs/esperanto/wiki/Comparisons-with-other-tools

(esperanto is rollup's predecessor..)

1

u/[deleted] Sep 03 '15

I don't use ES6 with browserify, I just use commonjs modules, so I don't know what bloat browserify adds for ES6 support. But as far as I know browserify only supports ES6 in the form of transformers, so basically anything can be used to transpile your ES6 into ES5, so also a transpiler that does not use any "bloat".

What kind of bloat does browserify add when using ES6?

1

u/pkstn Sep 03 '15

I mean in the beginning of the file:

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

..for every module:

},{"xxxx-yyyy":37}],2:[function(require,module,exports){

..not to mention when you have more dependencies:

},{"../xxxx/yyyy/zzzz/xxxx.js":1,"aaaa":3,"bbbb":37,"cccc":78,"dddd":81,"eeee":82,"ffff":83,"gggg":85,"hhhh":87,"iiii":88,"jjjj":89}],3:[function(require,module,exports){

I just like clean code more.

2

u/[deleted] Sep 03 '15

Yeah, well I also run uglifyjs on my code, so my production bundle is absolutely unreadable. I don't think readability of the production bundle is really important. If you still need to debug the production bundle then you can use codemaps and chrome dev tools to get the actual code back in your development console.

1

u/pkstn Sep 03 '15

Browserify is great also, no question about it.

1

u/ayostaycrispy Sep 03 '15

Can you elaborate on how you used ES6?

2

u/pkstn Sep 03 '15

1

u/ayostaycrispy Sep 03 '15

Thanks. How many years have you been working in Javascript to get to your current level of expertise? I'm trying to get an idea of the approx. number of hours you've put in, although I know you probably only have a rough estimate.

2

u/pkstn Sep 03 '15

I made this one in couple of hours, but I started web developing with Flash back in 1999. And made first Deck of Cards in 2006 (http://pakastin.fi/cards_2006), so the concept is not new..

1

u/pkstn Sep 03 '15

If you mean javascript expertise in total..well, I switched using node.js late 2011 and after that I started to learn the language properly. I used jQuery before that as well, but nothing special..

-3

u/realhacker Sep 03 '15

I feel this needs to be said re: rollup. the readme file... it has rap lyrics at the top. I get youre trying to be a brogrammer or whatever, but its cliche and cringeworthy. nothing dorkier than a programmer including rap lyrics in code. try harder.

1

u/pkstn Sep 03 '15

:D I think Rich Harris is allowed to do that – he's the man B)

5

u/realhacker Sep 03 '15

who the hell is rich harris

4

u/pkstn Sep 03 '15

Author of rollup, ractive.js and many other great projects – follow the link bro!

I mean who cares about some stupid rap lyrics, when he's developed such many great software anyone can use for free.

-2

u/realhacker Sep 03 '15

such wow much amazed

1

u/pkstn Sep 03 '15

Your still the realhacker, don't worry.

-5

u/realhacker Sep 03 '15 edited Sep 03 '15

I assume your username means pakistan? hows sharia law treating you? ill laugh when trump turns your country to glass. in the meantime, youre on my shortlist if I ever need to hire a curry at .50 shekkels an hour

3

u/pkstn Sep 03 '15 edited Sep 03 '15

I'm from Finland: "pakastin" means "a freezer" in Finnish and it's my little company's name (makes cool stuff). Think of "pkstn" as "frzr". "Pakastin" was taken :/

I have nothing to do with Pakistan whatsoever. Never been there, actually don't even know where it's located. I also have never heard of this "sharia law" you're talking about.

Our currency is euro (EUR, €). I use curry mainly in my javascript projects.

Peace!

https://en.wiktionary.org/wiki/pakastin

https://en.wikipedia.org/wiki/Finland

→ More replies (0)

1

u/starboard_sighed Sep 03 '15 edited Sep 03 '15

Seriously? It really affects you that much? Clearly this person likes to use this bundler. And perhaps—I know this may be hard to grasp—the author of the repo's readme doesn't care how they are perceived? Like if you want to critique it on a technical level, that's one thing, but to complain about something so minor in software that was written at no cost to you, and which it sounds like you have no desire to use anyways? I just don't get it. Why do you feel that needs to be said?

It's just a stupid joke; it's not meant to be taken seriously in any way at all. The lyric is completely ridiculous, lol

12

u/[deleted] Sep 02 '15

Just make it so we can flip them over in that interface, and we can play our own games of solitaire.

8

u/pkstn Sep 02 '15 edited Sep 03 '15

Actually the original version had flipping - I will add it :)

3

u/[deleted] Sep 02 '15

Cool.

4

u/rentnil Sep 03 '15

If it just does the card bouncing thing from win95 solitaire we are all set.

3

u/pkstn Sep 03 '15

Must. Do. That. :D :D :D

2

u/pkstn Sep 05 '15 edited Sep 06 '15

Try clicking all the aces once and nothing in between..but don't tell anyone ;D Should use canvas for better performance for this one though..

10

u/Baturinsky Sep 02 '15

Not working in Firefox :(

3

u/pkstn Sep 02 '15

Which version? :/

4

u/yesman_85 Sep 02 '15

The latest.

3

u/pkstn Sep 02 '15

I added Moz -prefix – does it work now? (You might need couple of refreshes..)

4

u/antoninj Sep 02 '15

Nope. :/

2

u/pkstn Sep 02 '15

:( do you get any errors?

3

u/GuruMeditation Sep 02 '15

No errors in the console. The shuffle and sort buttons work; but the cards never move (none of the animations, fan button doesn't work, click drag doesn't work).

3

u/pkstn Sep 02 '15

The problem must with the css prefix - have to check it out..

4

u/[deleted] Sep 03 '15

FYI it works on my Firefox.

3

u/pkstn Sep 03 '15

Yeah, I fixed the bug with Firefox so it should too :)

5

u/GuruMeditation Sep 02 '15

No worries, it looked really snazzy in Chrome.

1

u/yesman_85 Sep 02 '15

Why don't you try it for yourself? It just doesn't do anything else but show 1 card in the middle of the screen.

3

u/pkstn Sep 02 '15

Works in my Firefox.. Have to check out if I have some older version. I don't use Firefox that much.

4

u/trouzy Sep 02 '15

Works fine on current FF for windows here.

1

u/pkstn Sep 02 '15

Good to know - the fix worked!

3

u/franrata Sep 02 '15

it works for me (windows)

2

u/RenThraysk Sep 02 '15

The code in prefix.js doesn't look right...

https://github.com/pakastin/deck-of-cards/blob/master/lib/prefix.js

In searching for correct prefix, it builds a string... but doesn't test it.

1

u/pkstn Sep 02 '15

Oh crap, you're totally right.. Brain fart 💩

I will fix that right away! Thanks!!

1

u/pkstn Sep 02 '15

Now fixed - thanks again!

1

u/RenThraysk Sep 02 '15

NP, Seems to have fixed the animation in Firefox nightly at least

1

u/pkstn Sep 02 '15

Perfect!

5

u/IWannaGoDeeper Sep 02 '15

Not working on Firefox?

3

u/pkstn Sep 02 '15

Check the other conversation about Firefox..

5

u/pkstn Sep 02 '15

Fixed now!

5

u/angellus Sep 02 '15

You have Mixed Content errors on your deck.min.js if you load the page over HTTPS (I have HTTPS everywhere install so it loaded automatically).

You should always use // instead of http:// to prevent this from happening. It will attempt to load the resource over the same protocol as the parent page.

2

u/pkstn Sep 02 '15

That's fixed now, thanks!

2

u/parpaythrums Sep 02 '15

Better yet, use https:// instead!

1

u/angellus Sep 02 '15

No argument there, https should be used everywhere.

This can lead to issues also. I have only seen it lead to issues if you use iFrames that have HTTPS when the parent page is not and you are trying to communicate between the two through the use of sockets.

Your best bet is to use // everywhere and than use nginx or some other Web server to force all requests to HTTPS, but this is just getting into the heavy technical side that OP probably does not care about. // gives you the least possible chance of issues because of mixed content which is why I perfer it.

4

u/MrBester Sep 02 '15

Chrome sends Upgrade-Insecure-Requests: 1 in the headers now.

Using protocol agnostic URLs is now considered an anti-pattern (plus, Content-Security-Policy will snarl at you)

2

u/pkstn Sep 02 '15 edited Sep 03 '15

I don't want to break things up when used from file:// – if you want to try and tinker locally.. I think I'll keep those https://

2

u/angellus Sep 02 '15

It is definitely not an anti-pattern. Making all the URLs protocol agnostic is a good thing. It makes the application more portable and able to run in more environment (for development or QA). SSL certs are expensive and there is no reason to spend extra to SSL a private network for testing and such. Using external resources from CDNs and such should always be HTTPS if possible.

Also, Content-Security-Policy only affects other domains. So using // is a better choice there because self is always allowed.

Upgrade-Insecure-Requests: 1 would be completely irrelevant since if the original GET is upgraded, all of the following requests would HTTPS also.

3

u/MrBester Sep 03 '15

I trust Paul Irish: http://www.paulirish.com/2010/the-protocol-relative-url/

Plus there's such a thing as free certificates these days. It's not like when they cost a packet anymore.

1

u/pkstn Sep 02 '15

Yeah, it's https now.

1

u/myrddin4242 Sep 03 '15

Almost always... Phonegap/Cordova apps wrap a webview which go to file:// 😁

5

u/robotslacker Sep 02 '15

This is cool! Nice work. It'd be pretty cool if you had an API that would allow people to build their own card games off of this.

4

u/pkstn Sep 02 '15 edited Sep 02 '15

Not a bad idea. I could add some new methods to the current API.

Basically now you can do the following:

var deck = Deck()

deck.shuffle()

deck.sort()

deck.bysuit()

deck.fan()

(check out example.js)

That's about it.. But it is pretty easy to fork the project and just add own modules.. But let's see. Might be fun to create a card game engine and see what people would make out of it.

2

u/robotslacker Sep 02 '15

Yeah you might be on to something -- it wouldn't be limited to games with traditional card decks either if the cards were skinnable and you could add different attributes to it, etc.

5

u/pkstn Sep 02 '15

Maybe I should create another more barebones project for that..

2

u/robotslacker Sep 03 '15

I'll give ya my blessing. :)

Can help out too as I've been looking for a side project to work on.

1

u/pkstn Sep 06 '15

I've been gradually refactoring + opening the API. Feel free to fork + pull request if you have something in mind..

4

u/cresquin Sep 02 '15

Looks like a good learning experience.

4

u/pkstn Sep 02 '15 edited Sep 02 '15

Feel free to ask any questions ;)

edit: about the project..

12

u/dhdfdh Sep 02 '15

Why is there air? I mean, why do we need it?

1

u/pkstn Sep 02 '15

What do you mean by air?

1

u/TheIronDev Sep 02 '15

Well you said feel free to ask questions.. He wants to know more about air. Please op.

4

u/pkstn Sep 02 '15

Oh :D

We need air to breathe.

1

u/rob132 Sep 02 '15

Thank you so much.

1

u/pkstn Sep 02 '15

Anytime!

3

u/3Fyr Sep 02 '15

Whatever I do, it always increase z-index, it should be increase/decrease I guess?

Also, some sort of animation could help.

1

u/pkstn Sep 02 '15

I agree, moving is not quite there yet.. Use the buttons on top ;)

3

u/theQuandary Sep 02 '15

I'd also add that the current card should default to the highest z-index (this is how they work in real life and is expected behavior).

1

u/pkstn Sep 06 '15

Fixed!

1

u/pkstn Sep 06 '15

Fixed!

3

u/[deleted] Sep 02 '15

I've had this desire to make something absolutely from scratch. Well, as much as possible. Like the endeavour to go out into the woods, find a rock, make shards, get some branches, make an axe, get a tree, get some lumber, etc etc. until I have a bird house or something.

I'm now compelled to do a similar series of projects in JS because of this. I would love to write code to go as far as to define the suits, characters all as vectors, then arrange into cards, then create the deck, etc etc.

I dunno. Rambling. But I think it would be beautiful.

1

u/pkstn Sep 03 '15

Sounds great, have fun! ;)

2

u/conundrumer Dec 29 '15

I've had this desire to make something absolutely from scratch. Well, as much as possible. Like the endeavour to go out into the woods, find a rock, make shards, get some branches, make an axe, get a tree, get some lumber, etc etc. until I have a bird house or something.

You will enjoy this video of someone doing precisely that.

3

u/bart2019 Sep 03 '15

Uh, all cards of the same colour all look like aces, but with a different number, or letter in case of the "people" cards.

1

u/pkstn Sep 03 '15

True dat.

1

u/pkstn Sep 06 '15

Fixed!

1

u/bart2019 Sep 06 '15

Wow. That does look a lot more finished now. Cool.

1

u/pkstn Sep 06 '15

Also try click all kings in a row.. ;)

2

u/pkstn Sep 03 '15

I just found the 2006 version of Deck of Cards – made with Flash: http://pakastin.fi/cards_2006/

:)

1

u/pkstn Sep 03 '15

Here's first HTML5-version: https://web.archive.org/web/20130823182335/http://pakastin.fi/cards (just close wayback machine controls first..)

2

u/memeship Sep 02 '15

Is there a particular reason why sometimes you're using the notation el.style[prop] and other times el.style.prop?

I haven't seen the first one a whole lot, just curious why you've done it that way, and more so why you're doing it both ways in the same file.

2

u/pkstn Sep 03 '15

Some params need a vendor prefix in some browsers (like transform & transition -> webkitTransform, mozTransform etc..), so that's why I've done it like this:

var transform = prefix('transform')

var transition = prefix('transition')

el.style[transform] = ...

el.style[transition] = ...

Maybe I should name those variables better to avoid the confusion..

1

u/memeship Sep 03 '15

Oh, I see now. You're passing in variables, not strings. That is certainly an interesting approach.

1

u/pkstn Sep 03 '15

Basically similar to i.e. vendor-prefix..

1

u/memeship Sep 02 '15

Also curious why you're using dollar signs in front of element variables. Just trying to imitate the look of jQuery or what?

1

u/pkstn Sep 03 '15

Just to separate DOM elements from plain objects..

0

u/ToucheMonsieur Sep 03 '15

Also curious why you're using dollar signs in front of element variables. Just trying to imitate the look of jQuery or what?

Most likely a style choice.

1

u/memeship Sep 03 '15

Oh I agree on that one. I also prefix stored jQuery objects. But he's not using jQuery, so it doesn't exactly make sense here in that context.

2

u/pkstn Sep 03 '15

I tend to prefix references to DOM elements because I want to separate view objects from DOM elements.. jQuery doesn't own the dollar sign in any way :)

0

u/3Fyr Sep 03 '15

I prefix some functions with dollar sign. I have no idea why.

Have seen others do it too.

3

u/memeship Sep 03 '15

If you have no idea why even you do it, I feel like that's an issue.

1

u/[deleted] Sep 03 '15

[removed] — view removed comment

2

u/thecheatah Sep 03 '15

The grabbing algorithm doesn't account for where the card was clicked from, making it twitch and seem unnatural. On click determine the offset and then base moves with the addition of that offset to get a smooth transition.

1

u/pkstn Sep 03 '15 edited Sep 03 '15

Yeah someone else brought that out as well. The problem is that I'm using transform: translate() with percents & pixels mixed, so I can't be certain how much initial offset the card has when dragging starts. I have to fix that one!

1

u/pkstn Sep 05 '15

That's now fixed - at least sort of..

2

u/[deleted] Sep 03 '15

phat and sick

1

u/pkstn Sep 03 '15

I had to Google up what does "phat" mean, but thanks, I guess! :D

2

u/muffsponge Sep 03 '15

Nice.

But having the cards snap to the middle when dragging is /r/mildlyinfuriating. They should anchor to the point they were clicked. Store an offset when a card is initially pressed.

1

u/pkstn Sep 03 '15

I will fix that.

1

u/pkstn Sep 05 '15

Fixed. Although a bit differently..

1

u/pkstn Sep 08 '15

Added better graphics and a couple of easter eggs..see if you can find them :) https://deck-of-cards.js.org

1

u/[deleted] Sep 02 '15

What's it supposed to do? I'm in IE11 (don't judge me--I'm at work) and the buttons don't seem to do anything.

1

u/pkstn Sep 06 '15

I think it's fixed..?

1

u/[deleted] Sep 11 '15

All the buttons now work but the suits don't appear. Just numbers. IE11. Windows 7.

Still haven't tried at home. I'll do that and let you know the results as well.

1

u/Tribuadore Sep 02 '15

Wow, I've studied your code, very interesting.

Haven't seen anyone bitch about no semi-colons yet. I used to leave them off too, until I gave up the fight and just started conforming with everyone else. I really like your style.

Something I've never seen before either is for example your queue.js, where given an object it assigns .queue to the object and returns. Took me a minute to work out what was going on. I'm looking at the code thinking "this function doesn't do anything", then I realised the queue function is in scope even though it's defined after the return.

I'm wondering could you also put the queuing variable after the return too?

4

u/randfur Sep 02 '15

That's JavaScript's function hoisting where function definitions are implicitly moved to the top of their scope. Variables get hoisted to the top of their scope as well with the value undefined, it isn't until the point in the code that you specify that they get assigned something else. This means you can use variables before you've assigned them and they'll have the value undefined.

2

u/pkstn Sep 02 '15

Yes, that's true. In this case it's not possible to define queueing after return:

return target

var queueing = []

Queueing would get hoisted, but the value would be undefined - I think. Function definitions work a little differently. Although some old IE might crash and burn, but minification (uglifyjs) should fix the order, I think..

4

u/MrBester Sep 02 '15 edited Sep 02 '15

queueing would get hoisted, but the value would be undefined - I think.

Correct.

While you know what you're doing, newer developers may not. Hence I advocate declaring vars (uninitialised until you need them), internal functions, then the meat of the main function with returns liberally spread around.

Anything to minimise the slightest possibility that old IE will cough. It already has enough ways, so why give it more?

You also get to see at a glance just how much you're declaring - instead of picking through the code - so you can tell if you really ought to refactor it...

1

u/pkstn Sep 03 '15

You are right..

1

u/pkstn Sep 02 '15

Yeah, I tend to keep the "basic structure" of the function as high as possible (initializations and returns).. Hoisting does the magic.

About those semicolons: I use standard with sublime and it's been awesome!

1

u/pkstn Sep 03 '15

..and the produced output have semicolons: https://github.com/pakastin/deck-of-cards/blob/master/dist/deck.js

;)

1

u/I_Pork_Saucy_Ladies Sep 03 '15

As a proponent of semicolons, thank you for choosing the pragmatic approach. :)

1

u/nightlily Sep 02 '15

Looks good!

I would recommend changing the way card stacking works so it is more intuitive/consistent. At the moment, when I move a card around it is hard to tell whether the card is going to go under or above the card I stack it with.

Try playing a game of solitaire and you'll see what I mean.

1

u/pkstn Sep 03 '15

I agree. The moving around bit is not quite there yet.. I made a stupid choice with using only translate but not saving the current values. I will fix that.

1

u/pkstn Sep 05 '15

Fixed now. Finishing solitaire session at the moment.. :)

1

u/nightlily Sep 05 '15

Nice work!

1

u/anlumo Sep 02 '15

Please add a license to the repository!

1

u/pkstn Sep 03 '15

Thanks! I have no idea about open source licenses. Which one would you recommend? There is "MIT" text in package.json, so maybe I copypaste that one from somewhere..?

1

u/anlumo Sep 03 '15

MIT would be good, yeah.

1

u/pkstn Sep 06 '15

Sorry, I had to change to GPL, since the new graphics are also licensed GPL.. Hope that want cause any problem. 0.0.x versions are still MIT, you can find them from the "releases"-tab.

1

u/anlumo Sep 06 '15

You can still license your part MIT, because this license is GPL-compatible. Just the whole thing including the graphics would be GPL then.

1

u/pkstn Sep 07 '15

The problem is I modified the graphics. When theming is possible, I could separate graphics and change the license back, but like I said, I want to respect Chris having choosed GPL for now.

1

u/dadecounty3051 Sep 03 '15

Which computer do you use?

1

u/pkstn Sep 03 '15

I have a 15" MacBook Pro.

1

u/Xeon06 Sep 03 '15

Very cool. Good job man.

1

u/cipherous Sep 03 '15

Slick!

1

u/pkstn Sep 03 '15

Thanks! :)

1

u/MeanestBossEver Sep 03 '15

This is very cool. Well done.

1

u/pkstn Sep 03 '15

Thank you!

1

u/BeniBin Sep 03 '15

I would definitely read a blog post about the process of making this.

2

u/pkstn Sep 03 '15 edited Sep 03 '15

Actually the story goes back to (at least) 2006: http://pakastin.fi/cards_2006/ (made with Flash)

..then I made Angular.js version, which I can't find anywhere – but it was on Chrome Experiments back then.

And now I made vanilla JS version..

I got the original idea because vending machines with card games had premade animation back then which I found unrealistic. I though if it would be hard to animate better. Turned out it wasn't :)

3

u/pkstn Sep 03 '15 edited Sep 05 '15

I just found the Angular.js version as well: https://web.archive.org/web/20130823182335/http://pakastin.fi/cards

Close wayback machine's topbar to use the controls ;)

2

u/pkstn Sep 06 '15

I got inspired by your idea - planning to write. I've never wrote a blog, but you got to start somewhere :)

1

u/BeniBin Sep 07 '15

Awesome ! Thanks for doing this :)

1

u/pkstn Sep 07 '15

I was thinking that because I'm not a native English speaker, that would be a great learning experience as well. Especially if readers could correct my grammar, it would be a win-win! :)

1

u/pkstn Sep 07 '15

Btw. did you already try what happens when you click all the kings in a row.. ;)

1

u/[deleted] Sep 03 '15

The z-index of a card seems to be incremented on each click by 1. I think the desired behavior sorts the currently clicked card to be on top of the others, so maybe it should be set to max + 1 on a click.

1

u/pkstn Sep 03 '15

Yeah, I should fix that. You're not the first to tell me about this, but thanks anyway :D

1

u/pkstn Sep 05 '15

Now works better!

1

u/pkstn Sep 06 '15

Should work now!

1

u/[deleted] Sep 09 '15

Nice

1

u/pkstn Sep 09 '15

Btw. try click all kings in a row ;)

1

u/[deleted] Sep 10 '15

Nice! For a moment, I thought it was going to do the solitaire winning animation, but easter eggs are always fun.

1

u/pkstn Sep 12 '15

Try same with aces.. ;)

1

u/[deleted] Dec 01 '15

I was checking if you did a fair shuffle, and found this

rnd = Math.random() * i | 0

I'm impressed that you can OR 0 to round.

1

u/pkstn Dec 02 '15

OR is double pipes (||), one pipe (|) turns number to integer..

1

u/[deleted] Dec 02 '15

One pipe is a bitwise OR. You don't typically do OR operations with floating point, so javascript rounds down to an integer first.

1

u/pkstn Dec 02 '15

You're correct, sorry I thought you were talking about the logical operator. But yeah, bitwise OR is useful, because it floors down the number - looks so much cleaner IMO. I also use bitwise NOT to check if indexOf is over -1: ~haystack.indexOf('needle') instead of haystack.indexOf('needle') > -1..

0

u/[deleted] Sep 02 '15

[deleted]

1

u/pkstn Sep 03 '15

It's actually a feature, but I know that it is not that intuitive. Have to fix the whole moving around logic..

0

u/[deleted] Sep 03 '15

[deleted]