Question

In: Computer Science

IN PYTHON- Problem: Roll a ball and make it bounce around the sides of a window...

IN PYTHON- Problem: Roll a ball and make it bounce around the sides of a window 4 times

Details: You need to design, write, and test a program that rolls a ball as demonstrated at the beginning of the lab. The ball goes down and right, bounces against the right edge of the window, then goes down and left, bounces against the bottom edge, then goes up and left, bounces against the left edge, then goes up and right, and stops when it hits the top edge.

Program Requirements:

at least 1 function: it returns a value input by the user after checking that that value is between 2 values (a min and a max); you can assume that the user will enter integer values only: it accepts 3 parameters representing the min, max, and a message to pass to the user when asking the user to input a value Your program should use that function to get user input for the starting x coordinate of the ball (the starting y coordinate is 20). Note that you can do that function at the very end (i..e you can start by hard coding a value for the starting x coordinate) Important note: Point ( 0, 0 ) is at the top left of the window. Your program should make sure that the starting x coordinate is between 50 and 450 included (considering that the height and width of the window are set at 500 - see skeleton code provided); this will make sure that the ball hits the right edge first, then the bottom edge, then the left edge, and finally the top edge. Steps: Understand the problem Write the first loop, moving the ball to the right and down; do not worry about the ball going through the wall of the window Make your ball stop at the edge of the window Write the 2nd, then 3rd, then 4th loop.

USE at least 1 or more of the Following Function in your Algorithm:

#1

def make_window( title, width, height ):
#2
def make_circle( x, y, radius ):
    return Circle( Point( x, y ), radius )

#3

def move( circle, moveX, moveY ):
    circle.move( moveX, moveY  )

#4

def change_title( window,title ):
    window.master.title( title )

#5

def sleep( ms):
    time.sleep( ms / 1000 )

Solutions

Expert Solution

Solution:

Givendata:

Roll a ball and make it bounce around the sides of a window 4 times

Details: You need to design, write, and test a program that rolls a ball as demonstrated at the beginning of the lab.

Answer:

I created a demo program to move circle around the window.program was difficult to complete in given time frame but i created it with move() and make_window, create_circle() function and try to give you a demo , how to move circle inside window.

Now you can play with this more and can make it as per your need.

Attaching program and output window.

from graphics import *

def change_title( window,title ):
    window.master.title( title )


# it will create circle ay x,y points and with given radious
def make_circle( x, y, radius ):
    return Circle( Point( x, y ), radius )

#moving cirle around the window
def move(circle, dx, dy):
    x=10
    y=10
    for i in range (100000):
        # move the circle 
        circle.move(dx, dy)
        x = x + dx
        y = y + dy
        # when x reaches 190, reverse the direction of movement in
        # the x direction
        if x >490:
            dx = -1*dx
        # when y reaches 190, reverse the direction of movement in
        # the y direction
        if y > 490:
            dy = -1*dy
        # when x reaches 10, reverse the direction of movement in
        # the x direction
        if x == 10:
            dx = -1*dx
        
        # when y reaches 10, reverse the direction of movement in
        # the y direction
        if y == 10:
            dy = -1*dy
      
        
#once circle stoped click muose over window




def make_window( title, width, height ):
    win = GraphWin("Move the Circle", 500, 500)
    c = make_circle( 0, 0, 100 ) 
    c.draw(win)
    win.getMouse()
    moveX = .01
    moveY = .01

    move(c, moveX, moveY)
    win.getMouse()
    win.close()

# it will create a window , draw circle and calling other methods so it primary main call
make_window("Move the Circle", 500, 500)    

PLEASE GIVEME THUMBUP........


Related Solutions

IN PYTHON- Problem: Roll a ball and make it bounce around the sides of a window...
IN PYTHON- Problem: Roll a ball and make it bounce around the sides of a window 4 times Details: You need to design, write, and test a program that rolls a ball as demonstrated at the beginning of the lab. The ball goes down and right, bounces against the right edge of the window, then goes down and left, bounces against the bottom edge, then goes up and left, bounces against the left edge, then goes up and right, and...
In a game of basketball, a forward makes a bounce pass to the center. The ball...
In a game of basketball, a forward makes a bounce pass to the center. The ball is thrown with an initial speed of 4.3 m/s at an angle of 15 ∘ below the horizontal. It is released 0.70 m above the floor. Part A What horizontal distance does the ball cover before bouncing?
short answer questions: 7. Ball Bounce Explain the relationship between the work done on a ball...
short answer questions: 7. Ball Bounce Explain the relationship between the work done on a ball and the resulting transformation of energy. Identify each type of energy as the ball is released from a height up to an including the rebound of the ball and its achieved height from bouncing.
A rubber ball is dropped from a height of 30 feet, and on each bounce it...
A rubber ball is dropped from a height of 30 feet, and on each bounce it rebounds up 22% of its previous height. How far has the ball traveled vertically at the moment when it hits the ground for the 23rd time? Round your answer to two decimal places.
Python 3 Fix the code so i can make the window larger or smaller and the...
Python 3 Fix the code so i can make the window larger or smaller and the fields adjusts everytime according to the window size import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook window = tk.Tk() window.title("daily logs") # window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window)...
The ball in Task 1 will then continue to bounce and rebound until it loses all energy.
  Task 2 – Subsequent Motion The ball in Task 1 will then continue to bounce and rebound until it loses all energy. By first finding an expression for the maximum height of the ball after the first bounce, find formulas for the total distance travelled by the ball (i.e. the total distance travelled up and down for all bounces) and the total time taken to complete its motion. A ball of mass 0.06 kg is dropped from rest from...
Python 3 Fix the code so i can make the window larger and the fields increase...
Python 3 Fix the code so i can make the window larger and the fields increase size import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook window = tk.Tk() window.title("daily logs") # window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window) product = tk.Entry(window) money = tk.Entry(window) #...
Python 3 Fix the code so i can make the window larger and the fields increase...
Python 3 Fix the code so i can make the window larger and the fields increase size Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook window = tk.Tk() window.title("daily logs") # window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window) product = tk.Entry(window) money = tk.Entry(window)...
1) A ball is tossed from an upper-story window of a building. The ball is given...
1) A ball is tossed from an upper-story window of a building. The ball is given an initial velocity of 8..00 m/s at an angle of 20.0 below the horizontal. It strikes the ground 5 .00 s later. A) How far horizontally from the base of the building does the ball strike the ground? B) Find the height from which the ball was thrown. C) How long does it take the ball to reach a point 10.0 m below the...
A ball is thrown upward from the ground. You observe the ball through a window on...
A ball is thrown upward from the ground. You observe the ball through a window on its way up, and notice it was visible for 2 seconds while it travels from the bottom of the window to the top, which is a length of 43.42 metres. a) How much time does it take for the ball to be seen again (in seconds)? b) How far above top of window will the ball reach (in metres)?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT