Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

####python 3x ## 1:Adjust the code in draw.py by adding the Rectangle , Triangle , and Square classes using the inheritance r/ship. 2:Make a drawing

####python 3x ##

1:Adjust the code in draw.py by adding the Rectangle, Triangle, and Square classes using the inheritance r/ship.

2:Make a drawing that uses the above added classes in makeDrawing.py.

draw.py code is given below or u can find it in this link http://pasted.co/c6f51cc6

### draw.py code below ####

import turtle

class Canvas:

def __init__(self, w, h):

self.width = w

self.height = h

self.visibleObjects = []

self.turtle = turtle.Turtle()

self.screen = turtle.Screen()

self.screen.setup(width=self.width,height=self.height)

self.turtle.hideturtle()

def drawAll(self):

self.turtle.reset()

self.screen.tracer(0)

for shape in self.visibleObjects:

shape._draw(self.turtle)

self.screen.tracer(1)

self.turtle.hideturtle()

def addShape(self, shape):

self.visibleObjects.append(shape)

def draw(self, gObject):

gObject.setCanvas(self)

gObject.setVisible(True)

self.turtle.up()

self.screen.tracer(0)

gObject._draw(self.turtle)

self.screen.tracer(1)

self.addShape(gObject)

class GeometricObject:

def __init__(self):

self.lineColor = 'black'

self.lineWidth = 1

self.visible = False

self.myCanvas = None

def setColor(self, color):

self.lineColor = color

if self.visible:

self.myCanvas.drawAll()

def setWidth(self, width):

self.lineWidth = width

if self.visible:

self.myCanvas.drawAll()

def getColor(self):

return self.lineColor

def getWidth(self):

return self.lineWidth

def _draw(self, someturtle):

print('Error: You must define _draw in subclass')

def setVisible(self, vFlag):

self.visible = vFlag

def setCanvas(self, theCanvas):

self.myCanvas = theCanvas

class Point(GeometricObject):

def __init__(self, x, y):

super().__init__()

self.x = x

self.y = y

def getCoord(self):

return (self.x, self.y)

def getX(self):

return self.x

def getY(self):

return self.y

def _draw(self, turtle):

turtle.goto(self.x, self.y)

turtle.dot(self.lineWidth, self.lineColor)

class Line(GeometricObject):

def __init__(self, p1, p2):

super().__init__()

self.p1 = p1

self.p2 = p2

def getP1(self):

return self.p1

def getP2(self):

return self.p2

def _draw(self, turtle):

turtle.color(self.getColor())

turtle.width(self.getWidth())

turtle.goto(self.p1.getCoord())

turtle.down()

turtle.goto(self.p2.getCoord())

turtle.up()

class Shape(GeometricObject):

def __init__(self):

super().__init__()

self.fillColor = 'white'

def setFill(self, color):

self.fillColor = color

if self.visible:

self.myCanvas.drawAll()

class Polygon(Shape):

def __init__(self, corners):

super().__init__()

self.corners = corners # Expect this to be a list of Points

def _draw(self, turtle):

turtle.color(self.getColor())

turtle.width(self.getWidth())

turtle.fillcolor(self.fillColor)

turtle.begin_fill()

for corner in self.corners:

turtle.goto(corner.getCoord())

turtle.down()

turtle.goto(self.corners[0].getCoord())

turtle.end_fill()

turtle.up()

def test2():

myCanvas = Canvas(500,500)

myLine = Line(Point(-100,-100), Point(100,100))

myOtherLine = Line(Point(-100, 100), Point(100,-100))

myLine.setWidth(4)

myOtherLine.setWidth(4)

myCanvas.draw(myLine)

myCanvas.draw(myOtherLine)

myLine.setColor('red')

myPolygon = Polygon([Point(-100,0), Point(-100,-100), Point(100,-50)])

myPolygon.setColor('blue')

myPolygon.setFill('yellow')

myCanvas.draw(myPolygon)

test2()

image text in transcribed

###python 3 code## draw.py code is given in this link http://pasted.co/c6f5 1cc6. 1:Adjust the code and implement the Rectangle, Triangle, and Square classes. using the INHERITANCE HIERACHY relationship. 2: In makeDrawing.py, make a drawing that uses your classes. Please comment on the changes, thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

9. What are the leading causes of capital flight?

Answered: 1 week ago