Question: Computer science find the solution by processing time program structure, and the global constants . loll? _ 'mplete the program by adding a few state

Computer science find the solution by processing

Computer science find the solution by processing time program structure, and the

time program structure, and the global constants . loll? _ 'mplete the program by adding a few state '9 , _ tvvo functions, so that it will draw a circle that moves ,1: nd rth along ahorizontal line, as shown here. The circle will " onn'ally move at a constant speed, but will freeze in place whenever mouse button is pressed, resuming its motion when the mouse button is released. 1; _ The following constants are supplied. X__!.EFT and X_RIGHT are the at coordinates of the ends of the line, and Y is the y coordinate of everything (both ends of the line, and the centre of the circle). BALL_DIAM and BALL_SPEED give the diameter of the circle (in pixels) and the speed of motion of the circle (in pixels per frame). (But that motion will change between right-to-left and left-toright.) . Dene the \"state variables\" needed to keep track of the current situation. You need to know the current position of the centre of the circle (use a float) and whether the circle is moving to the left, or to the right (you must use a boolean variable for this). . Add the drauAIlO function which will erase the window to grey, and draw the line and the circle. . Add the moveBa 11 () function which will cause the circle to move back and forth along the line. Whenever the centre of the circle goes beyond either end of the line, it should change direction. Whenever the mouse button is pressed, the circle should not move. Otherwise it should move BALL_SPEED pixels to the left, or to the right, according to the value of your boolean state variable. Use IF statements to do these things (you will need at least 3 of them, perhaps 4)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!