Skip to content

Commit

Permalink
Update emoji game example to work
Browse files Browse the repository at this point in the history
It's unclear if wrapping everything in VDOM() worked even before
this
  • Loading branch information
yuvipanda committed May 1, 2018
1 parent 78e3885 commit 792a6c5
Showing 1 changed file with 149 additions and 133 deletions.
282 changes: 149 additions & 133 deletions example-notebooks/emoji-game.ipynb
@@ -1,140 +1,156 @@
{
"cells": [
{
"cell_type": "code",
"source": [
"from vdom import VDOM, h1, div, p, b, createComponent\n",
"# marquee is deprecated officially by browsers\n",
"# we're going to create and use it anyway\n",
"marquee = createComponent('marquee')"
],
"outputs": [],
"execution_count": 2,
"metadata": {
"collapsed": false,
"outputHidden": false,
"inputHidden": false
}
},
{
"cell_type": "code",
"source": [
"from collections import Counter\n",
"\nwinners = Counter()"
],
"outputs": [],
"execution_count": 3,
"metadata": {
"collapsed": false,
"outputHidden": false,
"inputHidden": false
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"from vdom import VDOM, h1, div, p, b, createComponent\n",
"# marquee is deprecated officially by browsers\n",
"# we're going to create and use it anyway\n",
"marquee = createComponent('marquee')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"from collections import Counter\n",
"\nwinners = Counter()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false,
"inputHidden": false,
"outputHidden": false
},
"outputs": [
{
"cell_type": "code",
"source": [
"import secrets\n",
"import time\n",
"\n",
"winner = \"\"\n",
"\n",
"# Each player should pick an emoji that you put into this array\n",
"choices = [\"🥑\", \"🐱\", \"😻\"]\n",
"\n",
"game = display(VDOM(h1('GAMETIME')), display_id=\"game\")\n",
"\n",
"for ii in range(40):\n",
" winner = secrets.choice(choices)\n",
" game.display(\n",
" VDOM(\n",
" marquee(winner, style={ \"fontSize\" : '3em' })\n",
" ),\n",
" update=True\n",
" )\n",
" time.sleep(0.1)\n",
"\n",
"winners[winner] += 1\n",
" \n",
"game.display(VDOM(\n",
" div(\n",
" [\n",
" h1('WINNER ' + winner, style={ \"fontSize\" : '3em' }),\n",
" list(map(lambda i: p(i + ': ' + str(winners[i])), winners))\n",
" ]\n",
" )\n",
"), update=True)"
],
"outputs": [
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {
"style": {
"fontSize": "3em"
}
},
"children": [
"WINNER 🥑"
],
"tagName": "h1"
},
{
"attributes": {},
"children": [
"🥑: 2"
],
"tagName": "p"
},
{
"output_type": "display_data",
"data": {
"application/vdom.v1+json": {
"tagName": "div",
"attributes": {},
"children": [
{
"tagName": "h1",
"attributes": {
"style": {
"fontSize": "3em"
}
},
"children": "WINNER 🐱"
},
[
{
"tagName": "p",
"attributes": {},
"children": "😻: 1"
},
{
"tagName": "p",
"attributes": {},
"children": "🐱: 1"
}
]
]
},
"text/plain": [
"<vdom.core.VDOM at 0x110a86080>"
]
},
"metadata": {}
"attributes": {},
"children": [
"🐱: 2"
],
"tagName": "p"
},
{
"attributes": {},
"children": [
"😻: 1"
],
"tagName": "p"
}
],
"execution_count": 5,
"metadata": {
"collapsed": false,
"outputHidden": false,
"inputHidden": false
}
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"language": "python",
"display_name": "Python 3"
},
"kernel_info": {
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.6.4",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
],
"tagName": "div"
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"nteract": {
"version": "0.7.1"
"text/plain": [
"<div />"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import secrets\n",
"import time\n",
"\n",
"winner = \"\"\n",
"\n",
"# Each player should pick an emoji that you put into this array\n",
"choices = [\"🥑\", \"🐱\", \"😻\"]\n",
"\n",
"game = display(h1('GAMETIME'), display_id=\"game\")\n",
"\n",
"for ii in range(40):\n",
" winner = str(secrets.choice(choices))\n",
" game.display(marquee(winner, style={ \"fontSize\" : '3em' }), update=True)\n",
" time.sleep(0.1)\n",
"\n",
"winners[winner] += 1\n",
" \n",
"game.display(\n",
" div(\n",
" h1('WINNER ' + winner, style={ \"fontSize\" : '3em' }),\n",
" *list(map(lambda i: p(i + ': ' + str(winners[i])), winners))\n",
" ), \n",
" update=True\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernel_info": {
"name": "python3"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
},
"nbformat": 4,
"nbformat_minor": 4
}
"nteract": {
"version": "nteract-on-jupyter@1.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 792a6c5

Please sign in to comment.