(sprito.py) File added

This commit is contained in:
KikooDX 2020-04-09 18:08:00 +02:00
parent c70103d97c
commit 3ef2a4577f
1 changed files with 34 additions and 0 deletions

34
sprito.py Normal file
View File

@ -0,0 +1,34 @@
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