To begin this assignment I downloaded the datumskeleton.py file and renamed it as datum.py. Self is the first parameter in each method because is contains the reference to the object on which the method is acting. I then began by setting the x, y, and z fields in the set method. To do this I set self.x = tx. This sets self.x equal to the value tx. The self is necessary so that you know what object it refers to. I did the same thing for y and z. I set self.y = ty and self.z = tz. I then needed to set the draw parameters. To do this I did, self.x0 = drawX. This set the field x0 to the input value drawX. Once again the self was necessary so we know what object it is referring to. I then wrote the accessor functions, X, Y, and Z. Each function, X, Y, and Z returned the values of the x, y, and z fields, respectively. For example, the function X would return self.x. I then set the draw parameters again, as I did above in the set function, in the setDrawParameters function. In the draw function I first checked to see if the circle field was equal to nothing, if it was I created a circle at (self.x0, self.y0) with a radius self.dr, filled it with a color (self.circle.setFill(self.color)) and drew the circle in the window (self.circle.draw(win)). If the circle was not equal to nothing then I would undraw the circle( self.circle.undraw()) and move it to a new location (self.circle.move) and then draw it in this new location. I did this by using an 'if else' statement. I then wanted to read a single line of a file and extract 3 values. First I needed to split the line of file into separate strings (s.split) and set this equal to a variable so that each string was contained in a list, I did this within the read function. I then used 'try' and 'float' to access each new string within the list. I set each of these variables in the string equal to x, y, and z. I then returned true if it was successful and false when it was unsuccessful. For the write function I wrote from a given file a single line of the file to the current line and then would go to the next line and write the next line of the file. I did this by adding the three strings together with an empty space in between. This way I would only have 3 numbers on each line with a space in between them.
I then downloaded DataCollectionskeleton. I began by completing the add function. The add function appended the datum objects to the list of datum objects held by DataCollection (self.data.append(datum)). Next I did the write method. I first opened a file to write in. I then wrote the file by using a 'for loop'. Then I closed the file. For the move method I also used a 'for loop' in order to move all visible aspects of the data, but not the data itself. I then also wanted to move the background rectangle. This completed the project.
This image includes my extension in the image. For an extension I made the datum class look like a zelle graphics object. I cloned the circle, which is why there are two big circles in this picture rather than just one. To clone the circle I created a function clone which took the argument self. I then created a new object by setting p = Datum(). I then set this new Datum object to self and then I cloned the circle by setting p.clone = self.circle.clone(). I then added this to the main function by calling clone. This cloned the circle. I then moved the cloned circle to a new point and drew the new clone.
Fields in an object are created in the set function. We set each field of the object to a value. The set function has parameters and we want to set the fields of the objects equal to the value of the respective parameters. For example, setting the x, y, and z fields would be self.x = tx, self.y = ty and self.z = tz. tx, ty, and tz are some of the parameters of the set function. Self.x, for example, refers to the instance varaible x that is stored inside the object. Within the set function we have set this instance varibale x that is stored within the object to tx. this is how a field object is created.
To accessing a field object is done with an accessor function. For example, the accessing function X, simply returns the field value, thus it return self.x. This returns the value of that point.