Description
The purpose of this programming assignment is to generate a canvas that plots different colored points at random
locations.
Specification
The program consists of two parts:
• A Point class that defines a blueprint for a 2D point; and
• A CoordinateSystem class that manages a Tkinter Canvas and plots Point objects in random colors onto the
canvas.
Point Class
When designing your Point class, make sure to address the following:
• A constructor which takes two parameters – x and y.
• The default values of x and y in the constructor should be 0.0 and 0.0.
• Getters and setters for x and y
• A subroutine named dist, which takes two points as input and returns the distance between the two points1
.
One of the two inputs should be self.
• A subroutine named midpt, which takes two points as input and returns the mid point between the two
points2
. One of the two inputs should be self and the returned object should be a Point object.
• Finally, the str function which returns string in the format of (x,y)
• Create various Point objects and test your class!
CoordinateSystem Class
This class (which will inherit from Tkinter’s Canvas class) will initialize a canvas on which the points will be plotted.
• The CoordinateSystem class must inherit from Tkinter’s Canvas class and fill the entire Tkinter window.
• A subroutine named plot should take an instance of a Point and a color as input – and plot the specified
point on the canvas in the specified color3
;
• A subroutinection named plotPoints should take the number of points to plot as input (set to 5,000 by
default), generate the points (each should be randomly generated and of a randomly chosen color), and call
the plot subroutine to plot each point;
• Plotted points should be individual instances of your Point class, each with random X- and Y-components
that are within the width and height of the canvas (set to 800×800 by default);
• Plotted points should have a radius of 0 (i.e., a point is made up of a single pixel);
• Points should be plotted in a random color from the following set of colors: black, red, green, blue,
cyan, yellow, and magenta. Feel free to add more colors!
1https://www.mathsisfun.com/algebra/line-midpoint.html
2https://www.mathsisfun.com/algebra/distance-2-points.html
3https://www.geeksforgeeks.org/python-tkinter-create-different-shapes-using-canvas-class/
Figure 1: Sample Output
Deliverable
• Submit the Point.py and CoordinateSystem.py. Both classes can also be present in the same file.
Rubric
Item Points
Good coding style 2
Appropriate Comments & Header 4
Point class 3
Point class constructor 3
Point class getters 4
Point class setters 4
CoordinateSystem class 4
CoordinateSystem plot subroutine 4
CoordinateSystem plotPoints subroutine 4
Output is correct 8
Total 40