Write a program to animate a circle bouncing around a window. The basic idea is to start | StudySoup

Textbook Solutions for Python Programming: An Introduction to Computer Science

Chapter 7 Problem 17

Question

Write a program to animate a circle bouncing around a window. The basic idea is to start the circle somewhere in the interior of the window. Use variables dx and dy (both initialized to 1) to control the movement of the circle. Use a large counted loop (say 10000 iterations), and each time through the loop move the circle using dx and dy . When the x-value of the center of the circle gets too high (it hits the edge), change dx to -1. When it gets too low, change dx back to 1. Use a similar approach for dy . Note: Your animation will probably run too fast. You can slow it down by using update from the graphics library with a rate parameters. For example, this loop will be limited to going around at a rate of 30 times per second: for i in range ( 10000) : 241 update (30) # pause so rate is not more than 30 times a second

Solution

Step 1 of 7)

The first step in solving 7 problem number 40 trying to solve the problem we have to refer to the textbook question: Write a program to animate a circle bouncing around a window. The basic idea is to start the circle somewhere in the interior of the window. Use variables dx and dy (both initialized to 1) to control the movement of the circle. Use a large counted loop (say 10000 iterations), and each time through the loop move the circle using dx and dy . When the x-value of the center of the circle gets too high (it hits the edge), change dx to -1. When it gets too low, change dx back to 1. Use a similar approach for dy . Note: Your animation will probably run too fast. You can slow it down by using update from the graphics library with a rate parameters. For example, this loop will be limited to going around at a rate of 30 times per second: for i in range ( 10000) : 241 update (30) # pause so rate is not more than 30 times a second
From the textbook chapter Decision Structures you will find a few key concepts needed to solve this.

Step 2 of 7)

Visible to paid subscribers only

Step 3 of 7)

Visible to paid subscribers only

Subscribe to view the
full solution

Title Python Programming: An Introduction to Computer Science 3 
Author John Zelle
ISBN 9781590282755

Write a program to animate a circle bouncing around a window. The basic idea is to start

Chapter 7 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back