info
-
ipythonblocks and ipythonblocks.org are mode by matt davis
-
ipythonblocks can be found on github
-
[ipythonblocks.org] is generously hosted by rackspace
usage
-
-
grid
from ipythonblocks import BlockGrid grid = BlockGrid(10, 10, fill=(123, 234, 123)) grid gird[0, 0]
-
iteration .row .col
for block in grid: if block.row % 2 == 0 and block.col % 3 == 0: block.red = 0 block.green = 0 block.blue = 0 gird
-
.height .width
for r in range(grid.height): for c in range(grid.width): sq = grid[r, c] sq.red = 100 if r % 2 == 0: sq.green = 15 else: sq.green = 255 if c % 2 == 0: sq.blue = 15 else: sq.blue = 255
-
show()
grid.show() gird[5, 5].show()
-
slicing
sub_grid = grid[:, 5] sub_grid.show() for block in sub_grid: block.red = 255 sub_grid gird
-
set_colors()
for block in grid[2:6, 2:4]: block.set_colors(245, 178, 34) grid
-
copy()
sub_copy = grid[3:-3, 3:-3].copy() sub_copy.show() sub_copy[:] = (0, 0, 0) sub_copy.show() grid
-
modified by assigning rgb tuples
gird[5] = (0, 0, 0) grid.show() grid[:, 5] = (255, 0, 0) grid.show() gird[-3:, -3:] = (0, 124, 124) grid.show() grid[1, 1] = (255, 255, 255) gird.show() gird[:, :] = (123, 234, 123) grid.show()
-
block_size
grid = BlockGrid(50, 50, block_size=5) grid # modified at any time grid.block_size = 2 grid
-
grid lines can be toggled by
lines_on
grid.lines_on = False grid
-
demos
-
Awesome Big Data Algorithms 21:17
from ipythonblocks import BlockGrid grid = BlockGrid(10, 10) x = grid.shape[0] y = grid.shape[1] for block in grid: r = block.row * 255 / float(x) g = block.col * 255 / float(y) block.red = r block.green = g grid