We can work on Assessment item 2 – Forest Drawing TASK back to top In this assignment you will use turtle graphics to create an interactive forest drawing application. Start by creating a module ‘utilities.py’ which should contain four drawing functions as listed below. draw_triangle(centre_x, centre_y, width, height, pen_color, fill_color) draw_rectangle(centre_x, centre_y, width, height, pen_color, fill_color)

Assessment item 2 – Forest Drawing

TASK

back to top

In this assignment you will use turtle graphics to create an interactive forest drawing application.

Start by creating a module ‘utilities.py’ which should contain four drawing functions as listed below.

draw_triangle(centre_x, centre_y, width, height, pen_color, fill_color)
draw_rectangle(centre_x, centre_y, width, height, pen_color, fill_color)
draw_circle(centre_x, centre_y, radius, pen_color, fill_color)
stamp_turtle(centre_x, centre_y, color)

The parameter names are self explanatory. For example, the draw_triangle() function should draw an upwards pointing triangle with (centre_x, centre_y) located as shown in figure.

Additionally the module should also contain these functions:

distance(x1, y1, x2, y2)– to find the Cartesian distance between two points (x1, y1) and (x2, y2)
save_state()and restore_state() – the former should save turtle’s important parameters (position, pen color, fill color) in global (module-level) variables. The latter function will reload the turtle’s state from those same variables. The four drawing functions listed above should call these save and restore functions before and after a drawing respectively so that turtle’s state is restored to same values as it was before a drawing.

In your main file ‘forest.py’ you should import the utilities module and call its functions to do all drawings. No direct drawing should be needed from main file.

At the program start, you should disable all turtle animations and change the turtle’s icon to a bird shape (see sample code). Then turtle should be hidden from view. Next your program should implement the following requirements.

Create a large rectangle to represent drawing boundary.
On top of the rectangle, draw two small circles and write text to let the user choose between a bird and tree drawing. When the program starts, tree must be chosen by default.
Handle mouse clicks in the turtle window. Clicks within the drawing rectangle will draw a tree or bird depending on user’s selection. Mouse clicks outside the drawing rectangle are ignored, except for those within the selection circles which switch the drawing mode from bird to tree.
Drawing a tree consists of drawing one vertical rectangle (stem) and three overlapped triangles (branches and leaves).
The bird on the other hand should be drawn using turtle stamping at the click point.
Tree size should change randomly. First you will choose a reference size for tree components (stem rectangle and leave triangles). Then at the drawing time, generate a random value between 0.7 and 1.3 which will act as a scale factor so that individual trees can be shorter, equal to or bigger than the reference size.
When the bird mode is selected, the (bird shaped) turtle becomes visible in the top left corner. When tree mode is selected, turtle hides itself again.
While the bird mode is selected, your program should respond to left (⭠) and right (⭢) keyboard buttons. User will press these buttons in order to change the turtle’s tilt angle. By changing the title angle, birds can be drawn in many different orientations.

For further clarification of all these requirements, watch this video demo of the application: www.youtube.com/watch?v=ZYuyRYipZz4. You should try to make a drawing with similar style and colors.

Suggested dimensions and locations of all elements

Window size – 800 × 800
Inner rectangle – 700 × 700
Tree/bird selector circles – radius 10, centre points (0, 370) and (100, 370)
Bird location in top left – (-340, 370)
Tree (unscaled) size – stem 15 × 80, leaves 100 × 50, 40% overlap of leaf triangles

Sample Codes

All the following turtle functions can be called after importing the turtle module.

(1) To change window size

turtle.setup(window_width, window_height)

(2) To handle mouse clicks

# first create a click handler function which receives (x,y) location of click point

# Python call this function automatically when a left click is detected anywhere in the window

def handle_click(x, y):

print(‘detected a click at’, x, y)

 

# in main function, declare hande_click as the listener function

turtle.listen()

turtle.onscreenclick(handle_click)  # pass the function name as parameter (no function call)

(3) To handle keyboard buttons

# create a listener function which is called automatically on button press

def left_keypress():

print(‘left key detected’)

 

# in main function, declare left_keypress as the listener function

turtle.listen()

turtle.onkey(left_keypress, ‘Left’)

(4) To change turtle icon to a bird

turtle.register_shape(‘bird’, ((-22,-39),(-20,-7),(-7,3),(-11,7),(-12,9),(-11,10),(-9,10),(-3,7),

(10,24),(30,16),(13,18),(4,0),(14,-6),(6,-13),(0,-4),(-14,-13),(-22,-39)))

turtle.shape(‘bird’)

(5) To change turtle tilt angle (it is different from turtle heading)

turtle.tiltangle(new_tilt_value)

Constraints

In many online examples of turtle graphics applications, multiple turtle objects are used on the same window. You are NOT allowed that. Only use a single turtle for all drawings.

You should follow good programming practices, for example using named constants, creating several functions (top down design) and minimizing the use of global variables. A few global variables will be essential though, for example, to store the currently selected drawing object and the current tilt angle value.

 

Your assignment should consist of following tasks.

Task 1

Draw a flowchart of your handle_click() function, including flowcharts for all other functions that are called by handle_click.

You can draw the flowcharts with a pen/pencil on a piece of paper and scan it for submission, as long as the handwriting is clear and legible. However, it is strongly recommended to draw flowcharts using a drawing software.

Task 2

Select four sets of test data that will demonstrate the ‘normal’ operation of your program; that is, test data that will demonstrate what happens when a valid input is entered. Select three sets of test data that will demonstrate the ‘abnormal’ operation of your program. Please note that for this application, user input includes mouse clicks as well as keyboard button presses.

Set out test results in a tabular form as follows. It is important that the output listings (i.e., screenshots) are not edited in any way.

 

Test Data Table

Test data type
Test data
The reason it was selected
The output expected due to the use of the test data
The screenshot of actual output when the test data is used

Normal
 
 
 
 

Normal
 
 
 
 

Abnormal
 
 
 
 

Abnormal
 
 
 
 

Task 3

Implement your program in Python. Comment on your code as necessary to explain it clearly.  Run your program using the test data you have selected and complete the final column of test data table above.

Your submission will consist of:

Your algorithm through flowchart/s
The table recording your chosen test data and results
Source code for your Python implementation

Thus your directory for Assignment will at least contain two or three files (depending on whether you put the flowchart and the test table in the same file).

It is critically important that your test runs are unmodified outputs from your program, and that these results should be reproducible by the marker running your saved .py python program.

RATIONALE

back to top

This assessment task will work towards assessing the following learning outcome/s:

be able to analyse the steps involved in a disciplined approach to problem-solving, algorithm development and coding.
be able to demonstrate and explain elements of good programming style.
be able to identify, isolate and correct errors; and evaluate the corrections in all phases of the programming process.
be able to interpret and implement algorithms and program code.
be able to apply sound program analysis, design, coding, debugging, testing and documentation techniques to simple programming problems.
be able to write code in an appropriate coding language.

MARKING CRITERIA AND STANDARDS

back to top

Criteria
High Distinction
Distinction
Credit
Pass
Fail

Flowcharts

(3 marks)

Algorithm design is efficient in terms of time and memory.
Flowcharts precisely describe the algorithm design.

Flowcharts do not have any unnecessary component.

Flowcharts have at most one notation error.

Algorithm matches the program code.

Flowcharts follow the convention, contain at most three notation errors and produce algorithm at a high level.
Does not meet Pass criteria.

Testing documentation

(3 marks)

Test data is explores every branch of the program.

To demonstrate comprehensive testing, number of test cases exceeds the required minimum.

Sound justification is provided for the selection of test data.

Diversity is evident among the chosen test data.

Minimum required number of normal and abnormal test cases are collected.

Brief reasoning is provided for the test data selection.

Selected test data is clearly presented in required table format.

At least two normal and two abnormal test cases are provided.

Test results are reproducible.

Does not meet Pass criteria.

Program functionality

(6 marks)

Python code contains only necessary statements and variables.
Program meets all specifications.

Output format is correct as required.

Python code produces correct results.

Output has minor formatting errors.

Functionality is mostly implemented but code may contain minor syntax or logical errors.
Python code is produced that does not execute properly. It may contain
lot of syntax errors and/or produce completely incorrect results.

Code style

 

(3 marks)

Code includes function header comments and module level docstrings.
Code design is modular, containing several reusable functions.

Named constants are used instead of magic numbers.

White space is appropriately used for code readability.

Avoids unnecessary global variables.

All variables have meaningful names.

Sufficient inline comments are present.

Indentation is consistent throughout.

Functions are used but they are not generic (reusable).

Uses many global variables.

Most variables have unambiguous names.

Small number of inline comments.

Incomplete or largely dysfunctional code.

Additional Note: The standards outlined for each criteria are cumulative. So, for example, to achieve the standard for high distinction your work also needs to meet the standards outlined for Pass, Credit and Distinction levels.

PRESENTATION

back to top

You have to prepare and present all source code, test data table, and flowchart/s separately and include them all in a single MS Word file identified by your name. See the ‘Requirements’ section below. The Python source code you write should be saved with a name such as ITC558assignment2YourName.py and then include a copy of it as text in the MS Word file named ITC558assignment2YourName.docx.

The other parts of the assignment (such as your flowchart/s and your table of test data) should be included in the same MS Word file and save as ITC558assignment2YourName.docx.

It is critically important that your test runs are unmodified outputs from your program, and that these results should be reproducible by the marker running your saved ITC558assignment2YourName.py python program.

REQUIREMENTS

back to top

You have to save all the parts of the assignment (as described under ‘Presentation’ above) into a single MS Word document identified by your name as outlined in the section on presentation.

Failure to adhere to these requirements may disqualify the submission for marking.

Submit your complete assignment in MS Word format to Turnitin and insert your program source code as an object to your MS Word document (The subject lecturer will explain to you how to insert the object to your MS Word document).

 

Is this question part of your Assignment?

We can help

Our aim is to help you get A+ grades on your Coursework.

We handle assignments in a multiplicity of subject areas including Admission Essays, General Essays, Case Studies, Coursework, Dissertations, Editing, Research Papers, and Research proposals

Header Button Label: Get Started NowGet Started Header Button Label: View writing samplesView writing samples