def draw(field): """ Re-draw canvas in two steps: clear and draw """ canvas.delete("all") for x, y in field: x0 = origin_x + dx * x y0 = origin_y + dy * y canvas.create_rectangle(x0, y0, x0 + dx, y0 + dy, fill="black") # re-draw canvas after delay with new field canvas.after(delay, functools.partial(draw, advance(field)))
def draw(field, position, velocity): ''' Re-draw canvas in two steps: clear and draw ''' canvas.delete("all") for (x, y), color in field.items(): x0 = origin_x + dx * x y0 = origin_y + dy * y canvas.create_rectangle(x0, y0, x0 + dx, y0 + dy, fill="black" if color else "red") # re-draw canvas after delay with new field canvas.after(delay, functools.partial(draw, *advance(field, position, velocity)))