icon

Usetutoringspotscode to get 8% OFF on your first order!

1. Write a function, triangle(sz), that draws an equilateral triangle

1. Write a function, triangle(sz), that draws an equilateral triangle
with a horizontal base and each side of length sz. [What is the turn
angle required? You will make 3 equal angle turns, drawing the next side after each turn, and you
should return to the starting position and the starting angle.]
Sample run:
>>> triangle(120)

2. (20 pts) Write a function, sixPtdStar(sz), which uses triangle(sz) to draw a 6-pointed star by drawing 2 equilateral triangles and rotating one relative to the other.[Draw the first triangle. Properly place & point turtle for second triangle, then draw second triangle. Return turtle to the initial position and angle. When the 2 sides of one triangle intersect 1 side of the other triangle, the 1 side is trisected (divided into 3 equal lengths) by the 2 sides. The angle between each of the 2 sides of the one triangle and the 1 side of the other triangle is 60 deg. See notes added to star below.] Sample run:
>>> sixPtdStr(120)

3. Write a function, rowOfStars(numInRow,sz), which uses sixPtdStr(sz)
to make a row of numInRow 6-pointed stars each of side length sz.
[Draw a 6-pointed star, move forward; repeat.]
Sample run:
>>> rowOfStars(6,72)
4. Write a function, sqrOfRows(numInRow,sz), which uses rowOfStars(numInRow,sz)
to make a square bordered by numInRow 6-pointed starts, each of side length
sz. [ Draw a row of stars, turn; repeat.] Sample run:
>>> sqrOfRows(6,36)
5. Without writing the code, explain clearly in your own words how you would change your code so that, in each star, each of the 2 triangles used to draw the star is a different line color, say one is red, and the other is blue. Furthermore, the 2 colors should alternate from one star to the next:
Star 1: triangle 1 is blue, triangle 2 is red
Star 2: triangle 1 is red, triangle 2 is blue
etc.
Triangle 1 has a pointy top, triangle 2 has a pointy bottom.
What functions would you change? How would you change them? How would you alternate line colors from one star to the next?

6. [10 pts] For extra credit, write the python code for Q5. Code for this question will not be accepted without a clear explanation in your own words in Q5. My turtle screen for the modified sqrOfRows function is shown below. [Try using multiple assignment to switch the colors.]

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

1. Write a function, triangle(sz), that draws an equilateral triangle

1. Write a function, triangle(sz), that draws an equilateral triangle
with a horizontal base and each side of length sz. [What is the turn
angle required? You will make 3 equal angle turns, drawing the next side after each turn, and you
should return to the starting position and the starting angle.]
Sample run:
>>> triangle(120)

2. (20 pts) Write a function, sixPtdStar(sz), which uses triangle(sz) to draw a 6-pointed star by drawing 2 equilateral triangles and rotating one relative to the other.[Draw the first triangle. Properly place & point turtle for second triangle, then draw second triangle. Return turtle to the initial position and angle. When the 2 sides of one triangle intersect 1 side of the other triangle, the 1 side is trisected (divided into 3 equal lengths) by the 2 sides. The angle between each of the 2 sides of the one triangle and the 1 side of the other triangle is 60 deg. See notes added to star below.] Sample run:
>>> sixPtdStr(120)

3. Write a function, rowOfStars(numInRow,sz), which uses sixPtdStr(sz)
to make a row of numInRow 6-pointed stars each of side length sz.
[Draw a 6-pointed star, move forward; repeat.]
Sample run:
>>> rowOfStars(6,72)
4. Write a function, sqrOfRows(numInRow,sz), which uses rowOfStars(numInRow,sz)
to make a square bordered by numInRow 6-pointed starts, each of side length
sz. [ Draw a row of stars, turn; repeat.] Sample run:
>>> sqrOfRows(6,36)
5. Without writing the code, explain clearly in your own words how you would change your code so that, in each star, each of the 2 triangles used to draw the star is a different line color, say one is red, and the other is blue. Furthermore, the 2 colors should alternate from one star to the next:
Star 1: triangle 1 is blue, triangle 2 is red
Star 2: triangle 1 is red, triangle 2 is blue
etc.
Triangle 1 has a pointy top, triangle 2 has a pointy bottom.
What functions would you change? How would you change them? How would you alternate line colors from one star to the next?

6. [10 pts] For extra credit, write the python code for Q5. Code for this question will not be accepted without a clear explanation in your own words in Q5. My turtle screen for the modified sqrOfRows function is shown below. [Try using multiple assignment to switch the colors.]

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes