{ "metadata": { "name": "06_More_Examples" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Going Further... Insane & Ridiculous Matplotlib Applications" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Minesweeper" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Minesweeper is the classic PC game in which you click on a grid to find\n", "and mark the location of hidden mines. I wrote a minesweeper implementation\n", "entirely in matplotlib, using the principles we've discussed in this tutorial.\n", "\n", "I've included the code in this repository, and it can be run with the command below.\n", "\n", "You can also read more on my blog: http://jakevdp.github.com/blog/2012/12/06/minesweeper-in-matplotlib/" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%run ../examples/minesweeper.py" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To have a look at the code, you can use the ``%load`` magic:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%load ../examples/minesweeper.py" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Rubik's Cube" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another example builds upon the 3D cube rotation we saw before, but\n", "adds some operations to make a fully functional 3D NxN Rubik's cube,\n", "all in matplotlib.\n", "\n", "Again, I've included the script in this repository, and you can run\n", "or load the code below:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%run ../examples/cube_interactive.py" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The interactive cube script takes one argument: the number of cubies per side.\n", "You can specify any number, but for very large numbers it tends to slow down\n", "significantly:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%run ../examples/cube_interactive.py 5" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The code is complicated, but based on the building blocks that we've seen here.\n", "You can load it and take a look here:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%load ../examples/cube_interactive.py" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The projections and rotations are accomplished by the tools in this script. Note that\n", "this script is also used by the simple cube example we looked at earlier" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%load ../examples/projection.py" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }