Python Shapes
We moved on from Scratch to Python this week. To practice our new knowledge of functions we...
Design Critieria
Utilize Python to draw shapes. Practice by writing some simple functions that do things we already know how to do with for loops then draw different shapes with different sizes and colors.
Design Constraints
1. Download the starter code and familiarize yourself with its contents.
2. Draw a square using the “forward”, “right” or “left” functions.
3. Use a for loop
4. Store the size of the side of the square as `side_length`.
5. Use a for loop to draw an equilateral triangle.
6. Call your function to make sure it draws the exact same square and then again with the triangle
7. Add parameters to your square function to so that you can draw squares of different sizes and colors.
8. Do the same thing for your triangle function.
9. Recreate the following picture. Each square has a side of 50 pixels and are 10 pixels apart. You can pick whatever colors you want. a. Can you do the same thing with your triangles?
2. Draw a square using the “forward”, “right” or “left” functions.
3. Use a for loop
4. Store the size of the side of the square as `side_length`.
5. Use a for loop to draw an equilateral triangle.
6. Call your function to make sure it draws the exact same square and then again with the triangle
7. Add parameters to your square function to so that you can draw squares of different sizes and colors.
8. Do the same thing for your triangle function.
9. Recreate the following picture. Each square has a side of 50 pixels and are 10 pixels apart. You can pick whatever colors you want. a. Can you do the same thing with your triangles?
10. Write a function that can draw any regular polygon with any of the possible colors.
a. A regular polygon is any shape where all the sides and all the internal angles are the same.
Hint: The turtle draws the outside edges of the polygon. Each angle it draws will be a number of degrees that is (360 / number of sides).
d. Hint: regular_polygon(4, 50 , “red”) should give something that looks like this:
e. Hint : regular_polygon(3, 50, “green”)should give something that looks like this: f. What happens if you call regular_polygon(100, 5, “red”)?
11. You can make complex drawings just by repeating simple shapes at a slightly different angle or position each time. The following the drawing was built by repeatedly calling regular_polygon(5, 20, “maroon”)but moving the turtle two pixels forward each time. Trying playing around with repeated simple shapes but changing something small each time, like the angle the turtle is turned or where it is.
a. A regular polygon is any shape where all the sides and all the internal angles are the same.
Hint: The turtle draws the outside edges of the polygon. Each angle it draws will be a number of degrees that is (360 / number of sides).
d. Hint: regular_polygon(4, 50 , “red”) should give something that looks like this:
e. Hint : regular_polygon(3, 50, “green”)should give something that looks like this: f. What happens if you call regular_polygon(100, 5, “red”)?
11. You can make complex drawings just by repeating simple shapes at a slightly different angle or position each time. The following the drawing was built by repeatedly calling regular_polygon(5, 20, “maroon”)but moving the turtle two pixels forward each time. Trying playing around with repeated simple shapes but changing something small each time, like the angle the turtle is turned or where it is.