44 lines
1.1 KiB
Plaintext
44 lines
1.1 KiB
Plaintext
T Colour = Vec3b
|
||
|
||
V black = Colour(0, 0, 0)
|
||
V white = Colour(255, 255, 255)
|
||
|
||
T Bitmap
|
||
Int width, height
|
||
Colour background
|
||
[[Colour]] map
|
||
|
||
F (width = 40, height = 40, background = white)
|
||
assert(width > 0 & height > 0)
|
||
.width = width
|
||
.height = height
|
||
.background = background
|
||
.map = [[background] * width] * height
|
||
|
||
F fillrect(x, y, width, height, colour = black)
|
||
assert(x >= 0 & y >= 0 & width > 0 & height > 0)
|
||
L(h) 0 .< height
|
||
L(w) 0 .< width
|
||
.map[y + h][x + w] = colour
|
||
|
||
F chardisplay()
|
||
V txt = .map.map(row -> row.map(bit -> (I bit == @@.background {‘ ’} E ‘@’)).join(‘’))
|
||
txt = txt.map(row -> ‘|’row‘|’)
|
||
txt.insert(0, ‘+’(‘-’ * .width)‘+’)
|
||
txt.append(‘+’(‘-’ * .width)‘+’)
|
||
print(reversed(txt).join("\n"))
|
||
|
||
F set(x, y, colour = black)
|
||
.map[y][x] = colour
|
||
|
||
F get(x, y)
|
||
R .map[y][x]
|
||
|
||
V bitmap = Bitmap(20, 10)
|
||
bitmap.fillrect(4, 5, 6, 3)
|
||
assert(bitmap.get(5, 5) == black)
|
||
assert(bitmap.get(0, 1) == white)
|
||
bitmap.set(0, 1, black)
|
||
assert(bitmap.get(0, 1) == black)
|
||
bitmap.chardisplay()
|