-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbitmap.py
More file actions
27 lines (19 loc) · 794 Bytes
/
bitmap.py
File metadata and controls
27 lines (19 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from sys import stdout
class Bitmap:
def __init__(self, width, height):
self.width = width
self.height = height
self.data = [[0] * width for i in range(height)]
def apply(self, bitmap, op=lambda a, b: b, x=0, y=0):
for py, row in enumerate(bitmap.data):
for px, pixel in enumerate(row):
old = self.data[y + py][x + px]
if y + py >= 0 and y + py < self.height and x + px >= 0 and x + px < self.width:
self.data[y + py][x + px] = op(old, pixel)
def dump(self, out=stdout):
"""Dump this to stdout, for debugging."""
for row in self.data:
for pixel in row:
out.write('#' if pixel else ' ')
out.write('\n')
out.flush()