This is a demo of the ipythonblocks module available at https://github.com/jiffyclub/ipythonblocks. ipythonblocks provides a BlockGrid object whose representation is an HTML table. Individual table cells are represented by Block objects that have .red, .green, and .blue attributes by which the color of that cell can be specified.

ipythonblocks is a teaching tool that allows students to experiment with Python flow control concepts and immediately see the effects of their code represented in a colorful, attractive way. BlockGrid objects can be indexed and sliced like 2D NumPy arrays making them good practice for learning how to access arrays.

In [1]:

fromipythonblocksimportBlockGrid

In [2]:

grid=BlockGrid(10,10,fill=(123,234,123))

In [3]:

grid

Out[3]:

In [4]:

grid[0,0]

Out[4]:

BlockGrid objects support iteration for quick access to individual blocks. Blocks have .row and .col attributes (zero-based) to help track where in the grid you are. The individual color channels on each Block can be modified directly.