# Imported Modules for Randomization and Turtle
import turtle as trtl
import random as rand
from random import *
# Painter Configuration and Screen Configuration
painter = trtl.Turtle()
distanceForward = 20
painter.pensize(5)
painter.speed(10000000)
painter.screen.setup(1000, 1000)
walls = 32
#This for loop is essential--> it creates 32 lines, and based on the conditions below, adds walls, barriers, and exits
for i in range(walls):
#Register the beginning position of the Turtle.
xBeginCor = painter.xcor()
yBeginCor = painter.ycor()
#Variables for randomization of Exits and Doors
initialWallDistance = randint(1, distanceForward-5)
doorDistance = randint(1,distanceForward-18)
#Program for the Walls and their Randomization
#Prevents the last 4 lines having barriers protruding
#We feel this method of randomizing the wall distance was really innovative and that it works pretty well
if i < walls - 4:
painter.penup()
painter.forward(initialWallDistance)
painter.left(90)
painter.pendown()
painter.forward(30)
painter.backward(30)
painter.right(90)
painter.penup()
#Preventing overlapping for the Walls and Doors. This does not work perfectly, and sometimes the doors are too small as a result of this
if doorDistance == range(0, 21):
doorDistance + 20
painter.forward(distanceForward - initialWallDistance)
else:
painter.forward(distanceForward - initialWallDistance)
#Creates the randomization of the doors. This works really well, as it makes the turtle go a random distance forward from the beginning of the line, and create a door
painter.goto(xBeginCor, yBeginCor)
painter.pendown()
painter.forward(doorDistance)
painter.penup()
painter.forward(20)
painter.pendown()
painter.forward(distanceForward-doorDistance)
#Turn the turtle to create the next line
painter.right(90)
#Change the length of the line so the next one is a longer distance
distanceForward += 15
#Keeps window open
wn = trtl.Screen()
wn.mainloop()
I need help stopping these doors and barriers happening on top of each other. I have also attached an image describing what I mean.
This code here is what I am working on to prevent the two from going on top of each other:
if doorDistance == range(0, 21):
doorDistance + 20
painter.forward(distanceForward - initialWallDistance)
else:
painter.forward(distanceForward - initialWallDistance)
Nothing is working. At this point I am completely confused, and I have no idea what I am doing. Any explanations/help would be appreciated
Note: I am a beginner, so I will not be able to use any complex techniques