55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from casioplot import set_pixel, get_pixel
|
|
|
|
class SpriteIndexed:
|
|
def __init__(self, w: int, h: int, data):
|
|
self.w = w
|
|
self.h = h
|
|
self.data = data
|
|
def _get_data(self, index: int, pallet: dict):
|
|
value = self.data[index]
|
|
if value == " ":
|
|
return None
|
|
return pallet[value]
|
|
def draw(self, x: int, y: int, pallet: dict) -> None:
|
|
i = 0
|
|
for yoff in range(self.h):
|
|
for xoff in range(self.w):
|
|
value = self._get_data(i, pallet)
|
|
if value:
|
|
set_pixel(x + xoff, y + yoff, value)
|
|
i += 1
|
|
def to_raw(self, pallet: dict) -> SpriteRaw:
|
|
raw_data = []
|
|
for i in range(len(self.data)):
|
|
data_cell = self.data[i]
|
|
if data_cell and data_cell != " ":
|
|
raw_data.append(pallet[data_cell])
|
|
else:
|
|
raw_data.append(None)
|
|
return SpriteRaw(self.w, self.h, raw_data)
|
|
|
|
class SpriteRaw(SpriteIndexed):
|
|
def _get_data(self, index: int, placeholder: None) -> tuple:
|
|
return self.data[index]
|
|
def draw(self, x: int, y: int) -> None:
|
|
SpriteIndexed.draw(self, x, y, None)
|
|
def to_raw(self) -> None:
|
|
return None
|
|
|
|
def rect(x: int, y: int, w: int, h: int, color: tuple) -> None:
|
|
for i in range(x, x + w):
|
|
for j in range(y, y + h):
|
|
set_pixel(i, j, color)
|
|
|
|
def fill_screen(color: tuple) -> None:
|
|
rect(0, 0, 384, 192, color)
|
|
|
|
def invert_pixel(x: int, y: int) -> None:
|
|
ocolor = get_pixel(x, y)
|
|
set_pixel(x, y, (255 - ocolor[0], 255 - ocolor[1], 255 - ocolor[2]))
|
|
|
|
def invert_rect(x: int, y: int, w: int, h: int) -> None:
|
|
for i in range(x, x + w):
|
|
for j in range(y, y + h):
|
|
invert_pixel(i, j)
|