{
"metadata": {
"name": "ipythonblocks_animation"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Animation with ipythonblocks
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For more on `ipythonblocks` see the home page at [https://github.com/jiffyclub/ipythonblocks](https://github.com/jiffyclub/ipythonblocks)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from ipythonblocks import BlockGrid"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import time\n",
"from IPython.display import clear_output"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It's possible to do animation of sorts using IPython's `clear_output` function."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"grid = BlockGrid(3, 3)\n",
"\n",
"previous_block = None\n",
"\n",
"for block in grid:\n",
" clear_output()\n",
" block.green = 255\n",
" \n",
" if previous_block:\n",
" previous_block.green = 0\n",
" \n",
" grid.show()\n",
" \n",
" previous_block = block\n",
" \n",
" time.sleep(0.2)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"