|
1. |
Define a command triangle(color) with which the turtle can draw colored triangles. Draw 4 triangles with the colors red, green, blue and violet.
|
|
|
|
2. |
Define a command colorCircle(radius, color) with which the turtle draws a colored circle. You can use the command rightArc(radius, angle). Make the adjacent figure.
|
|
|
|
3. |
Unfortunately, the following program draws 3 equally sized pentagons instead of the expected differently sized ones. Why is this? Fix it.
from gturtle import *
def pentagon(sidelength, color):
setPenColor(color)
repeat 5:
forward(90)
left(72)
makeTurtle()
pentagon(100, "red")
left(120)
pentagon(80, "green")
left(120)
pentagon(60, "violet")
Highlight program code
(Ctrl+C copy, Ctrl+V paste) |
4. |
Using the command segment(s, w), you tell the turtle that it should move a certain distance s forward and to rotate by a certain angle w:
def segment(s, w):
forward(s)
right(w)
Write a program that runs this command 92 times with s = 300 and w = 151. Using setPos(x, y) you can start with the turtle at a suitable position in the window.
|
5*. |
The turtle will execute two, three, or four-segment movements. Check out the nice graphics in the following cases:
Number of Segments |
Values |
Number of Repetitions |
2 |
forward(77)
right(140.86)
forward(310)
right(112)
|
37 |
3 |
forward(15.4)
right(140.86)
forward(62)
right(112)
forwad(57.2)
right(130) |
46 |
4 |
forward(31)
right(141)
forward(112)
right(87.19)
forward(115.2)
right(130)
forward(186)
right(121.43) |
68 |
|
|