Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

# Change the name of the function to \'addHouse\'. It should # take the picture

ID: 3606104 • Letter: #

Question

# Change the name of the function to 'addHouse'. It should
# take the picture and the most important parameters of the
# house as the function's parameters/arguments. (Which values will
# you not parameterise?). Once written correctly, you should be able
# to add a house at any size on to any picture in the same way the
# addRect or addRectFilled can be used to add a rectangle of any
# size on to any picture.
#
# Finally, create a driver function to test your addHouse function. The
# driver function should be called houseDrawDriver.

--------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

def drawHouse():
houseX=50
houseY=50
houseWidth=200
houseHeight=200
picture=makeEmptyPicture(800,600)
golden=1.61803398875
x1=houseX+(houseWidth/2)
y1=houseY
y2=int( houseY+(houseHeight/golden) )
x2=houseX
while(x2<(houseX+houseWidth)):
    addLine(picture,x1,y1,x2,y2,red)
    x2=x2+1
rw=int( houseWidth/golden )
x1=houseX+((houseWidth-rw)/2)
y1=y2
addRectFilled(picture,x1,y2,rw,houseHeight/2,blue)
repaint(picture)

Explanation / Answer

def addHouse(houseX, houseY, houseWidth, houseHeight, color1, color2)
picture=makeEmptyPicture(800,600)
golden=1.61803398875
x1=houseX+(houseWidth/2)
y1=houseY
y2=int( houseY+(houseHeight/golden) )
x2=houseX
while(x2<(houseX+houseWidth)):
addLine(picture,x1,y1,x2,y2,color1)
x2=x2+1
rw=int( houseWidth/golden )
x1=houseX+((houseWidth-rw)/2)
y1=y2
addRectFilled(picture,x1,y2,rw,houseHeight/2,color2)
repaint(picture)
  
def houseDrawDriver()
addHouse(50,50,200,200,"red", "blue")