Advertisement
neongm

Untitled

Oct 6th, 2022
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. from .dosplay import Screen
  2. from abc import ABC, abstractmethod
  3.  
  4.  
  5.  
  6. class Renderer(ABC):
  7.     @abstractmethod
  8.     def Clear(self): pass
  9.    
  10.     @abstractmethod
  11.     def SetScreenSize(self, height, width): pass
  12.    
  13.     @abstractmethod
  14.     def PutPixel(self, pixelValue, x, y): pass
  15.  
  16.     @abstractmethod
  17.     def PutString(self, x, y, string): pass
  18.    
  19.     @abstractmethod
  20.     def FillQuad(self, x, y): pass
  21.    
  22.     @abstractmethod
  23.     def Render(self): pass
  24.    
  25.    
  26.  
  27. # Pdosplay to Renderer adapter
  28. class PdosplayAdapt(Renderer):
  29.     def __init__(self):
  30.         self._renderer = Screen()
  31.         self._palette = [' ', '.', ',', '-', '=', 'n', 'w', 'W', '#', '@']
  32.         #self._palette = ['@', '#', 'W', 'w', '.', 'n', 'w', 'W', '#', '@']
  33.         self.ScaledVram = []
  34.    
  35.     def Clear(self):
  36.         self._renderer.clear_vram()
  37.    
  38.     def SetScreenSize(self, height, width):
  39.         self._renderer.setup_size(xsize=width, ysize=height)
  40.    
  41.     def PutPixel(self, pixelValue, x, y):
  42.         pixelBrightness = 0
  43.         if x*y > len(self._renderer.vram):
  44.             raise Exception("ERROR: OutOfRange")
  45.            
  46.         if type(pixelValue) == tuple:
  47.             pixelBrightness = self._RGBToBrightness(pixelValue[0]/256, pixelValue[1]/256, pixelValue[2]/256)
  48.         elif type(pixelValue) == float: pixelBrightness = pixelValue
  49.        
  50.         #if pixelBrightness == 0: pixelBrightness+=1
  51.         char = self._palette[int(pixelBrightness * len(self._palette))]
  52.        
  53.         self._renderer.vin(char, x, y)
  54.        
  55.        
  56.     def PutString(self, x, y, string):
  57.         self._renderer.vin(string, x, y)
  58.        
  59.     def FillQuad(self, x, y): pass
  60.    
  61.     def Render(self):
  62.         self._renderer.render()
  63.    
  64.     # auxiliarry    
  65.     def _RGBToBrightness(self, R, G, B):
  66.         return (0.2126*R + 0.7152*G + 0.0722*B)
  67.         #return (R+R+B+G+G+G)/6
  68.    
  69.    
  70.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement