The program draws the layout of the wall. According to my idea, it should draw the boundaries of the wall, move to the center and only when pressing the spacebar fill the wall with drawings, creating a design. And it should also stop when the spacebar is pressed. The problem is that with my code, it performs all tasks, except for stopping. Do you have any ideas? The picture shows the result.result The program works with files that contain color palettes.
from turtle import *
from turtle import Screen
from random import randint
import random
seinalaius=float(input("Sisestage seina laius (500-1500): "))
seinapikkus=float(input("Sisestage seina pikkus (500-900): "))
värvipalett=input("Mis värvipaletti tahaksite kasutada? (Valik: mustvalge, roosa, punane, lilla, sinine, kollane, roheline, beež, oranž): ")
screen = Screen()
fail = open(värvipalett + '.txt', encoding='UTF-8')
värvid = []
for rida in fail:
rida = rida.strip()
värvid.append(rida)
up()
goto(-seinalaius / 2, -seinapikkus / 2)
down()
for i in range(2):
forward(seinalaius)
left(90)
forward(seinapikkus)
left(90)
up()
goto(0, 0)
down()
def current_state():
global moving
moving = False
penup()
def next_state():
global moving
pendown()
moving = True
move()
def space_bar():
global current_state, next_state
next_state()
current_state, next_state = next_state, current_state
def move():
if moving:
while True:
pöörded = randint(4, 8)
begin_fill()
color(random.choice(värvid))
for i in range(pöörded):
pikkus = randint(0, 150)
up()
forward(pikkus)
if not -seinalaius / 2 <= xcor() <= seinalaius / 2 or not -seinapikkus / 2 <= ycor() <= seinapikkus / 2:
backward(pikkus)
backward(pikkus)
down()
forward(pikkus)
lr = randint(1, 2)
if lr == 1:
left(90)
else:
right(90)
speed("fastest")
end_fill()
up()
down()
current_state()
screen.onkey(space_bar, "space")
screen.listen()
screen.mainloop()
File ('sinine.txt') content:
aliceblue
aquamarine
aquamarine1
aquamarine2
aquamarine3
aquamarine4
blue
blue1
blue2
blue3
blue4
CadetBlue
CadetBlue1
CadetBlue2
CadetBlue3
CadetBlue4
CornflowerBlue
cyan
cyan1
cyan2
cyan3
cyan4
DarkBlue
DarkCyan
DarkSlateBlue
DarkSlateGray
DarkSlateGray
DarkSlateGray2
DarkSlateGray3
DarkSlateGray4
DarkSlateGrey
DarkTurquoise
DeepSkyBlue
DeepSkyBlue2
DeepSkyBlue3
DeepSkyBlue4
DodgerBlue
DodgerBlue1
DodgerBlue2
DodgerBlue3
DodgerBlue4
LightBlue
LightBlue1
LightBlue2
LightBlue3
LightBlue4
LightSeaGreen
LightSkyBlue
LightSkyBlue1
LightSkyBlue2
LightSkyBlue3
LightSkyBlue4
LightSlateGray
LightSlateGrey
LightSteelBlue
LightSteelBlue1
LightSteelBlue2
LightSteelBlue3
LightSteelBlue4
MediumAquamarine
MediumBlue
MediumSlateBlue
MediumTurquoise
midnightblue
MidnightBlue
navy
NavyBlue
PaleTurquoise
PaleTurquoise1
PaleTurquoise2
PaleTurquoise3
PaleTurquoise4
PaleVioletRed
PowderBlue
RoyalBlue
RoyalBlue1
RoyalBlue2
RoyalBlue3
RoyalBlue4
SkyBlue
SkyBlue1
SkyBlue2
SkyBlue3
SkyBlue4
SlateGray
SlateGray1
SlateGray2
SlateGray3
SlateGray4
SteelBlue
SteelBlue1
SteelBlue2
SteelBlue3
SteelBlue4
turquoise
turquoise1
turquoise2
turquoise3
turquoise4