35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from casioplot import set_pixel
|
|
|
|
class SpriteIndexed:
|
|
def __init__(self, w: int, h: int, data):
|
|
self.w = w
|
|
self.h = h
|
|
self.data = data
|
|
def draw(self, x: int, y: int, pallet: dict) -> None:
|
|
i = 0
|
|
for yoff in range(self.h):
|
|
for xoff in range(self.w):
|
|
data_cell = self.data[i]
|
|
if data_cell and data_cell != " ":
|
|
set_pixel(x + xoff, y + yoff, pallet[data_cell])
|
|
i += 1
|
|
def to_raw(self, pallet: dict):
|
|
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 draw(self, x: int, y: int) -> None:
|
|
i = 0
|
|
for yoff in range(self.h):
|
|
for xoff in range(self.w):
|
|
data_cell = self.data[i]
|
|
if data_cell:
|
|
set_pixel(x + xoff, y + yoff, data_cell)
|
|
i += 1
|