class BaseballTracker:
    def __init__( self, window, angle, velocity, height ):
        
        self.projectile = Projectile( angle, velocity, height )
        
        self.ball = Circle( Point( 0, height ), 3 )
        self.ball.setOutline( 'red' )
        self.ball.setFill( 'red' )
        self.ball.draw( window )
        
    def update( self, timeInterval ):
        prevX = self.projectile.getX()
        prevY = self.projectile.getY()
        
        self.projectile.update( timeInterval )
        
        dx = self.projectile.getX() - prevX
        dy = self.projectile.getY() - prevY
        
        self.ball.move( dx, dy )
        
    def clear( self ):
        self.ball.undraw()
        
    def getX( self ):
        return self.projectile.getX()
        
    def getY( self ):
        return self.projectile.getY()       
Example #2
0
def main():
    angle, vel, h0, time = getInputs()
    cball = Projectile(angle, vel, h0)
    while cball.getY() >= 0 and cball.getYv() >= 0:
        cball.update(time)
    print("\nDistance traveled: {0:0.1f} meters.".format(cball.getX()))
    print("Max height: {0:0.1f} meters.".format(cball.getY()))
Example #3
0
class ShotTracker:
    def __init__(self, win, angle, velocity, height):
        """win is the GraphWin to display the shot. angle, velocity,
            and height are initial projectile parameters.
        """

        self.proj = Projectile(angle, velocity, height)
        self.marker = Circle(Point(0, height), 3)
        self.marker.setFill("red")
        self.marker.setOutline("red")
        self.marker.draw(win)

    def update(self, dt):
        """Move the shot dt seconds farther along its flight """

        # Update the projectile
        self.proj.update(dt)

        # Moves the circle to the new projectile location
        center = self.marker.getCenter()
        dx = self.proj.getX() - center.getX()
        dy = self.proj.getY() - center.getY()
        self.marker.move(dx, dy)

    def getX(self):
        """ return the current x coordinate of the shot's center """
        return self.proj.getX()

    def getY(self):
        """ return the current y coordinate of the  shot's center """
        return self.proj.getY()

    def undraw(self):
        """ undraw the shot """
        self.marker.undraw()
Example #4
0
class ShotTracker:
    def __init__(self, win, angle, velocity, height):
        # displays initial projectile parameters
        self.proj = Projectile(angle, velocity, height)
        self.marker = Circle(Point(0, height), 3)
        self.marker.setFill("red")
        self.marker.setOutline("red")
        self.marker.draw(win)

    def update(self, dt):
        """move the shot seconds further in its flight"""
        # update projectile
        self.proj.update(dt)
        # move circle to new location
        center = self.marker.getCenter()
        dx = self.proj.getX() - center.getX()
        dy = self.proj.getY() - center.getY()
        self.marker.move(dx, dy)

    def getX(self):
        # current x coordinate
        return self.proj.getX()

    def getY(self):
        # return currect y coordinate
        return self.proj.getY()

    def undraw(self):
        # undraw the shot
        self.marker.undraw()
Example #5
0
class ShortTracker:
    """ Graphical depiction of a projectile flight suing a circle """
    def __init__(self, win, angle, velocity, height):
        """Win is the GraphWin to display the shot angle, velocity,
        and height are initial projectile parameters.
        """

        self.proj = Projectile(angle, velocity, height)
        self.marker = Circle(Point(0, height), 3)
        self.marker.setFill("red")
        self.marker.setOutline("red")
        self.marker.draw(win)

    def update(self, dt):
        """ Move the shot dt seconds farther along its flight """
        # update the projectile, move the circle to the new projectile location
        self.proj.update(dt)
        center = self.marker.getCenter()
        dx = self.proj.getX() - center.getX()
        dy = self.proj.getY() - center.getY()
        self.marker.move(dx, dy)

    def getX(self):
        return self.proj.getX()

    def getY(self):
        return self.proj.getY()

    def undraw(self):
        self.marker.undraw()
Example #6
0
def main():
	angle, vel, h0, time = getInputs()
	cball = Projectile(angle, vel, h0)
	prev_y = h0
	while cball.getY() >= prev_y:
		prev_y = cball.getY()
		cball.update(time)
	print("\nMaximum Height: {0:0.1f} meters".format(prev_y))
Example #7
0
def main():
    angle, vel, h0, time = getInputs()
    cball = Projectile(angle, vel, h0)
    maxHeight = h0
    while cball.getY() >= 0:
        if maxHeight < cball.getY():
            maxHeight = cball.getY()
        cball.update(time)
    print('Distance traveled: {:0.2f} meters.'.format(cball.getX()))
    print('Maximum height: {:0.2f} meters.'.format(maxHeight))
def main():
    angle, vel, h0, time = getInputs()
    hmax = h0
    cball = Projectile(angle, vel, h0)
    while cball.getY() >= 0:
        if cball.getY() >  h0:
            h0 = cball.getY()
        cball.update(time)

    print("\nDistance traveled: {0:0.1f} meters, max height is {1:0.1f}.".format(cball.getX(), h0))
def main():
    angle, vel, h0, time = getInputs()
    cball = Projectile(angle, vel, h0)
    maxheight = h0
    while cball.getY() >= 0.0:
        cball.update(time)
        if cball.getY() > maxheight:
            maxheight = cball.getY()
    print("\nDistance traveled: {:0.1f} meters.".format(cball.getX()))
    print("Maximum height: {:0.1f} meters.".format(maxheight))
Example #10
0
def main():
    win = GraphWin("Projectile Tracker", 600, 600)
    win.setCoords(0, 0, 1400, 1400)
    missile = Projectile(45, 100, 0)
    tracker = Tracker(win, missile, 1400)
    while missile.getY() >= 0:
        missile.update(.05)
        dx = missile.getX()
        dy = missile.getY()
        tracker.move(dx, dy)
        print("{}:{}".format(missile.getX(), missile.getY()))
def fire(angle, vel, h0, time):

    cball = Projectile(angle, vel, h0)

    xcoords = [0.]
    ycoords = [h0]

    while cball.getY() >= 0.0:
        cball.update(time)
        xcoords.append(cball.getX())
        ycoords.append(cball.getY())

    plt.plot(xcoords, ycoords, marker=".", label=time/vel)
Example #12
0
def main():
    angle, vel, h0, time = getInputs()
    cball = Projectile(angle, vel, h0)
    while cball.getY() >= 0:
        cball.update(time)
    print("\nDistance traveled: {0:.1f} meters. Max height {1:.1f}".format(
        cball.getX(), cball.getYmax()))
Example #13
0
def main():

    angle, vel, h0, time = getInputs()
    cball = Projectile(angle, vel, h0)
    while cball.getY() >= 0:
        cball.update(time)
    print "\nDistance traveled : %0.1f meters." % (cball.getX())
def main ():

    #Introduction
    print ("This program graphically depicts the flight of a cannonball. ")
    print ()

    #Get inputs
    a = eval(input("Enter the launch angle in degrees: "))
    v = eval(input("Enter the initial velocity in meters per second: "))
    h = eval(input("Enter the initial height in meters: "))

    #Create tracker
    projectile = Projectile(a, v, h)
    win = GraphWin(200, 200)
    win.setCoords(0.0, 0.0, 25.0, 25.0)
    tracker = Tracker(win, projectile)
    time = 0.0
    while projectile.getY() >= -5:
        time += .0005
        projectile.update(time)
        tracker.update()

    #Close window
    win.getMouse()
    win.close()
def main():
    angle, vel, h0, time = getInputs()
    cball = Projectile(angle, vel, h0)
    while cball.getY() >= 0:
        cball.update(time)
    print("\nDistance traveled: {0:0.1f} meters.".format(cball.getX()))
    print("The maximum height of the projectile was {0:0.1f} meters.".format(
        cball.getYmax()))
Example #16
0
def main():
    angle, vel, h0, time = getInputs()
    cBall = Projectile(angle, vel, h0)

    #loop until the ball hits the ground
    while cBall.getY() >= 0:
        cBall.update(time)

    print('\nDistance traveled: {0:0.1f} meters.'.format(cBall.getX()))
Example #17
0
class ShotTracker:
    """ Graphical depiction of a projectile flight using a Circle """
    def __init__(self, win, angle, velocity, height):
        """win is the GraphWin to display the shot, angle, velocity, and
        height are initial projectile parameters.
        """

        self.proj = Projectile(angle, velocity, height)
        self.radius = 2
        self.marker = Circle(Point(0, height), self.radius)
        self.marker.setFill("red")
        self.marker.setOutline("red")
        self.marker.draw(win)

    def update(self, dt, win):
        """ Move the shot dt seconds farther along its flight """

        _greyCircle = Circle(Point(self.proj.getX(), self.proj.getY()), .05)
        _greyCircle.setFill("grey")
        _greyCircle.setOutline("grey")
        _greyCircle.draw(win)
        self.proj.update(dt)
        center = self.marker.getCenter()
        dx = self.proj.getX() - center.getX()
        dy = self.proj.getY() - center.getY()
        self.marker.move(dx, dy)

    def getX(self):
        """ return the current x coordinate of the shot's center """
        return self.proj.getX()

    def getY(self):
        """ return the current y coordinate of the shot's center """
        return self.proj.getY()

    def getRadius(self):
        """ return the radius of the shot """
        return self.radius

    def destroy(self):
        """ undraw the shot """
        self.marker.undraw()
Example #18
0
def main():
    win = GraphWin("Projectile Tracker", 600, 600)
    win.setCoords(0, 0, 1400, 1400)
    missile = Projectile(45, 100, 0)
    tracker = Tracker(win, missile, 1400)
    target = Button(win, Point(1021, 70), 140, 140, "x")
    target.activate()
    click = Point(missile.getX(), missile.getY())
    while not target.clicked(click):
        missile.update(.05)
        dx = missile.getX()
        dy = missile.getY()
        tracker.move(dx, dy)
        click = tracker.getPosition()
        print(click.getX(), click.getY())
        if dy <= 0:
            angle = eval(input("Angle: "))
            velocity = eval(input("Velocity: "))
            height = eval(input("Initial Height: "))
            missile = Projectile(angle, velocity, height)
Example #19
0
def main():

    angle,vel,h0,timestep = getInputs()

    cball = Projectile(angle,vel,h0)

    while cball.getY() >= 0:
        cball.update(timestep)
    print("Distance travelled is ", cball.getX(),"meters")

    print("Distance traveled is {0:0.1f} meters".format(cball.getX()))
Example #20
0
def main():
    angle, vel, h0, time = getInputs()
    window = GraphWin("window",250,250)
    cball = Projectile(angle, vel, h0)
    #Tracker(window,cball)  
    while cball.getY() >= 0:
        cball.update(.001)
        Tracker(window,cball)  
        
    window.getMouse()      
    window.close()
    print("\nDistance traveled: {0:0.1f} meters.".format(cball.getX()))
def main ():

    #Introduction
    print ("This program uses a cannonball to shoot at a target.")

    #Create graphics window
    win = GraphWin(200, 200)
    win.setCoords(0.0, 0.0, 25.0, 25.0)
    target = Target(win)

    flag = False
    targetHit = False
    while not flag:

    #Get inputs
        print ()
        a = eval(input("Enter the launch angle in degrees: "))
        v = eval(input("Enter the initial velocity in meters per second: "))
        h = eval(input("Enter the initial height in meters: "))

    #Create tracker
        projectile = Projectile(a, v, h)
        tracker = Tracker(win, projectile)
        time = 0.0
        while projectile.getY() >= -5:
            time += .0005
            projectile.update(time)
            tracker.update()

    #Calculate if cannonball hit target
            points = target.points()
            center = tracker.circ.getCenter()
            center_x = center.getX()
            center_y = center.getY()
            radius = tracker.circ.getRadius()
            for point in points:
                x = point.getX()
                y = point.getY()
                square_dist = (center_x-x) ** 2 + (center_y-y) ** 2
                if square_dist <= radius ** 2:
                    targetHit = True
        if targetHit:
            print ("\nYou hit the target!")
            flag = True
        else:
            flag = False
            print ("\nTry again!")


    #Close window
    win.getMouse()
    win.close()
Example #22
0
def main():

    #Introduction
    print("This program uses a cannonball to shoot at a target.")

    #Create graphics window
    win = GraphWin("Target", 200, 200)
    win.setCoords(0.0, 0.0, 25.0, 25.0)
    target = Target(win)

    flag = False
    targetHit = False
    while not flag:

        #Get inputs
        print()
        a = eval(input("Enter the launch angle in degrees: "))
        v = eval(input("Enter the initial velocity in meters per second: "))
        h = eval(input("Enter the initial height in meters: "))

        #Create tracker
        projectile = Projectile(a, v, h)
        tracker = Tracker(win, projectile)
        time = 0.0
        while projectile.getY() >= -5:
            time += .0005
            projectile.update(time)
            tracker.update()

            #Calculate if cannonball hit target
            points = target.points()
            center = tracker.circ.getCenter()
            center_x = center.getX()
            center_y = center.getY()
            radius = tracker.circ.getRadius()
            for point in points:
                x = point.getX()
                y = point.getY()
                square_dist = (center_x - x)**2 + (center_y - y)**2
                if square_dist <= radius**2:
                    targetHit = True
        if targetHit:
            print("\nYou hit the target!")
            flag = True
        else:
            flag = False
            print("\nTry again!")

    #Close window
    win.getMouse()
    win.close()
class ShotTracker(object):
    def __init__(self, win, angle, velocity, height):
        self.proj = Projectile(angle, velocity, height)
        self.marker = Circle(Point(0, height), 3)  # εœ†εΏƒ, εŠεΎ„
        self.marker.setFill('red')
        self.marker.setOutline('red')
        self.marker.draw(win)

    def update(self, dt):
        self.proj.update(dt)

        center = self.marker.getCenter()
        dx = self.proj.getX() - center.getX()
        dy = self.proj.getY() - center.getY()
        self.marker.move(dx, dy)

    def getX(self):
        return self.proj.getX()

    def getY(self):
        return self.proj.getY()

    def undraw(self):
        self.marker.undraw()
Example #24
0
def main():

    # Setting up the cannonball
    #angle, vel, h0, time = getInputs()
    angle, vel, h0, time = 45.0, 25.0, 2.0, 0.5
    cball = Projectile(angle, vel, h0)

    # Setting up the window
    wind = GraphWin("Cannonball Animation", width=1000, height=800)
    wind.setCoords(0, 0, 300, 240)
    sprite = Tracker(wind, cball)

    wind.getMouse()

    while cball.getY() >= 0.0:
        cball.update(time)
        sleep(time)
        sprite.update()

    wind.getMouse()
Example #25
0
def main():
    angle, vel, h0, time = getInputs()
    cball = Projectile(angle, vel, h0)
    while cball.getY() >= 0:
        cball.update(time)        
    print("\nDistance traveled: {0:0.1f} meters.".format(cball.getX()))
Example #26
0
def main():
	# Draw the window to simulate green field and sky.
	
	win = GraphWin("Shoot a Cannon!", 850,850)
	win.setCoords(0,-50,700,700)
	win.setBackground("lightblue")
	ground = Rectangle(Point(0,-100),Point(700,0))
	ground.setFill("green")
	cloud1 = Oval(Point(153,420),Point(390,580))
	cloud1.setFill("white")
	cloud1.setWidth(2)
	cloud2 = Oval(Point(23,232),Point(230,400))
	cloud2.setFill("white")
	cloud2.setWidth(2)
	cloud3 = Oval(Point(434,370),Point(610,520))
	cloud3.setFill("white")
	cloud3.setWidth(2)
	tangle = Text(Point(30,680), "     Angle: ")
	tvel = Text(Point(30,650), "Velocity:")
	anginp = Entry(Point(70,680),3)
	velinp = Entry(Point(70,650),3)
	fbutton = CButton(win,Point(55,590),30,"FIRE!")
	fbutton.activate()
	quitbutton = CButton(win,Point(630,660),30,"Quit")
	quitbutton.activate()
	ground.draw(win)
	cloud1.draw(win)
	cloud2.draw(win)
	cloud3.draw(win)
	tangle.draw(win)
	tvel.draw(win)
	anginp.draw(win)
	anginp.setText("0")
	velinp.setText("0")
	velinp.draw(win)
	target = Target(win)
	
	
	
	
	
	pt = win.getMouse()
	shots = 0
	while not quitbutton.clicked(pt):
		try:
			if fbutton.clicked(pt):
			
				ang = float(anginp.getText())
				vel = float(velinp.getText())
				
				shot = Projectile(ang,vel,0)
				ball = Tracker(win,shot)
				
				
				
					
				
				while shot.getY() >= 0 and target.Hit(shot) == False and shot.getX() < 750:
					sleep(.025)
					shot.update(.1)
					ball.update(win,shot)
					target.Hit(shot)
					
					
					if target.Hit(shot) == True:
						shots += 1
						wintxt = Text(Point(325,500), "You Hit the Target in %d shot(s)!" % shots)
						wintxt.setSize(36)
						wintxt.setTextColor("red")
						wintxt.draw(win)
						exit
					
				shots += 1
		except ValueError:
			exit
			
			
		
		pt = win.getMouse()
Example #27
0
def main():
    angle, vel, h0, time = getInputs()
    cball = Projectile(angle, vel, h0)
    while cball.getY() >= 0:
        cball.update(time)
    print "\nDistance traveled: %0.1f meters." % (cball.getX())