Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help me in python? 8:01? LTE CSC 131-Computational Thinking Lab 8 For this lab, you will develop a GUI application to to animate a bouncing

help me in python?
image text in transcribed
8:01? LTE CSC 131-Computational Thinking Lab 8 For this lab, you will develop a GUI application to to animate a bouncing balL The ball will start near the top left corner of an 800 by 400 canvas. The ball will move in a 45 degrees, where it moves 2 pixels horizontally and 2 pixels vertically every 15 milliseconds. When the ball hits any of of the four edges of the canvas, it will bounce in the opposite direction. The angle of reflection is always equal to the angle of incidence. So, if the baill is moving south- east and it hits, let us say, the bottom edge, it will bounce in the north-east direction It will be easier to consider the east-west (ie., right-left) movement as independent from the north- south (i e, up-down movement). Below, you are given code to deal with the east-west movement and need to add code to deal with the north-south movement To help you with this lab, write the code in stages as follows and always make sure your code is working before you move to the nest stage. You may also nood to draw things down on a piece of paper to help you visualize things. 1. Create a GUI application with an 800 pixels by 400 pinels 2 Create a small ball starting near the top left oorner of the canvas. You can either draw a small circle, say with diameter 20 pixels, or use an imagc ofa smaill ball Identify the ball (ie, give it a tags valac) so that you can refer to in later 3. Use two variables, say top_x and top_y, to track the bal's location. This is needed to figure out when the ball hits an edge and, therefore, should change direction 4. Use two variables to track the ball's horizonal and vertical directions Initially, the bal moves cast-south. So in my code, I used horizontal direction and vertical direction and set them as follows: horizontal directioneast . Insert code for the animation loop to move the ball 2 pixels down (ie. south) and 2 pixels right(i.?., east) every 15 miliseconds. This code will be adjusted in steps 6 and 7. Hint: see how this was done in the example AninationDeno-py on TRACE 6. Use the idea in the following code and insert appropriate code in the animation loop from the previous step to take care of the balls horinontal movement # horizontal movement if horizontal directioneast self .eanvas- ove [.ball", dz, 0) # Bove ball horizontal] top-x +. dx # dx is 2 because the ball moves 2 if top-x >. canvas-width-ball-diameter: # ball has h else: # i.e., horizontal-direction i 'vest self.canvas.move("ball.. .dz, 0) # nove ball horisontal if toP_x <. ball has hit vest vall horizontal-dir eetion . .ease. ehange direetion add code to the animation loop take care of ballr vertical movemont. name your file lab8.py. make sure include and trace folder at top in a docstring. when you are done demonstrate instructor. upload an clectronic copy solution csc131 named labslab8>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

More Books

Students also viewed these Databases questions

Question

The drama club had x cars at $5 each an can be used to repre

Answered: 1 week ago