Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Brick Wall using nested functions to draw a brick wall Purpose: Solidify and demonstrate your understanding and application of using functions to break a problem

Brick Wall

using nested functions to draw a brick wall

Purpose: Solidify and demonstrate your understanding and application of using functions to break a problem into pieces.

Skills The primary new coding skill exercised by this project is defining and invoking functions. You will develop separate functions for each piece of this project. The recommended pieces are:

Initializing turtle

Drawing a square brick

Drawing a rectangle brick

Drawing a row of rectangle bricks by invoking the draw rectangle brick function

Drawing a row of offsetted bricks by starting and ending with square brick by invoking the draw rectangle and draw square brick functions

Invoking the draw row functions from the main function

use the following code:

# # Brick Wall Project recommended starting file #

import turtle

SQUARE_SIZE = 40 # recommended square size is 40 x 40

# # initialize Turtle by clearning screen, setting speed, # putting the pen down, setting initial direction # and location # def InitTurtle(): pass

# # Draw a SQUARE_SIZE brick square at the given x,y coordinates # def DrawSquareBrick(x,y): global SQUARE_SIZE

pass # # Draw a rectangle horizontal rectangle at the given x,y coordinates # length of 2 times SQUARE_SIZE and height of SQUARE_SIZE # def DrawRectangleBrick(x,y): global SQUARE_SIZE

pass

# # Use the DrawRectangleBrick funciton to draw a row of 8 Rectangle bricks # at the given y positiion starting with x == -300 # def DrawRowOfRectangleBricks(yPos): pass # # Use the DrawRectangleBrick and DrawSquareBrick funcitons to draw a row of # 1 square followed by 7 Rectangle bricks ending with 1 square brick # at the given y positiion starting with x == -300 # def DrawRowOfBricksStartingWithSquare(yPos): pass

# # Main routine that uses DrawRowOfRectangleBricks and # DrawRowOfBricksStartingWithSquare functions to the row of bricks # to draw the entire brick wall # def main(): global SQUARE_SIZE

InitTurtle() yPos = -300

for i in range (8): DrawRowOfRectangleBricks(yPos) yPos += SQUARE_SIZE DrawRowOfBricksStartingWithSquare(yPos) yPos += SQUARE_SIZE

main() turtle.done()

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions