# File: shapeParser.py # Purpose: Parses a CSV file of shapes and draws them to the window. # Author: TODO # # Collaboration statement: TODO # # Inputs: CSV file from graphics import * def parseCircle(vals): """ Creates a Circle object based on the values given in vals. Assumes vals is either a list [x,y,r,color] of strings, or [x,y,r]. x: x-coordinate of center point (expect an int in the str) y: y-coordinate of center point (expect an int in the str) r: radius (expect a float in the str) color: optional color (str) Returns: the Circle object """ # TODO return Circle(Point(0,0),0) # replace with your code def parseSquare(vals): """ Creates a Rectangle object representing a square based on the values given in vals. Assumes vals is either a list [x,y,s,color] of strings, or [x,y,s]. x: x-coordinate of center point (expect an int in the str) y: y-coordinate of center point (expect an int in the str) s: side length (expect an int in the str) color: optional color (str) Returns: the Rectangle object representing the square """ # TODO return Rectangle(Point(0,0), Point(0,0)) # replace with your code def parseRectangle(vals): """ Creates a Rectangle object based on the values given in vals. Assumes vals is either a list [x1,y1,x2,y2,color] of strings, or [x1,y1,x2,y2]. x1: x-coordinate of first point (expect an int in the str) y1: y-coordinate of first point (expect an int in the str) x2: x-coordinate of second point (expect an int in the str) y2: y-coordinate of second point (expect an int in the str) color: optional color (str) Returns: the Rectangle object """ # TODO return Rectangle(Point(0,0), Point(0,0)) # replace with your code def parseTriangle(vals): """ Creates a Triangle object based on the values given in vals. Assumes vals is either a list [x1,y1,x2,y2,x3,y3,color] of strings, or [x1,y1,x2,y2,x3,y3]. x1: x-coordinate of first point (expect an int in the str) y1: y-coordinate of first point (expect an int in the str) x2: x-coordinate of second point (expect an int in the str) y2: y-coordinate of second point (expect an int in the str) x3: x-coordinate of third point (expect an int in the str) y3: y-coordinate of third point (expect an int in the str) color: optional color (str) Returns: the Polygon object representing the Triangle """ # TODO return Polygon([Point(0,0), Point(0,0), Point(0,0)]) # replace with your code def parseShapesFromFile(filename): """ Opens the file specified by filename for reading, and parses the window dimensions and the shapes. Returns: the Window object and a list of shapes """ # Specify variables for the window and the shape list # Open the file for reading # Go through each line in the file # Skip over any empty lines # Split the line into strings on the commas # Use the first string in the line to determine which object to create # Return the window and shapes list def main(): # Read in the provided file and parse it into a window and shapes filename = "shapes.csv" win, shapes = parseShapesFromFile(filename) # Draw each shape (in order) in the window pass # TODO: replace with your code # Wait to close until the user clicks win.getMouse() if __name__ == "__main__": main()