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()
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()
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()
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()
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()))
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 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(): 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()))
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()))
def main(): angle, vel, h0, time = getInputs() cball = Projectile(angle, vel, h0) while cball.getY >= 0: cball.update(time) print "The distance traveled is: %0.1f meters." %(cball.getX())
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()))
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()))
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))
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()
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)
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 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)
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()
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()
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()))