from ipythonblocks import BlockGrid, colors
# start with the grid at http://ipythonblocks.org/zcezcM
grid = BlockGrid.from_web('zcezcM')
grid
# turn off the grid lines
grid.lines_on = False
grid
# going to draw a white spiral through the grid starting with the
# [0, 1] block and proceeding counter-clockwise.
# can think of this as repeatedly drawing some almost-closed
# boxes and making the box smaller each time.
def draw_spiral_box(row, col):
# starting point, since it's skipped
grid[row, col] = colors['White']
# calculate the bounds of the spiral box
left_col = col
right_col = grid.width - col - 1
top_row = row + 1
bot_row = grid.height - row - 2
# make sure it hasn't gotten so small it's time to stop
if right_col - left_col < 1 or bot_row - top_row < 2:
return None
# left line
grid[top_row:bot_row, col] = colors['White']
# bottom line
grid[bot_row, left_col:(right_col + 1)] = colors['White']
# right line
grid[top_row:bot_row, right_col] = colors['White']
# top line--going to be two blocks shorter than the bottom one
grid[top_row, (left_col + 2):right_col] = colors['White']
# start over from a new point
draw_spiral_box(row + 2, col + 2)
row = 0
col = 1
draw_spiral_box(row, col)
grid
grid.post_to_web('1:8')
u'http://ipythonblocks.org/RTRATA'