Turtle graphics module in python programming language, Python Programming

Your assignment for the semester will involve the development of a system for drawing trees using the Python programming language and the turtle graphics module (turtle.py). Completion of the assignment will involve the use of many of the programming constructs that you have seen previously in the labs. Your assignment mark constitutes 10% of your overall final module mark. If you get stuck, remember to ask for help - that's what the lab sessions are for!

Note: A model answer for the last question in lab 17+18 has been posted to the assignment directory. It is recommended that you use this file as a starting point for your program.


Your project will be to construct a system that allows you to draw trees using a fractal pattern similar to the Sierpinksi Triangle seen in the last two labs (Labs 17 and 18).

The remainder of this script guides you through the development of the system on a step-by-step basis and provides instructions for submission of your assignment.


Modify the code you used in Labs 17 and 18 for drawing the Sierpinski Triangle. Instead of drawing three lines at 120 degrees to each other, change your method so that it allows you to specify as parameters the number of lines to draw and their angle of separation. For example, if you draw 6 lines at an angle of 64 degrees, then the first step of the drawing should look like this:


As with the code for Labs 17 and 18, there should be a parameter that defines how much each line is reduced each step. If the reduction is by 0.5, then for the next step of the drawing, 6 further lines are recursively drawn from the end points of the previous 6 lines each in the same pattern as above but reduced in size (in a manner similar to the way the Sierpinski's Triangle was drawn). This ends up looking like this:

Repeating this for the next step, the drawing will end up looking like this:

After 5 steps, the drawing looks like this:

As with the code for Labs 17 and 18, the code should contain parameters that allow you to modify the following: 
• The initial heading of the first line drawn;
• The initial x and y co-ordinates of where the drawing should begin.
Add yet further parameters so that you can also specify the following:
• The initial thickness of the lines drawn;
• The ratio at which the thickness of the lines gets reduced each step (if this is set to 1.0, then the thickness remains the same for all lines drawn).


Allow the user to enter the parameters prior to the drawing of the fractal pattern. For example, ask the user what angle of separation they would like, the number of lines to draw, the length of the initial lines, how much each line is reduced each step, and the value of the four parameters listed above. This will allow you to easily try out many different configurations when testing your program. (Note: In the report you submit for your assignment, make sure you include a section on how you tested your program, along with screenshots that show it working).


Change your program so that multiple trees can be drawn. Add a further two parameters that define the number of trees that will be drawn, as well as the width between them (along the x axis). Then draw the forest of trees once the user has finished inputting the values of all the parameters.
For example, if the user wanted to draw 3 trees in their forest, separated by 10 units when the length of the initial lines is also set at 10 units, then the output would look something like this:

1916_tree m.png

Repeating this five times, the output would look like this:


So far the trees you have drawn are very regular. Add some randomness to your drawings so that the colour is randomly chosen for each line drawn rather than the same at each recursive step (as in the above images). Add further randomness by randomly choosing to stop drawing a percentage of some of the lines (and therefore all the lines that would have been recursively drawn latter on for those lines). This should result in lop-sided trees that look a bit more like trees do in nature. For example, in the following image, the leftmost tree has all its "branches", but the middle tree has randomly lost two of its branches, and the rightmost tree has lost three:

Repeating this random growth pattern for the next four steps might end up with a forest that looks like the following:



Thoroughly test your code out by getting it to draw different forests using different values for the user input. Post screenshots of the output of your program. Marks will be awarded for the variety of the screenshots.


Remember to structure your code neatly by indenting correctly and including blank lines occasionally such that it is easier to follow. Include comments using the ‘#' symbol to explain how your code works. If your code looks like spaghetti to you, imagine how it will look to another programmer who has never seen your code before! You will gain marks for following correct coding conventions here.


You've commented your code and structured it neatly so that other programmers will be able to follow your code but what about those people who are less-technically minded who will actually be using your program? Write a user guide explaining how your program works. Include screenshots guiding a user through the process of operating your software. Bear in mind that these users are likely not programmers themselves.

You will gain marks for the presentation & clarity of your work here.

Posted Date: 2/28/2013 1:51:51 AM | Location : United States

Related Discussions:- Turtle graphics module in python programming language, Assignment Help, Ask Question on Turtle graphics module in python programming language, Get Answer, Expert's Help, Turtle graphics module in python programming language Discussions

Write discussion on Turtle graphics module in python programming language
Your posts are moderated
Related Questions
Rewrite the area.py program (shown below, or in the Creating Functions section of the tutorial) so that it has separate functions for the perimeter and area of a square, a rectangl

Task This problem creates a list containing names. The list of names will be printed, sorted, printed again in the new sorted order, written to a new output file, and searched. Ca

Internal models As we want to create  more and more complex  machine with  software programs as controllers, we search  that  it is often needful  to create  additional types

Primitives, Composition, Abstraction, and Patterns   We will  start  by thinking about  how  the  PCAP  framework applies to computer programs, in general. We may do that by

Your task is to construct a translator from the subset of Python in Project 3 intocontinuation-passing style (CPS). Of course, the expected way of accomplishing this is to trans

Define a function that draws a pentagon of a size you provide when you call the function. Include a ''''''docstring'''''' as the first line of the function''s body — it tells the p

1)    Write a python programmecomparing for and while loops like the following. Math Times table For Loop: 2x1=2 2x2=4 ..... 2x12=24 While Loop: 3x1=3 3x

Programming models Just  as there  are several methods for organizing entire  software systems, there  are  different strategies for formally expressing computational processe

Variables We cannot  go very far without variables. A variable is a value related to a name that we can bind  to have a particular value  and  then  later use in an expression.

Every programming language has to have  some method for indicating grouping of operations. Here is how you execute an if-then-else structure in Java:   if (s == 1){ s = s