Skip to content

Commit

Permalink
Update bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
thornySoap committed Apr 1, 2023
1 parent b56f54f commit a1263ef
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/nspire/pathlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Allow values to be stored on Nspire"""
from ti_system import recall_value, store_value


class Path:
def __init__(self, path):
self.path = path

def __getattr__(self, item):
if item == "parent":
return self

def __truediv__(self, other):
self.path = other
return self

def resolve(self):
return self

def exists(self):
try:
recall_value(self.path)
except TypeError:
return False
else:
return True

def touch(self):
if not self.exists:
self.reset()

def reset(self):
store_value(self.path, 0)

def read_text(self):
return str(recall_value(self.path))

def write_text(self, text):
store_value(self.path, int(text))
9 changes: 7 additions & 2 deletions src/pygame/pygame.py → src/nspire/pygame.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def draw(self, pos):
self.color.set()
pos = Vector2(pos).flip_y()
draw_text(pos.x, pos.y, self.text)

def get_size(self):
return Vector2(len(self.text) * 7, -12)

Expand All @@ -175,6 +175,12 @@ def flip_y(self):
def copy(self):
return Vector2(self.x, self.y)

def length(self):
return (self.x ** 2 + self.y ** 2) ** 0.5

def normalize(self):
return self / self.length()

def __iter__(self):
return iter((self.x, self.y))

Expand Down Expand Up @@ -293,4 +299,3 @@ def __iter__(self):

def set(self):
set_color(self.r, self.g, self.b)

0 comments on commit a1263ef

Please sign in to comment.