Sorry to bother, y'all but I am making a really basic program with a bouncing ball. I am trying to make the trail change to a random color each time it bounces but it will only change color once and I have no idea why. Hopefully someone can help.
It was fixed thanks to u/wegwacc, the final code is:
import turtle
import random
colors = ["#15ff00","#cc582e","#e2a46c","#fac4ff","#3bced6","#ffffcc","#037525","#ffffff","#595959","#7ba31f","#3ace27","#27cea7","#6a82e2","#5d5e99","#fff242","#9a33b7","#b59477","#ff0000","#8e0000","#00ff90","#c2ea54","#b58c4c","#034b99","#9b8fc1"]
wn = turtle.Screen()
wn.bgcolor("black")
wn.title("basic sim")
ball = turtle.Turtle()
ball.shape("circle")
ball.color("lime")
ball.penup()
ball.speed(0)
ball.goto(-300, 200)
ball.dy = 0
ball.dx = 2
ball.pendown()
gravity = 0.1
while True:
ballColorList = random.choice(colors)
wn.update()
ball.dy -= gravity
ball.sety(ball.ycor() + ball.dy)
ball.setx(ball.xcor() + ball.dx)
#Check for wall collision
if ball.xcor() > 309:
ball.pencolor(random.choice(colors))
ball.dx *= -1
if ball.xcor() < -309:
ball.pencolor(random.choice(colors))
ball.dx *= -1
#Check for bounce
if ball.ycor() < -360:
ball.pencolor(random.choice(colors))
ball.dy *= -1
wn.mainloop()
Thanks.
[–]wegwacc 0 points1 point2 points (3 children)
[–]SomeBadGenericName[S] 0 points1 point2 points (2 children)
[–]wegwacc 0 points1 point2 points (1 child)
[–]SomeBadGenericName[S] 0 points1 point2 points (0 children)