In [ ]:
def distance(A, B):
    '''Taxicab distance between two tuples'''
    return abs(A[0]-B[0])+abs(A[1]-B[1])
distance((0,0),(3,5))
In [ ]:
# http://www.ipythonblocks.org/
from ipythonblocks import BlockGrid
import math
In [ ]:
adaYellow=(245,225,52)
adaPurple=(149,96,159)
adaGreen=(161,200,84)
adaCoral=(236,98,113)
adaBlue=(108,184,231)
adaOrange=(246,131,82)

adaBlack=(9,20,8)
adaGrey=(134,136,140)
adaLightGrey=(211,212,211)
adaWhite=(255,255,255)
In [ ]:
from ipywidgets import interact

An interactive. For playing with the 'eccentricity' $e$

In [ ]:
grid = BlockGrid(31,31,block_size=5,fill=(255,255,255))
# Directrix is col=0
d = 0
# Focus is at row 0, col 1
F = (5,16)
def draw(e):
    for block in grid:
        distance_from_edge = block.col
        distance_from_focus = distance((block.col, block.row), F)
        if distance_from_edge == round(e*distance_from_focus):
            block.set_colors(*adaBlack)
        else:
            block.set_colors(*adaWhite)
        if block.col == d:
            block.set_colors(*adaPurple)
        if (block.col, block.row) == F:
            block.set_colors(*adaBlue)
    return grid
interact(draw, e=(0,3,0.1));

To save a bunch of images

In [ ]:
grid = BlockGrid(31,31,block_size=5,fill=(255,255,255))
# Directrix is col=0
d = 0
# Focus is at row 0, col 1
F = (5,16)
for i in range(0,21,1):
    e = i/10
    for block in grid:
        distance_from_edge = block.col
        distance_from_focus = distance((block.col, block.row), F)
        if distance_from_focus == round(e*distance_from_edge):
            block.set_colors(*adaBlack)
        else:
            block.set_colors(*adaWhite)
        if block.col == d:
            block.set_colors(*adaPurple)
        if (block.col, block.row) == F:
            block.set_colors(*adaBlue)
    grid.save_image("eccentricity_{}.png".format(e))