Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from .dosplay import Screen
- from abc import ABC, abstractmethod
- class Renderer(ABC):
- @abstractmethod
- def Clear(self): pass
- @abstractmethod
- def SetScreenSize(self, height, width): pass
- @abstractmethod
- def PutPixel(self, pixelValue, x, y): pass
- @abstractmethod
- def PutString(self, x, y, string): pass
- @abstractmethod
- def FillQuad(self, x, y): pass
- @abstractmethod
- def Render(self): pass
- # Pdosplay to Renderer adapter
- class PdosplayAdapt(Renderer):
- def __init__(self):
- self._renderer = Screen()
- self._palette = [' ', '.', ',', '-', '=', 'n', 'w', 'W', '#', '@']
- #self._palette = ['@', '#', 'W', 'w', '.', 'n', 'w', 'W', '#', '@']
- self.ScaledVram = []
- def Clear(self):
- self._renderer.clear_vram()
- def SetScreenSize(self, height, width):
- self._renderer.setup_size(xsize=width, ysize=height)
- def PutPixel(self, pixelValue, x, y):
- pixelBrightness = 0
- if x*y > len(self._renderer.vram):
- raise Exception("ERROR: OutOfRange")
- if type(pixelValue) == tuple:
- pixelBrightness = self._RGBToBrightness(pixelValue[0]/256, pixelValue[1]/256, pixelValue[2]/256)
- elif type(pixelValue) == float: pixelBrightness = pixelValue
- #if pixelBrightness == 0: pixelBrightness+=1
- char = self._palette[int(pixelBrightness * len(self._palette))]
- self._renderer.vin(char, x, y)
- def PutString(self, x, y, string):
- self._renderer.vin(string, x, y)
- def FillQuad(self, x, y): pass
- def Render(self):
- self._renderer.render()
- # auxiliarry
- def _RGBToBrightness(self, R, G, B):
- return (0.2126*R + 0.7152*G + 0.0722*B)
- #return (R+R+B+G+G+G)/6
Advertisement
Add Comment
Please, Sign In to add comment