Python Forum
Turtle Graphics Help - Filling each shape in
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turtle Graphics Help - Filling each shape in
#5
(Nov-14-2018, 11:14 PM)ichabod801 Wrote: 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:

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.
How do i make it stop at the half length point to draw the arrows? Thanks
Reply


Messages In This Thread
Turtle Graphics Help - by Nate - Nov-14-2018, 05:45 PM
RE: Turtle Graphics Help - by ichabod801 - Nov-14-2018, 11:14 PM
RE: Turtle Graphics Help - by Nate - Nov-15-2018, 04:39 AM
RE: Turtle Graphics Help - by ichabod801 - Nov-15-2018, 03:07 PM
RE: Turtle Graphics Help - by Nate - Nov-16-2018, 04:21 AM
RE: Turtle Graphics Help - by ichabod801 - Nov-16-2018, 04:26 AM
RE: Turtle Graphics Help - by Nate - Nov-16-2018, 04:53 AM
RE: Turtle Graphics Help - by ichabod801 - Nov-16-2018, 02:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Project 4 Shape Calculator FreeCodeCamp btownboy 5 2,976 Sep-14-2020, 01:38 AM
Last Post: btownboy
  python idle turtle graphics help jojo 5 4,197 Apr-14-2019, 12:28 PM
Last Post: ichabod801
  Turtle Graphics Card Values in a List Muzz 0 2,438 Apr-11-2019, 12:55 PM
Last Post: Muzz
  why is this not filling my empty list? Siylo 4 3,308 Jan-21-2019, 05:27 PM
Last Post: Siylo
  ValueError: shape mismatch: value array of shape... ulrich48155 2 24,002 Jul-10-2017, 02:17 PM
Last Post: ulrich48155

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020