Python turtle graphics filling issue












0















I'm supposed to draw a building for my Python class, and the fillcolor() function does its job for two of the shapes, but for the last shape, even though I finish the circuit so to speak, it won't fill it with the color I need:



import turtle

def main():
turtle.setup(900, 900)
cityscape(-300, -400, 300, 'gray')
cityscape(0, -400, 300, 'gray')
building(-300, -100, 'gray')
turtle.speed(0)

def cityscape(x, y, width, color):
turtle.penup()
turtle.goto(x, y)
turtle.pencolor('gray')
turtle.fillcolor(color)
turtle.pendown()
turtle.begin_fill()
for count in range(4):
turtle.forward(width)
turtle.left(90)
turtle.end_fill()

def building(x, y, color):
turtle.penup()
turtle.goto(x, y)
turtle.fillcolor(color)
turtle.pendown()
turtle.begin_fill()
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.right(180)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(250)
turtle.left(90)
turtle.forward(70)
turtle.left(90)
turtle.forward(175)
turtle.right(90)
turtle.forward(80)
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(70)
turtle.right(90)
turtle.forward(425)
turtle.right(90)
turtle.forward(425)


main()


How can I resolve this?










share|improve this question





























    0















    I'm supposed to draw a building for my Python class, and the fillcolor() function does its job for two of the shapes, but for the last shape, even though I finish the circuit so to speak, it won't fill it with the color I need:



    import turtle

    def main():
    turtle.setup(900, 900)
    cityscape(-300, -400, 300, 'gray')
    cityscape(0, -400, 300, 'gray')
    building(-300, -100, 'gray')
    turtle.speed(0)

    def cityscape(x, y, width, color):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pencolor('gray')
    turtle.fillcolor(color)
    turtle.pendown()
    turtle.begin_fill()
    for count in range(4):
    turtle.forward(width)
    turtle.left(90)
    turtle.end_fill()

    def building(x, y, color):
    turtle.penup()
    turtle.goto(x, y)
    turtle.fillcolor(color)
    turtle.pendown()
    turtle.begin_fill()
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(100)
    turtle.right(180)
    turtle.left(90)
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(200)
    turtle.right(90)
    turtle.forward(100)
    turtle.right(90)
    turtle.forward(250)
    turtle.left(90)
    turtle.forward(70)
    turtle.left(90)
    turtle.forward(175)
    turtle.right(90)
    turtle.forward(80)
    turtle.right(90)
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(70)
    turtle.right(90)
    turtle.forward(425)
    turtle.right(90)
    turtle.forward(425)


    main()


    How can I resolve this?










    share|improve this question



























      0












      0








      0








      I'm supposed to draw a building for my Python class, and the fillcolor() function does its job for two of the shapes, but for the last shape, even though I finish the circuit so to speak, it won't fill it with the color I need:



      import turtle

      def main():
      turtle.setup(900, 900)
      cityscape(-300, -400, 300, 'gray')
      cityscape(0, -400, 300, 'gray')
      building(-300, -100, 'gray')
      turtle.speed(0)

      def cityscape(x, y, width, color):
      turtle.penup()
      turtle.goto(x, y)
      turtle.pencolor('gray')
      turtle.fillcolor(color)
      turtle.pendown()
      turtle.begin_fill()
      for count in range(4):
      turtle.forward(width)
      turtle.left(90)
      turtle.end_fill()

      def building(x, y, color):
      turtle.penup()
      turtle.goto(x, y)
      turtle.fillcolor(color)
      turtle.pendown()
      turtle.begin_fill()
      turtle.forward(100)
      turtle.left(90)
      turtle.forward(100)
      turtle.right(180)
      turtle.left(90)
      turtle.forward(100)
      turtle.left(90)
      turtle.forward(200)
      turtle.right(90)
      turtle.forward(100)
      turtle.right(90)
      turtle.forward(250)
      turtle.left(90)
      turtle.forward(70)
      turtle.left(90)
      turtle.forward(175)
      turtle.right(90)
      turtle.forward(80)
      turtle.right(90)
      turtle.forward(100)
      turtle.left(90)
      turtle.forward(70)
      turtle.right(90)
      turtle.forward(425)
      turtle.right(90)
      turtle.forward(425)


      main()


      How can I resolve this?










      share|improve this question
















      I'm supposed to draw a building for my Python class, and the fillcolor() function does its job for two of the shapes, but for the last shape, even though I finish the circuit so to speak, it won't fill it with the color I need:



      import turtle

      def main():
      turtle.setup(900, 900)
      cityscape(-300, -400, 300, 'gray')
      cityscape(0, -400, 300, 'gray')
      building(-300, -100, 'gray')
      turtle.speed(0)

      def cityscape(x, y, width, color):
      turtle.penup()
      turtle.goto(x, y)
      turtle.pencolor('gray')
      turtle.fillcolor(color)
      turtle.pendown()
      turtle.begin_fill()
      for count in range(4):
      turtle.forward(width)
      turtle.left(90)
      turtle.end_fill()

      def building(x, y, color):
      turtle.penup()
      turtle.goto(x, y)
      turtle.fillcolor(color)
      turtle.pendown()
      turtle.begin_fill()
      turtle.forward(100)
      turtle.left(90)
      turtle.forward(100)
      turtle.right(180)
      turtle.left(90)
      turtle.forward(100)
      turtle.left(90)
      turtle.forward(200)
      turtle.right(90)
      turtle.forward(100)
      turtle.right(90)
      turtle.forward(250)
      turtle.left(90)
      turtle.forward(70)
      turtle.left(90)
      turtle.forward(175)
      turtle.right(90)
      turtle.forward(80)
      turtle.right(90)
      turtle.forward(100)
      turtle.left(90)
      turtle.forward(70)
      turtle.right(90)
      turtle.forward(425)
      turtle.right(90)
      turtle.forward(425)


      main()


      How can I resolve this?







      python turtle-graphics






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 23:36









      cdlane

      18.8k21144




      18.8k21144










      asked Nov 14 '18 at 22:40









      Donni BenottiDonni Benotti

      94




      94
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You left turtle.end_fill() off the end of your building() function. I'd also write main() as follows:



          def main():
          turtle.setup(900, 900)
          turtle.speed('fastest')
          cityscape(-300, -400, 300, 'gray')
          cityscape(0, -400, 300, 'gray')
          building(-300, -100, 'gray')
          turtle.mainloop()


          Complete code listing with the above fix and some style changes:



          from turtle import Screen, Turtle

          def main():
          screen = Screen()
          screen.setup(900, 900)

          yertle = Turtle(visible=False)
          yertle.speed('fastest')

          cityscape(yertle, -300, -400, 300, 'gray')
          cityscape(yertle, 0, -400, 300, 'gray')
          building(yertle, -300, -100, 'gray')

          screen.mainloop()

          def cityscape(turtle, x, y, width, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          for _ in range(4):
          turtle.forward(width)
          turtle.left(90)
          turtle.end_fill()

          def building(turtle, x, y, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(200)
          turtle.right(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(250)
          turtle.left(90)
          turtle.forward(70)
          turtle.left(90)
          turtle.forward(175)
          turtle.right(90)
          turtle.forward(80)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(70)
          turtle.right(90)
          turtle.forward(425)
          turtle.right(90)
          turtle.forward(425)
          turtle.end_fill()

          main()





          share|improve this answer


























          • So you're saying I need to place my end fill under def building instead of cityscape

            – Donni Benotti
            Nov 14 '18 at 23:30











          • @DonniBenotti, no, I'm saying you need one end_fill() for every begin_fill(). I'm adding a complete code listing to my answer.

            – cdlane
            Nov 14 '18 at 23:31













          • I misread that entirely the first time, I was a little stressed, but it worked out. thanks for your help. It turned out well in the end.

            – Donni Benotti
            Nov 14 '18 at 23:47











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309808%2fpython-turtle-graphics-filling-issue%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You left turtle.end_fill() off the end of your building() function. I'd also write main() as follows:



          def main():
          turtle.setup(900, 900)
          turtle.speed('fastest')
          cityscape(-300, -400, 300, 'gray')
          cityscape(0, -400, 300, 'gray')
          building(-300, -100, 'gray')
          turtle.mainloop()


          Complete code listing with the above fix and some style changes:



          from turtle import Screen, Turtle

          def main():
          screen = Screen()
          screen.setup(900, 900)

          yertle = Turtle(visible=False)
          yertle.speed('fastest')

          cityscape(yertle, -300, -400, 300, 'gray')
          cityscape(yertle, 0, -400, 300, 'gray')
          building(yertle, -300, -100, 'gray')

          screen.mainloop()

          def cityscape(turtle, x, y, width, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          for _ in range(4):
          turtle.forward(width)
          turtle.left(90)
          turtle.end_fill()

          def building(turtle, x, y, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(200)
          turtle.right(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(250)
          turtle.left(90)
          turtle.forward(70)
          turtle.left(90)
          turtle.forward(175)
          turtle.right(90)
          turtle.forward(80)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(70)
          turtle.right(90)
          turtle.forward(425)
          turtle.right(90)
          turtle.forward(425)
          turtle.end_fill()

          main()





          share|improve this answer


























          • So you're saying I need to place my end fill under def building instead of cityscape

            – Donni Benotti
            Nov 14 '18 at 23:30











          • @DonniBenotti, no, I'm saying you need one end_fill() for every begin_fill(). I'm adding a complete code listing to my answer.

            – cdlane
            Nov 14 '18 at 23:31













          • I misread that entirely the first time, I was a little stressed, but it worked out. thanks for your help. It turned out well in the end.

            – Donni Benotti
            Nov 14 '18 at 23:47
















          0














          You left turtle.end_fill() off the end of your building() function. I'd also write main() as follows:



          def main():
          turtle.setup(900, 900)
          turtle.speed('fastest')
          cityscape(-300, -400, 300, 'gray')
          cityscape(0, -400, 300, 'gray')
          building(-300, -100, 'gray')
          turtle.mainloop()


          Complete code listing with the above fix and some style changes:



          from turtle import Screen, Turtle

          def main():
          screen = Screen()
          screen.setup(900, 900)

          yertle = Turtle(visible=False)
          yertle.speed('fastest')

          cityscape(yertle, -300, -400, 300, 'gray')
          cityscape(yertle, 0, -400, 300, 'gray')
          building(yertle, -300, -100, 'gray')

          screen.mainloop()

          def cityscape(turtle, x, y, width, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          for _ in range(4):
          turtle.forward(width)
          turtle.left(90)
          turtle.end_fill()

          def building(turtle, x, y, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(200)
          turtle.right(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(250)
          turtle.left(90)
          turtle.forward(70)
          turtle.left(90)
          turtle.forward(175)
          turtle.right(90)
          turtle.forward(80)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(70)
          turtle.right(90)
          turtle.forward(425)
          turtle.right(90)
          turtle.forward(425)
          turtle.end_fill()

          main()





          share|improve this answer


























          • So you're saying I need to place my end fill under def building instead of cityscape

            – Donni Benotti
            Nov 14 '18 at 23:30











          • @DonniBenotti, no, I'm saying you need one end_fill() for every begin_fill(). I'm adding a complete code listing to my answer.

            – cdlane
            Nov 14 '18 at 23:31













          • I misread that entirely the first time, I was a little stressed, but it worked out. thanks for your help. It turned out well in the end.

            – Donni Benotti
            Nov 14 '18 at 23:47














          0












          0








          0







          You left turtle.end_fill() off the end of your building() function. I'd also write main() as follows:



          def main():
          turtle.setup(900, 900)
          turtle.speed('fastest')
          cityscape(-300, -400, 300, 'gray')
          cityscape(0, -400, 300, 'gray')
          building(-300, -100, 'gray')
          turtle.mainloop()


          Complete code listing with the above fix and some style changes:



          from turtle import Screen, Turtle

          def main():
          screen = Screen()
          screen.setup(900, 900)

          yertle = Turtle(visible=False)
          yertle.speed('fastest')

          cityscape(yertle, -300, -400, 300, 'gray')
          cityscape(yertle, 0, -400, 300, 'gray')
          building(yertle, -300, -100, 'gray')

          screen.mainloop()

          def cityscape(turtle, x, y, width, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          for _ in range(4):
          turtle.forward(width)
          turtle.left(90)
          turtle.end_fill()

          def building(turtle, x, y, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(200)
          turtle.right(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(250)
          turtle.left(90)
          turtle.forward(70)
          turtle.left(90)
          turtle.forward(175)
          turtle.right(90)
          turtle.forward(80)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(70)
          turtle.right(90)
          turtle.forward(425)
          turtle.right(90)
          turtle.forward(425)
          turtle.end_fill()

          main()





          share|improve this answer















          You left turtle.end_fill() off the end of your building() function. I'd also write main() as follows:



          def main():
          turtle.setup(900, 900)
          turtle.speed('fastest')
          cityscape(-300, -400, 300, 'gray')
          cityscape(0, -400, 300, 'gray')
          building(-300, -100, 'gray')
          turtle.mainloop()


          Complete code listing with the above fix and some style changes:



          from turtle import Screen, Turtle

          def main():
          screen = Screen()
          screen.setup(900, 900)

          yertle = Turtle(visible=False)
          yertle.speed('fastest')

          cityscape(yertle, -300, -400, 300, 'gray')
          cityscape(yertle, 0, -400, 300, 'gray')
          building(yertle, -300, -100, 'gray')

          screen.mainloop()

          def cityscape(turtle, x, y, width, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          for _ in range(4):
          turtle.forward(width)
          turtle.left(90)
          turtle.end_fill()

          def building(turtle, x, y, color):
          turtle.penup()
          turtle.goto(x, y)
          turtle.pendown()

          turtle.color(color)

          turtle.begin_fill()
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(200)
          turtle.right(90)
          turtle.forward(100)
          turtle.right(90)
          turtle.forward(250)
          turtle.left(90)
          turtle.forward(70)
          turtle.left(90)
          turtle.forward(175)
          turtle.right(90)
          turtle.forward(80)
          turtle.right(90)
          turtle.forward(100)
          turtle.left(90)
          turtle.forward(70)
          turtle.right(90)
          turtle.forward(425)
          turtle.right(90)
          turtle.forward(425)
          turtle.end_fill()

          main()






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 23:32

























          answered Nov 14 '18 at 23:23









          cdlanecdlane

          18.8k21144




          18.8k21144













          • So you're saying I need to place my end fill under def building instead of cityscape

            – Donni Benotti
            Nov 14 '18 at 23:30











          • @DonniBenotti, no, I'm saying you need one end_fill() for every begin_fill(). I'm adding a complete code listing to my answer.

            – cdlane
            Nov 14 '18 at 23:31













          • I misread that entirely the first time, I was a little stressed, but it worked out. thanks for your help. It turned out well in the end.

            – Donni Benotti
            Nov 14 '18 at 23:47



















          • So you're saying I need to place my end fill under def building instead of cityscape

            – Donni Benotti
            Nov 14 '18 at 23:30











          • @DonniBenotti, no, I'm saying you need one end_fill() for every begin_fill(). I'm adding a complete code listing to my answer.

            – cdlane
            Nov 14 '18 at 23:31













          • I misread that entirely the first time, I was a little stressed, but it worked out. thanks for your help. It turned out well in the end.

            – Donni Benotti
            Nov 14 '18 at 23:47

















          So you're saying I need to place my end fill under def building instead of cityscape

          – Donni Benotti
          Nov 14 '18 at 23:30





          So you're saying I need to place my end fill under def building instead of cityscape

          – Donni Benotti
          Nov 14 '18 at 23:30













          @DonniBenotti, no, I'm saying you need one end_fill() for every begin_fill(). I'm adding a complete code listing to my answer.

          – cdlane
          Nov 14 '18 at 23:31







          @DonniBenotti, no, I'm saying you need one end_fill() for every begin_fill(). I'm adding a complete code listing to my answer.

          – cdlane
          Nov 14 '18 at 23:31















          I misread that entirely the first time, I was a little stressed, but it worked out. thanks for your help. It turned out well in the end.

          – Donni Benotti
          Nov 14 '18 at 23:47





          I misread that entirely the first time, I was a little stressed, but it worked out. thanks for your help. It turned out well in the end.

          – Donni Benotti
          Nov 14 '18 at 23:47




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309808%2fpython-turtle-graphics-filling-issue%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma