import turtle as t from typing import List, Tuple ######################################################## # Making a Scene ######################################################## # We've seen how...

it is a basic python assignment that uses beginner codes.


import turtle as t from typing import List, Tuple ######################################################## # Making a Scene ######################################################## # We've seen how using OOP can help us structure large programs. # So this time we're going to make our own large(ish) program. # We're going to practice the principles of OOP by drawing a picture. # You can draw whatever you want for your picture, but it must obey a few rules. # First it must be appropriate for a college class. # That means no excessive violence, sexual content, gore, slurs, Al Gore, etc. # Any inappropriate drawings will not be graded. I know that's an inconvenient truth. # Second, all drawings must contain at least five different types of Shape. # If you draw a house, you might have a: # * Roof Shape # * Window Shape # * Door Shape # * Cloud Shape # * Tree Shape # Finally, at least one shape must be composed of smaller shapes. # For example your Window shape might be composed of 4 square shapes. # So, how are we going to draw a picture? # Normally in animation we call a picture a scene. # and a scene has several shapes in it. # A shape is a very simple type of class. # The only thing it knows how to do is draw itself. # so a shape has a constructor (the __init__ function) and a draw method. class Shape(object): def __init__(): pass def draw(self): pass # A scene is just the place where we put all of the objects in the picture. # class Scene: # fields # shapes: a list of shapes to draw. # methods # constructor: creates a scene and initializes shapes # drawScene: draws the scene by asking each shape to draw itself. class Scene(object): def __init__(self, shapes : List[Shape]): self.shapes = shapes def drawScene(self): for s in self.shapes: s.draw() # your job is to create the different shapes in our scene. # We can do that by making a different class for each shape. # I'll start you off with a class for a blue square. # Notice that I have x and y as fields for the square. # This will be really useful. # slass Square # fields # x: x position of upper left corner of the square. # y: y position of upper left corner of the square. # size: the length of a side of the square # methods # constructor: initializes x, y, and size # draw: draws the square class Square(Shape): def __init__(self, x : int, y : int, size : int): self.x = x self.y = y self.size = size def draw(self): # go to position (x,y) t.penup() t.goto(self.x, self.y) t.pendown() # face to the right t.setheading(0) # draw a blue square t.fillcolor("blue") t.begin_fill() for n in range(4): t.forward(self.size) t.right(90) t.end_fill() # finally put all of your shapes together in a scene # Right now my scene just has 5 blue squares. theScene = Scene([Square(0,0,20), Square(100,100,20), Square(-100,-100,20), Square(100,-100,20), Square(-100,100,20)]) ########################### # Code for drawing scene ########################### if __name__ == "__main__": theScene.drawScene()
Nov 16, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here