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.
Thanks

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()
		self.update()

	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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.