Nov-14-2018, 11:14 PM
First of all, your figures aren't filling because you're starting and ending the fill every time you draw a side. That's because begin_fill and end_fill are inside your loops. You being the fill, draw a side, turn for the next side, then end the fill. And the penup being in the octogon loop is why it isn't getting drawn. Unindent that one level so the pen comes up after all of the sides are drawn, rather than coming up after the first (and every other) side is drawn.
Second, naming your turtle turtle blocks access to the turtle module. One line 1, the name turtle points to the turtle module. On line 4 you point it at an instance of the Turtle class. Now you have nothing pointing at the turtle module. It doesn't make a difference here, but it's bad programming style that could cause a problem in other programs you write. I would name your turtle instance something different and unique. Like george.
I would also just have one loop. Calculate the angle, and then loop through the number of sides. So it would look something like this:
Note that to make the triangle shapes in the sample diagram, you would use george.stamp(). That would mean moving half of the length, stamping, and move the other half of the length.
Second, naming your turtle turtle blocks access to the turtle module. One line 1, the name turtle points to the turtle module. On line 4 you point it at an instance of the Turtle class. Now you have nothing pointing at the turtle module. It doesn't make a difference here, but it's bad programming style that could cause a problem in other programs you write. I would name your turtle instance something different and unique. Like george.
I would also just have one loop. Calculate the angle, and then loop through the number of sides. So it would look something like this:
angle = 360.0 / num_sides george.pendown() george.begin_fill() for side in range(num_sides): george.foward(side_length) george.right(angle) george.end_fill() george.penup()Then you can either add a parameter named num_sides to the drawingpoly function, or you can put the above loop into another for loop that goes through 4 to eight sides.
Note that to make the triangle shapes in the sample diagram, you would use george.stamp(). That would mean moving half of the length, stamping, and move the other half of the length.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures