Matthilde 1 year ago
parent
commit
f60d162f72
  1. 35
      trc.py
  2. 7
      turtlec.py

35
trc.py

@ -13,14 +13,26 @@ turtle_stdout = "" @@ -13,14 +13,26 @@ turtle_stdout = ""
turtle_pos = 1
file_lines = 0
turtle_quotes = [
"*yawn* this is tiring, imma sleep for a bit...",
"o hewwo! i hope you having a nice day :)",
"i hope i am doing it well....",
"this program is very interesting...",
"Achoo! Sowwie >.>"]
ttqq = turtle_quotes.copy()
random.shuffle(ttqq)
def turtle_update():
global turtle_stderr
global turtle_stderr, ttqq
_clear()
n = random.randint(0, 50)
w = 5 if n == 24 else random.randint(5, 40) / 100
n = random.randint(0, 100)
w = 5 if n == 24 else random.randint(5, 30) / 100
if n == 24:
turtle_stderr += "*yawn* this is tiring, imma sleep for a bit...\n"
if ttqq == []:
ttqq = turtle_quotes.copy()
random.shuffle(ttqq)
turtle_stderr += ttqq.pop() + '\n'
tp = math.floor((turtle_pos / file_lines) * 20)
print(' '*tp + 'o')
print('-'*20 + '[GOAL!]\n')
@ -82,7 +94,7 @@ def turtle_introduction(): @@ -82,7 +94,7 @@ def turtle_introduction():
print("[Turtle]", quote, end=' ')
input()
def main(fn):
def main(fn, args):
global file_lines, turtle_stderr, turtle_pos
file_lines = len(fn.split('\n'))
@ -93,6 +105,8 @@ def main(fn): @@ -93,6 +105,8 @@ def main(fn):
env["wOa"] = turtle_wOa
env["wOA"] = turtle_wOA
env["woA"] = turtle_woA
env["TurtleArgv"] = argv2turtle(args)
try:
ast = build_ast(tokenize(fn), ppre = turtle_ppre)
for line in ast:
@ -119,12 +133,15 @@ Error at line {e.linenum}: {e.err} @@ -119,12 +133,15 @@ Error at line {e.linenum}: {e.err}
turtle_update()
if __name__ == "__main__":
if len(sys.argv) != 2:
print("USAGE: trci FILENAME")
if len(sys.argv) < 2:
print("USAGE: trci FILENAME ...")
sys.exit(1)
else:
try:
with open(sys.argv[1]) as f:
main(f.read())
main(f.read(), sys.argv[2:])
except IOError:
print("Could not open the file")
except KeyboardInterrupt:
_clear()
print("Why are you abandonning me like that ;_;...")

7
turtlec.py

@ -142,8 +142,11 @@ def _builtin_TurtleRead(env, fn): @@ -142,8 +142,11 @@ def _builtin_TurtleRead(env, fn):
"filename muust be an array of integers."
afn += chr(c.value)
with open(afn, "r") as f:
return TurtleArray([TurtleInteger(ord(x)) for x in f.read()])
try:
with open(afn, "r") as f:
return TurtleArray([TurtleInteger(ord(x)) for x in f.read()])
except IOError:
raise AssertionError("could not read the file.")
def _builtin_TurtleLength(env, arr):
assert type(arr(env)) == TurtleArray, "must be an array."

Loading…
Cancel
Save