broke different generative methods out into separate file
This commit is contained in:
64
gen.py
Normal file
64
gen.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import turtle
|
||||||
|
import random
|
||||||
|
|
||||||
|
def first(steps):
|
||||||
|
window = turtle.Screen()
|
||||||
|
|
||||||
|
win_height = window.window_height()
|
||||||
|
win_width = window.window_width()
|
||||||
|
|
||||||
|
asdf = turtle.Turtle()
|
||||||
|
window.tracer(delay=None)
|
||||||
|
asdf.hideturtle()
|
||||||
|
y=0
|
||||||
|
x = 1
|
||||||
|
|
||||||
|
history = []
|
||||||
|
|
||||||
|
print(win_width)
|
||||||
|
print(win_width)
|
||||||
|
def getRandom(x, direc):
|
||||||
|
|
||||||
|
r = random.randrange(x)
|
||||||
|
# pos = asdf.pos()
|
||||||
|
# print(pos)
|
||||||
|
# print(pos[1]+r)
|
||||||
|
# print(pos[1]-r)
|
||||||
|
|
||||||
|
# if pos[1] + r > win_height or pos[1] - r < -1*win_height:
|
||||||
|
# print(pos[1] + r)
|
||||||
|
# r=r/2
|
||||||
|
# print('hit')
|
||||||
|
# elif pos[0] + r > win_width or pos[0] -r < -1*win_width:
|
||||||
|
# r=r/2
|
||||||
|
# print('side hit')
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
# while y < 10:
|
||||||
|
# while x < 215:
|
||||||
|
# asdf.forward(x)
|
||||||
|
# asdf.left(x)
|
||||||
|
#
|
||||||
|
# print('forward: '+str(x))
|
||||||
|
# # print('left: '+str(x*x))
|
||||||
|
# x = x + 1
|
||||||
|
# asdf.right(x)
|
||||||
|
# x = 0
|
||||||
|
# y=y+1
|
||||||
|
|
||||||
|
while x<steps:
|
||||||
|
direc = random.randrange(5)
|
||||||
|
r = getRandom(x, direc)
|
||||||
|
if direc == 0:
|
||||||
|
asdf.forward(r)
|
||||||
|
elif direc == 1:
|
||||||
|
asdf.backward(r)
|
||||||
|
elif direc == 2:
|
||||||
|
asdf.left(r)
|
||||||
|
elif direc == 3:
|
||||||
|
asdf.right(r)
|
||||||
|
history.append([direc,r])
|
||||||
|
x=x+1
|
||||||
|
return history
|
||||||
|
|
||||||
66
main.py
66
main.py
@@ -1,63 +1,7 @@
|
|||||||
import turtle, random
|
import first
|
||||||
|
steps = 215
|
||||||
window = turtle.Screen()
|
history = []
|
||||||
|
|
||||||
win_height = window.window_height()
|
|
||||||
win_width = window.window_width()
|
|
||||||
|
|
||||||
asdf = turtle.Turtle()
|
|
||||||
window.tracer(delay=None)
|
|
||||||
asdf.hideturtle()
|
|
||||||
y=0
|
|
||||||
x = 1
|
|
||||||
|
|
||||||
step = []
|
|
||||||
|
|
||||||
print(win_width)
|
|
||||||
print(win_width)
|
|
||||||
def getRandom(x, direc):
|
|
||||||
|
|
||||||
r = random.randrange(x)
|
|
||||||
pos = asdf.pos()
|
|
||||||
print(pos)
|
|
||||||
print(pos[1]+r)
|
|
||||||
print(pos[1]-r)
|
|
||||||
|
|
||||||
# if pos[1] + r > win_height or pos[1] - r < -1*win_height:
|
|
||||||
# print(pos[1] + r)
|
|
||||||
# r=r/2
|
|
||||||
# print('hit')
|
|
||||||
# elif pos[0] + r > win_width or pos[0] -r < -1*win_width:
|
|
||||||
# r=r/2
|
|
||||||
# print('side hit')
|
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
||||||
# while y < 10:
|
|
||||||
# while x < 215:
|
|
||||||
# asdf.forward(x)
|
|
||||||
# asdf.left(x)
|
|
||||||
#
|
|
||||||
# print('forward: '+str(x))
|
|
||||||
# # print('left: '+str(x*x))
|
|
||||||
# x = x + 1
|
|
||||||
# asdf.right(x)
|
|
||||||
# x = 0
|
|
||||||
# y=y+1
|
|
||||||
|
|
||||||
while x<15:
|
|
||||||
direc = random.randrange(5)
|
|
||||||
r = getRandom(x, direc)
|
|
||||||
if direc == 0:
|
|
||||||
asdf.forward(r)
|
|
||||||
elif direc == 1:
|
|
||||||
asdf.backward(r)
|
|
||||||
elif direc == 2:
|
|
||||||
asdf.left(r)
|
|
||||||
elif direc == 3:
|
|
||||||
asdf.right(r)
|
|
||||||
step.append([direc,r])
|
|
||||||
x=x+1
|
|
||||||
print(step)
|
|
||||||
|
|
||||||
|
history = first.first(steps)
|
||||||
|
|
||||||
|
print(history)
|
||||||
Reference in New Issue
Block a user