I am working on a project for my programming class in which I need to use a Tracker class. The guidelines given to us are as follows:

class Tracker:
def __init__(self,window,objToTrack):
# window is a graphWin and objToTrack is an object whose
# position is to be shown in the window. objToTrack is
# an object that has getX() and getY() methods that
# report its current position.

# Creates a Tracker object and draws a circle in window
# at the curent position of objToTrack.

def update():
# Moves the circle in the window to the current position
# of the object being tracked.

Any help with creating the class and function to go along with it is much appreciated.

6 Years
Discussion Span
Last Post by sergb

I am not familiar with GraphWin API, but it should have methods to do what is described below.

class Tracker(object):
	def __init__(self, window, objToTrack):
		self.win = window
		self.obj = objToTrack
		self.x = self.obj.getX()
		self.y = self.obj.getY()

	def update(self):
		# Clear the tracker at the old location.
		# Assumes that self.win.bgColor is the background of the window.
		# Call whatever method is appropriate to clear the circle.
		self.win.plot(self.x, self.y, self.win.bgColor)
		# Remember the current point, so we can clear it at next update.
		self.x = self.obj.getX()
		self.y = self.obj.getY()
		# Draw the tracker at a new location.
		# Call whatever method appropriate to draw a circle.
		self.win.plot(self.x, self.y)

Hope this helps.

Edited by sergb: fixed typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.