The goal of this project is to incorporate loops and conditionals into your code as well as provide more practice in encapsulating code and concepts for later re-use and manipulation.
First, re-write the block function to take advantage of looping, if you have not already done so.
Second, edit the block function so that if the fill variable
has the value True
, then the block should be filled. If the
fill variable has the value False
, then the block should not
be filled. You can use an if-statement before and after the drawing
commands for your block to control whether to call the turtle's fill
function.
You may also want to add an optional color argument to your block function. You can specify colors for the turtle using one of two methods: as a string, or as an rgb-tuple.
The strings you can use to specify colors are given here.
An rgb-tuple is simply three values in the range [0.0, 1.0] as a comma-separated list surrounded by parentheses. For example:
(0.15, 0.6, 0.2)
makes a nice artificial grass green. You can use an rgb-tuple or a string when calling the turtle.color function. The following two calls create identical colors.
turtle.color("Forest Green")
turtle.color( (0.13, 0.55, 0.13) )
Don't forget to add appropriate documentation for your functions. Each docstring should state what shape the function draws, and where and how big the shape will be (e.g. if the scale is 1, then this will draw a house with its upper left corner at (x,y) and will be 200 pixels high and 150 pixels ide).
If you wish, use conditional statements to enable variations on the complex shapes. For example, you can make any function call dependent upon a random number using the following type of test. In the example below, the block will be drawn 70% of the time.
if random.random() < 0.7: block(x, y, w, h, True)
If you have a scene that looks like the following:
def myScene(): '''This draws a scene with .........''' block(5, 10, 50, 100) triangle(5, 100, 50) goto(30, 30) turtle.forward(10) turtle.left(90) turtle.circle(20)
You can easily convert it to a scalable, moveable scene using the following rules. First, change the function to have parameters x, y, and scale.
block(a, b, c, d)
becomes block(x+a*scale, y+b*scale, c*scale, d*scale)
goto(a, b)
becomes goto(x + a*scale, y + b*scale)
turtle.forward(a)
becomes turtle.forward(a * scale)
Angles do not change. Following the above rules, the myscene function would be the following.
def myScene(x, y, scale): '''This draws a scene with .........''' block(x + 5*scale, y + 10*scale, 50*scale, 100*scale) triangle(x + 5*scale, y + 100*scale, 50*scale) goto(x + 30*scale, y + 30*scale) turtle.forward(10*scale) turtle.left(90) turtle.circle(20*scale)
The first required picture is an image with three differently sized versions of your scene.
The second required picture is an image with your first scene located inside a second scene.
The third and fourth required images should be examples of one of your scenes drawn using two different values for the command-line parameter.
Each assignment will have a set of suggested extensions. The required tasks constitute about 85% of the assignment, and if you do only the required tasks and do them well you will earn a B+. To earn a higher grade, you need to undertake one or more extensions. The difficulty and quality of the extension or extensions will determine your final grade for the assignment. One complex extension, done well, or 2-3 simple extensions are typical.
Before handing in your code, double check that it is well-styled:
Turn in your code by putting it into your private handin directory on the Courses server. All files should be organized in a folder titled Proj3 and you should include only those files necessary to run the program. We will grade all files turned in, so please do not turn in old, non-working, versions of files.
Make a new wiki page for your assignment. Put the label cs151s14project3 in the label field on the bottom of the page. But give the page a meaningful title (e.g. Kyle's project 3).
In general, your intended audience for your write-up is your peers not in the class. Your goal should be to be able to use it to explain to friends what you accomplished in this project and to give them a sense of how you did it. Follow the outline below.