Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions act1_cowabunga.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# CHANGEME
# turn angle 90
replacementRules = {
"x": "x+yf+",
"y": "-fx-y",
"+": "+",
"-": "-",
"f": "f"
}

def generateCowabunga(generations):
print("initialized and running")
# CHANGEME
axiom = "fx"
structure = ""
for _ in range(generations):
print(f"gen {_} starting")
if (structure):
axiom = structure
structure = ""
for _ in axiom:
print(f"{structure}")
structure += replacementRules[_]
axiom = structure
return structure
Binary file added carl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@





actions = {
"f" : "go forward",
"+" : "turn right",
"-": "turn left"
}




# import turtle

# t = turtle.Turtle()


# def forward():
# return t.forward(50)
# def left():
# return t.left(90)
# def right():
# return t.right(90)

# actions = {
# "f" : forward,
# "+": right,
# "-": left
# }

# for letter in "f+f+f+f":

# actions[letter]()















37 changes: 37 additions & 0 deletions driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import turtle
import code
import sys

import pathlib
import importlib.util
import argparse

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('files', metavar='FILES', type=pathlib.Path, nargs='*')
args = parser.parse_args()

screen = turtle.Screen()
canvas = screen.getcanvas()
tk = canvas.winfo_toplevel()
tk.attributes('-fullscreen', True)

screen.title("Python Turtle on Replit")
screen.setup(1.0, 1.0)

print("Python turtle on Replit")
modules = []
for path in args.files:
spec = importlib.util.spec_from_file_location(path.stem, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
modules.append(module)

locals = {}
if len(modules) > 0:
main = modules[0]
locals = {attr: getattr(main, attr) for attr in dir(main)}

sys.ps1 = "\u001b[33m\uEEA7\u001b[00m "
code.interact(local=locals, banner='')

screen.mainloop()
29 changes: 29 additions & 0 deletions ex_arrow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
FX Axiom
X -> YF+XF+Y Rule 1
Y -> XF-YF-X Rule 2
angle = 60
"""

replacementRules = {
"x": "yf+xf+y",
"y": "xf-yf-x",
"+": "+",
"-": "-",
"f": "f"
}

def generateArrow(generations):
print("initialized and running")
axiom = "fx"
structure = ""
for _ in range(generations):
print(f"gen {_} starting")
if (structure):
axiom = structure
structure = ""
for _ in axiom:
print(f"{structure}")
structure += replacementRules[_]
axiom = structure
return structure
29 changes: 29 additions & 0 deletions ex_dragon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
AXIOM: fx
RULES:

x -> x+yf+
y -> -fx-y

"""


replacementRules = {
"x": "x+yf+",
"y": "-fx-y",
"+": "+",
"-": "-",
"f": "f"
}

def generateDragon(generations):
axiom = "fx"
structure = ""
for _ in range(generations):
if (structure):
axiom = structure
structure = ""
for _ in axiom:
structure += replacementRules[_]
axiom = structure
return structure
30 changes: 30 additions & 0 deletions ex_fern.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Axiom X
F --> FF
X --> x[-fff][+fff]fx
ø = 22.5
"""

replacementRules = {
"x": "y[-fff][+fff]fy",
"y": "yfx[+y][-y]",
"+": "+",
"-": "-",
"f": "f",
"[": "[",
"]": "]"
}

def generateFern(generations):
axiom = "yy"
structure = ""
for _ in range(generations):
print(f"gen {_}")
if (structure):
axiom = structure
structure = ""
for _ in axiom:
structure += replacementRules[_]
print(structure)
axiom = structure
return structure
28 changes: 28 additions & 0 deletions ex_weave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Axiom F+F+F+F
F --> FF+F-F+F+FF
ø = 90
"""

replacementRules = {
"x": "",
"y": "",
"+": "+",
"-": "-",
"f": "ff+f-f+f+ff"
}

def generateWeave(generations):
print("initialized and running")
axiom = "f+f+f+f"
structure = ""
for _ in range(generations):
print(f"gen {_} starting")
if (structure):
axiom = structure
structure = ""
for _ in axiom:
print(f"{structure}")
structure += replacementRules[_]
axiom = structure
return structure
84 changes: 84 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# File for running all turtle code and generating structure
import turtle
from act1_cowabunga import generateCowabunga
from ex_dragon import generateDragon
from ex_fern import generateFern
from ex_arrow import generateArrow
from ex_weave import generateWeave

# initialization
t = turtle.Turtle()
t.shape("turtle")
t.speed(10)
t.left(90)

# This variable determines how far the turtle
# moves everytime we call the goForward function
moveDistance = 10
# The angle at which the turtle runs
turnAmount = 22.5
# Fancy Computer-Sciency data structure that helps us
# keep track of all the coordinates we visit while generating structures with turtle
stack = []


#Enables the turle to go forward by the distance, moveDistance
def goForward():
t.forward(moveDistance)


# Turns the turtle left by the turn amount
def goLeft():
t.left(turnAmount)


# Turns the turtle right by the turn amount
def goRight():
t.right(turnAmount)


# 10 points if you can guess what this does!
def doNothing():
pass


# Put stuff onto the stack (fancy CS data strucutre)
def pushStack():
coor = t.position()
stack.append(coor)
# print(f"pushed {coor}")


# Get stuff out of the stack (fancy CS data strucutre)
def popStack():
coor = stack.pop()
t.penup()
t.goto(coor)
t.pendown()
# print(f"popped {coor}")


# Map stuff from our replacement rules to the functions above
actions = {
"f": goForward,
"+": goLeft,
"-": goRight,
"x": doNothing,
"y": doNothing,
"[": pushStack,
"]": popStack
}

# Generates the structure according to the given code
def run(structure):
for i in structure:
actions[i]()


# # Run this!
# run(generateCowabunga(5))
# examples
# run(generateDragon(10)) #angle = 90
run(generateFern(5)) #angle = 22.5
# run(generateArrow(7)) #angle = 60
# run(generateWeave(3)) #angle = 90
2 changes: 1 addition & 1 deletion panAndZoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def setListens():

def initialize():
setListens()
listen()
listen()