{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "from ipythonblocks import BlockGrid, colors" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "# start with the grid at http://ipythonblocks.org/zcezcM\n", "grid = BlockGrid.from_web('zcezcM')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 3, "text": [ "" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "# turn off the grid lines\n", "grid.lines_on = False\n", "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 4, "text": [ "" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "# going to draw a white spiral through the grid starting with the\n", "# [0, 1] block and proceeding counter-clockwise.\n", "# can think of this as repeatedly drawing some almost-closed\n", "# boxes and making the box smaller each time.\n", "def draw_spiral_box(row, col):\n", " # starting point, since it's skipped\n", " grid[row, col] = colors['White']\n", " \n", " # calculate the bounds of the spiral box\n", " left_col = col\n", " right_col = grid.width - col - 1\n", " top_row = row + 1\n", " bot_row = grid.height - row - 2\n", " \n", " # make sure it hasn't gotten so small it's time to stop\n", " if right_col - left_col < 1 or bot_row - top_row < 2:\n", " return None\n", " \n", " # left line\n", " grid[top_row:bot_row, col] = colors['White']\n", " # bottom line\n", " grid[bot_row, left_col:(right_col + 1)] = colors['White']\n", " # right line\n", " grid[top_row:bot_row, right_col] = colors['White']\n", " # top line--going to be two blocks shorter than the bottom one\n", " grid[top_row, (left_col + 2):right_col] = colors['White']\n", " \n", " # start over from a new point\n", " draw_spiral_box(row + 2, col + 2)\n", " \n", "\n", "row = 0\n", "col = 1\n", "\n", "draw_spiral_box(row, col)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 6, "text": [ "" ] } ], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "grid.post_to_web('1:8')" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 7, "text": [ "u'http://ipythonblocks.org/RTRATA'" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }