I have a code here that changes turtle to a ball and allows the user to move a ball around.
I want it to change background colors when the ball's x value decreases from (30,0) but is there a way to do this? if possible, i want the background color to change back to white if the ball's x value rises past 30 again.
# import turtle setup
from turtle import Screen, Turtle
TURTLE_SIZE = 200
# functions
def go_left():
x = t.xcor()
if x > TURTLE_SIZE - 576:
x -= 5
t.setx(x)
screen.update()
def go_right():
x = t.xcor()
if x < 576 - TURTLE_SIZE:
x += 5
t.setx(x)
screen.update()
def go_up():
y = t.ycor()
if y < 576 - TURTLE_SIZE:
y += 5
t.sety(y)
screen.update()
def go_down():
y = t.ycor()
if y < 576 - TURTLE_SIZE:
y -= 5
t.sety(y)
screen.update()
# screen
screen = Screen()
screen.setup(1152,648)
screen.tracer(0)
t = Turtle()
t.shape("circle")
t.speed("slow")
t.color("blue")
t.penup()
t.setx(338)
t.sety(0)
screen.update()
# Keyboard (listeners)
screen.onkeypress(go_left, "Left")
screen.onkeypress(go_down, "Down")
screen.onkeypress(go_up, "Up")
screen.onkeypress(go_right, "Right")
screen.listen()
screen.mainloop()
if x < 30 - TURTLE_SIZE:
screen.bgcolor("darkred")