The main purpose of this project was to learn more about python, coding in python, and drawing using the turtle module to draw a scene. Another purpose of the project was to write function to draw simple shapes in turtle to then use to write functions that draw aggregate shape and then uses theses aggregate shapes to draw an outdoor scene. .First, I wrote the code for two simple shape functions an equilateral triangle function and a trapezoid function. To write the triangle function I first used the goto function to lab to set the x, and y location and then used the loop below to draw each side of the triangle.
for i in range(3): turtle.forward(side_length) turtle.left(120)
for i in range(3):
However, for the trapezoid function I was unable to write it with a loop because the sides are not regular so I wrote the shape more directly by making the turtle go forward by the side_length parameter and then turned left by 120 degrees and went forward 1/2 the side length for the angular side of the trapezoid, then I drew the top of the trapezoid to be 3/4 of the side_length parameter, turned again and drew the other side, and then reconnected the bottom of the second angular side to the beginning of the where the function started using turtle's built in goto function.
For the new aggregate function not made in lab I wrote functions that draw a pine tree, mountain range, cloud, and a rock function. However the two main aggregate shapes are the pine tree and mountain range functions.
For the pine tree function I used the block function from lab for the trunk, 3 trapezoids decreasing in size on top of each other for the levels of the tree, and then a triangle on the top of the smallest trapezoid for the top of the tree as seen in the code below.
trapezoid(x, y+50*scale, 100*scale)
trapezoid(x + 12.5*scale, y + 93.*scale, 75*scale)
trapezoid(x + 18.75*scale, y + 125.25*scale, 50*scale)
triangle(x + 17.5*scale, y + 146.75*scale, 35*scale)
In the pine tree code I also colored in the tree as one of the extension options by using the turtle.fill(True) and then turtle.color('SaddleBrown') to fill in the trunk as brown and then before the trapezoids and the triangle were executed I wrote in turtle.color('dark green') to make the tree part a green color similar to most pine trees.
For the mountain range function I place four triangles at the same y starting points but with different x points and side length so it form four intersecting triangles that resembles a mountain range as seen below.
triangle( x, y, 100*scale)
triangle( x + 25*scale, y, 90*scale)
triangle( x + 50*scale, y, 80*scale)
triangle(x-25*scale, y, 75*scale)
I also used the turtle.fill and turtle.color functions to fill in the mountain ranges with the slate gray color and then returned the turtle color back to its standard black at the end of the function.
For the cloud function I used the built in turtle.circle function and the goto function we wrote in lab to draw three tangent circle with a radius of scale parameter and with one circle place one radius to the right and then another circle one radius to the left of the starting point x,y as seen in the code snippet below.
goto(x + (scale), y)
I then used the turtle.fill and turtle.color functions to fill in the clouds with the color mint cream.
Lastly I wrote a function that when spread out in a large number over a set area is meant to look like a bunch of rocks stuck on top of each other. I did this by placing four blocks on each other in a cross-hitched esque pattern by placing the block on either side of the center one and other blocks flipped and placed on top of the other ones. I also filled in the rocks with the color sienna using the turtle.fill and turtle.color functions.
I then used a combination of the above function to create two different scenes of the Great Main Outdoors. For the first outdoor function I set the turtle background color to steel blue using the function turtle.bgcolor, then I called the mountain range function in different locations and different scale three times as seen below.
Then I changed the turtle color to 'snow' and called a large block using the block function to make the ground as seen below.
Lastly I called the pine tree function 100 times, using the for i in range(100) loop, in random locations using the random.randint function with a scaling factor of 0.5. This can be seen in the code portion below: After the code placed below I placed one more mountain range in front of the trees.
for i in range(100):
To create the second out doors function I first called the cloud function 175 times using the for i in range(175) loop and then called the cloud function over the interval -450,450 in the x direction and 75,400 in the y direction with a scale of the guass distribution of 20 with a standard deviation of 5. For reference see the example code below.
for i in range(175): shapelib.cloud(random.randint(-450,450),random.randint(75,400),random.gauss(20,5))
for i in range(175):
Then to form the ground and make it seems like a group of rocks stack on top of each other I called the rock function 400 times using a loop with an x rang of -450,450 and a y range of -450,-250 and a scaling faction randomly selected between .25 and .5 for reference see the example code below.
for i in range(400):
Then I called the mountain range 15 times using another loop and placed between an x range between -350 and 450 and a y location between -10 and 10 with a scale factor of 2.
I then called a block at location -550,-215 a width of 1100 and a height of 215 and changed the turtle color to navy to make the water in the image. Lastly I changed the turtle color to orange and placed a circle at the location (-200,100) with a radius of 75 to be the sun during a sunset.
The main extention code I used in the outdoors scene is the use of the random function to place the aggregate shapes in the scene (as seen in the code snippets above) and to change the background color, and to fill in and color the shapes that make up the scenes.
In the completion of this project I learned how to use the random module to set up an interval where shapes are randomly placed within or assigned a size using, how to use simple shapes to form aggregate shapes, how to use the turtle module's fill and color functions to color in objects and scenes, and how to make loops that repeat a process a set amount of times
People/Resources Consulted: Professor Maxwell(during lab period), Python Programming by John Zelle, and tutorial for using color on the python website, and the tutorial for using the random module of the python website.
Required Image 1 Random Generation of Simple shapes to show test them:
Required Image 2:Random Generation of 2 primary aggregate shapes to make sure they work
Outdoor Scene 1: Scene visible on Sugarloaf
Outdoors Scene 2: Scene from Cadillac Mountain