nativelosa.blogg.se

Red and green bounce balls
Red and green bounce balls







red and green bounce balls

X, y, dx, dy, color = moveball(x, y, dx, dy, color) Move the balls in the application loop: def moveball(x, y, dx, dy, color): Y = random.randint(radius, screensize-radius)Ĭrate the 3 balls and store them to the variables as suggested in the assignment ( x2, y2, dx2, dy2): x, y, dx, dy, color = createball()Ĭreate a function ( moveball) which can move a ball, change there direction when the hit the bounds and change the color. X = random.randint(radius, screensize-radius) Create a certain number of ball ( max_balls) with random positions ( random.randint(a, b)) and random colors ( random.choice(seq)): radius = 25 A ball is a tuple of x and y position, the movement vector dx, dy and the color ( (x, y, dx, dy, color)). _caption("Animation Test")Ĭreate a function ( createball) which can crate a random ball. If someone could please help I literally cannot figure this out. I can't figure out how to make two more balls and have them change color each time they hit a wall. The code so far has the first ball bouncing and staying the same color. Here is my code so far, I am using Python 3.7 on a Mac.

red and green bounce balls

Level 4 Challenge: when the balls hit the wall and the colors change to make each color randomly change. Hint: you will need to create all new variables for each ballĪnd you will need to check each ball individually for hitting a wall and update the vertical and horizontal position of each ball individually. They will all bounce around continuously.

red and green bounce balls

The assignment is this:Īdd 2 other balls to the screen (3 in total) that will all be different colors, different sizes and start in different directions. I'm working on a project to make an animation in pygame.









Red and green bounce balls