Skip to content

Commit

Permalink
fix drawing colors when under range of 1-24
Browse files Browse the repository at this point in the history
  • Loading branch information
TabulateJarl8 committed Jul 18, 2021
1 parent 1ea2db5 commit 32dce4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ti842py/__version__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = "ti842py"
__description__ = "TI-BASIC to Python 3 Transpiler"
__url__ = "https://github.com/TabulateJarl8/ti842py"
__version__ = "0.8.3"
__version__ = "0.8.4"
__author__ = "Tabulate"
__author_email__ = "[email protected]"
__license__ = "GPLv3"
Expand Down
27 changes: 12 additions & 15 deletions ti842py/utils/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
GRAY = 23
DARKGRAY = 24

class InvalidColorError(Exception):
pass

class Draw:
def __init__(self):
self.win = None
self.winOpen = False
self.pixels = {}
self.points = {}
self.texts = {}
self.colors = {'BLUE': 'blue', 'RED': 'red', 'BLACK': 'black', 'MAGENTA': 'magenta', 'GREEN': 'green', 'ORANGE': 'orange', 'BROWN': 'brown', 'NAVY': 'navy', 'LTBLUE': 'light sky blue', 'YELLOW': 'yellow', 'WHITE': 'white', 'LTGRAY': 'light gray', 'MEDGRAY': 'dark gray', 'GRAY': 'gray', 'DARKGRAY': 'dark slate gray'}
self.colorNumbers = {'10': 'blue', '11': 'red', '12': 'black', '13': 'magenta', '14': 'green', '15': 'orange', '16': 'brown', '17': 'navy', '18': 'light sky blue', '19': 'yellow', '20': 'white', '0': 'white', '21': 'light gray', '22': 'dark gray', '23': 'gray', '24': 'dark slate gray'}
self.colors = {'10': 'blue', '11': 'red', '12': 'black', '13': 'magenta', '14': 'green', '15': 'orange', '16': 'brown', '17': 'navy', '18': 'light sky blue', '19': 'yellow', '20': 'white', '0': 'white', '21': 'light gray', '22': 'dark gray', '23': 'gray', '24': 'dark slate gray'}
for _ in range(1, 10):
self.colorNumbers[str(_)] = 'blue'
self.colors[str(_)] = 'blue'
self.currentTextColor = 'blue'

def _slow(function):
Expand Down Expand Up @@ -63,19 +65,14 @@ def graphCoordsToPixels(self, x, y, minX=-10, maxX=10, minY=-10, maxY=10):

def tiColorToGraphicsColor(self, color, isBackground=False):
color = str(color)
for color1, color2 in self.colors.items():
color = color.replace(color1, color2)
color = re.sub(r'(\d+)', lambda m: self.colorNumbers.get(m.group(), '[ERR:DOMAIN]'), color)
original_color = color

if color.find('-') != -1: # negative numbers
raise InvalidColorError(f'The specified color value "{original_color}" was not in range 1-24')
color = re.sub(r'(\d+)', lambda m: self.colors.get(m.group(), '[ERR:DOMAIN]'), color)
if '[ERR:DOMAIN]' in color:
raise ValueError('The specified color value was not in range 1-24')
if color not in self.colors.values():
# Failsafe
if not isBackground:
print(f'WARNING: Unknown color: {color}. defaulting to blue.')
color = 'blue'
else:
print(f'WARNING: Unknown color: {color}. defaulting to white.')
color = 'white'
raise InvalidColorError(f'The specified color value "{original_color}" was not in range 1-24')

return color

@_slow
Expand Down

0 comments on commit 32dce4f

Please sign in to comment.