-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b10a9f
commit a083dd7
Showing
7 changed files
with
619 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.3.1" | ||
__version__ = "0.4.0" | ||
__author__ = "Tabulate" | ||
__author_email__ = "[email protected]" | ||
__license__ = "GPLv3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
from graphics import * | ||
import time | ||
|
||
class Draw: | ||
def __init__(self): | ||
self.win = None | ||
self.pixels = {} | ||
self.points = {} | ||
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', '21': 'light gray', '22': 'dark gray', '23': 'gray', '24': 'dark slate gray'} | ||
self.currentTextColor = 'blue' | ||
|
||
def _slow(function): | ||
def child_function(*args, **kwargs): | ||
function(*args, **kwargs) | ||
time.sleep(0.01) | ||
return child_function | ||
|
||
def openWindow(self): | ||
# The TI-84 Plus CE has a graph resolution of 250x160 pixels | ||
# Not to be confused with the screen resolution of 320x240 pixels | ||
self.win = GraphWin('ti842py', 250, 160) | ||
self.win.setBackground('white') | ||
|
||
def closeWindow(self): | ||
self.win.close() | ||
|
||
def graphCoordsToPixels(self, x, y, minX=-10, maxX=10, minY=-10, maxY=10): | ||
# Can work for vertical or horizontal coords | ||
xs = (maxX - minX) / 250 | ||
ys = (minY - maxY) / 160 | ||
horiz = (x - minX) / xs | ||
vertical = (y - maxY) / ys | ||
return horiz, vertical | ||
|
||
def tiColorToGraphicsColor(self, color): | ||
color = str(color) | ||
for color1, color2 in self.colors.items(): | ||
color = color.replace(color1, color2) | ||
for color1, color2 in self.colorNumbers.items(): | ||
color = color.replace(color1, color2) | ||
return color | ||
|
||
@_slow | ||
def backgroundOn(self, color): | ||
self.win.setBackground(self.tiColorToGraphicsColor(color)) | ||
|
||
@_slow | ||
def backgroundOff(self): | ||
self.win.setBackground('white') | ||
|
||
def clrDraw(self): | ||
for item in self.win.items[:]: | ||
item.undraw() | ||
self.win.update() | ||
|
||
@_slow | ||
def circle(self, x, y, r, color='blue', linestyle=''): | ||
# TODO: Implement linestyle | ||
c = Circle(Point(self.graphCoordsToPixels(x), self.graphCoordsToPixels(y)), r) | ||
c.setOutline(self.tiColorToGraphicsColor(color)) | ||
c.draw(self.win) | ||
|
||
@_slow | ||
def line(self, x1, y1, x2, y2, erase=1, color='blue', style=1): | ||
# TODO: Erase and style not implemented yet | ||
x1, y1 = self.graphCoordsToPixels(x1, y1) | ||
x2, y2 = self.graphCoordsToPixels(x2, y2) | ||
line = Line(Point(x1, y1), Point(x2, y2)) | ||
line.setOutline(self.tiColorToGraphicsColor(color)) | ||
line.draw(self.win) | ||
|
||
@_slow | ||
def textColor(self, color): | ||
self.currentTextColor = self.tiColorToGraphicsColor(color) | ||
|
||
@_slow | ||
def text(self, row, column, *args): | ||
# TODO: Set font size and use row/column instead of x and y | ||
text = ''.join(args) | ||
message = Text(Point(column, row), text.upper()) | ||
message.setTextColor(self.currentTextColor) | ||
message.draw(self.win) | ||
|
||
@_slow | ||
def pxlOn(self, row, column, color='blue'): | ||
# Row = y; Column = x | ||
pnt = Point(column, row) | ||
pnt.setOutline(self.tiColorToGraphicsColor(color)) | ||
if not column in self.pixels: | ||
self.pixels[str(column)] = {} | ||
self.pixels[str(column)][str(row)] = pnt | ||
|
||
pnt.draw(self.win) | ||
|
||
@_slow | ||
def pxlOff(self, row, column): | ||
if str(column) in self.pixels: | ||
if str(row) in self.pixels[str(column)]: | ||
self.pixels[str(column)][str(row)].undraw() | ||
del self.pixels[str(column)][str(row)] | ||
|
||
@_slow | ||
def pxlTest(self, row, column): | ||
if str(column) in self.pixels and str(row) in self.pixels[str(column)]: | ||
return True | ||
return False | ||
|
||
@_slow | ||
def ptOn(self, x, y, mark=1, color='blue'): | ||
x, y = self.graphCoordsToPixels(x, y) | ||
|
||
if str(x) not in self.points: | ||
self.points[str(x)] = {} | ||
if str(y) not in self.points[str(x)]: | ||
self.points[str(x)][str(y)] = {} | ||
|
||
|
||
# If mark is unknown, it will default to 1, so test for 1 with `else` | ||
|
||
if mark in [2, 6]: | ||
# 3x3 box | ||
p1x = (x - 3 / 2) | ||
p1y = (y + 3 / 2) | ||
p2x = (x + 3 / 2) | ||
p2y = (y - 3 / 2) | ||
rec = Rectangle(Point(p1x, p1y), Point(p2x, p2y)) | ||
rec.setOutline(self.tiColorToGraphicsColor(color)) | ||
rec.draw(self.win) | ||
self.points[str(x)][str(y)][str(mark)] = (rec,) | ||
elif mark in [3, 7]: | ||
# 3x3 cross | ||
line1 = Line(Point(x - 2, y), Point(x + 2, y)) | ||
line1.setOutline(self.tiColorToGraphicsColor(color)) | ||
line1.draw(self.win) | ||
line2 = Line(Point(x, y - 2), Point(x, y + 2)) | ||
line2.setOutline(self.tiColorToGraphicsColor(color)) | ||
line2.draw(self.win) | ||
self.points[str(x)][str(y)][str(mark)] = (line1, line2) | ||
else: | ||
# Dot | ||
p1x = (x - 2 / 2) | ||
p1y = (y + 2 / 2) | ||
p2x = (x + 2 / 2) | ||
p2y = (y - 2 / 2) | ||
rec = Rectangle(Point(p1x, p1y), Point(p2x, p2y)) | ||
rec.setFill(self.tiColorToGraphicsColor(color)) | ||
rec.setOutline(self.tiColorToGraphicsColor(color)) | ||
rec.draw(self.win) | ||
self.points[str(x)][str(y)][str(mark)] = (rec,) | ||
|
||
@_slow | ||
def ptOff(self, x, y, mark=1): | ||
x, y = self.graphCoordsToPixels(x, y) | ||
if str(x) in self.points: | ||
if str(y) in self.points[str(x)]: | ||
if str(mark) in self.points[str(x)][str(y)]: | ||
for item in self.points[str(x)][str(y)][str(mark)]: | ||
item.undraw() | ||
del self.points[str(x)][str(y)][str(mark)] |
Oops, something went wrong.