In this challenge we are going to build different medieval castles by customising some Python code.
Our first castle is already made for us and looks as follows:
You can see, in the trinket window below, the Python code used to create this castle.
The code uses a range of pre-defined functions to draw the different building blocks of the castle (walls, towers, doors, flags and loopholes). These functions can be accessed in the extra file (tab) called shapes.py. However for the purpose of this challenge, you will not need to access the code of these functions.
The main functions that you will have to reuse to cutomise the look and feel of your castle are:
- drawWall()
- drawTower()
- drawDoor()
- drawLoophole()
- drawFlag()
Each of these functions is using some parameters to change the position, width and height of the different building blocks and to change the colour of the flag. Let’s investigate these functions and their parameters.
So the following code would be used to create a wall at position (-150,0). The wall would be 300 pixels wide, 150 pixels high and would have battlements (crenellation).
So the following code would be used to create a tower at position (-100,0). The tower would be 50 pixels wide, 150 pixels high and would have battlements (crenellation).
So the following code would be used to create a door at position (-100,0). The door would be 50 pixels wide, 150 pixels high.
So the following code would be used to create a loophole at position (-100,0). The loophole would be 10 pixels wide, 30 pixels high.
(X,Y) Coordinates?
The canvas we are drawing on (using Python Turtle) is 400 pixels wide by 400 pixels high.
Look at the canvas below to understand how (x,y) coordinates work:
Colour Codes
Python Code
Here is the Python code to create the castle.
Your Task
Your task is to edit the code from line 16 to 27 to re-create the following castles. To do so you will have to tweak the parameters of the functions used to create the castle. You may also need to remove or add some extra lines of code to add extra elements (towers, flags, loopholes, etc…)
Extension Task
Access the code in the shapes.py file (tab).
Create two more functions as follows:
- drawSun() to draw a yellow circle at a given (x,y) set of coordinates.
- drawTree() to draw a tree at a given (x,y) set of coordinates.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area