

And made the color advance through the list of colors (in a circular fashion) instead of choosing one (possibly the same one) at random. You'll notice I changed it from using left and right 90 degree turns to using absolute headings to control the ball bouncing off the walls. If not CURSOR_SIZE/2 - WIDTH/2 <= tx <= WIDTH/2 - CURSOR_SIZE/2: If not CURSOR_SIZE/2 - HEIGHT/2 <= ty <= HEIGHT/2 - CURSOR_SIZE/2: And center it on the screen: from turtle import TurtleĬOLORS = And parameterize it so you can change your rectangle size and stil have it work without fixing up lots of lines of code. I believe we can fix your program and simplify it. I make better code for changing the color so you always change color for turtle. Sometimes when turtle change color random.choice(color) turns the color into the same as it is. Overall, this is a fantastic toy for keeping your dog’s attention. This toy is excellent for dogs of various sizes, but it’s probably perfect for smaller dogs. It also can make squeaking sounds, which likely interest your dog. You make some mistakes in angle direction change, when you have to set angle right +90 you set angle left +90 or when you have to set angle left +90 you set angle right +90 in left, right and bottom wall collision. The motor-driven ball will make the toy bounce and shake. I'm completely lost, so any advice/help would be much appreciated. What I tried to do was divide the rectangle into 4 sections based on the degree its setheading is, but that doesn't seem to be working I'm a beginner, and I've been trying to figure this out for a while. I have to write a code for a computer science class that makes a turtle bounce around a rectangle, and also changes color every time it does this.
