Turtle graphics drawing over itself

拥有回忆 提交于 2019-12-04 05:16:09

问题


This should be a very simple question, however, it is proving difficult for me. I'm rather new to turtle graphics, and so, I am trying to get a simple drawing done. My turtle will draw a row, pick the pen up, move up one pixel, place the pen down, and keep drawing. Here's my code so far:

for y in range(height):
  turtle.pendown()
  for x in range(width):
    detLand(y, x) # Set the color, works just fine
    turtle.setx(x)
    turtle.sety(y)
  turtle.penup()

I figured this would be easy, however, it's still drawing over top of my lines.


回答1:


I believe the problem is that you're accidentally drawing on the backstroke. Try this instead:

for y in range(height):
    turtle.sety(y)

    turtle.pendown()

    for x in range(width):
        detLand(y, x)
        turtle.setx(x)

    turtle.penup()

    turtle.setx(0)

I believe your problem is this schism:

turtle.setx(x)
turtle.sety(y)

Think about what happens at end of line, you just set Y and then you come around with X = 0 and over draw the line you just finished before Y gets positioned correctly.



来源:https://stackoverflow.com/questions/40984799/turtle-graphics-drawing-over-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!