龟本身绘制图形 [英] Turtle graphics drawing over itself

查看:182
本文介绍了龟本身绘制图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是一个非常简单的问题,然而,这对我来说很困难。我对龟图形颇为陌生,所以我正在尝试完成一个简单的绘图。我的乌龟会画一排,拿起笔,向上移动一个像素,放下笔,然后继续绘画。以下是我的代码:

  for y在范围内(高度):
turtle.pendown()
为范围(宽度)x:
detLand(y,x)#设置颜色,工作正常
turtle.setx(x)
turtle.sety(y)
turtle.penup()

我认为这很容易,但它仍然在顶层我的线。

解决方案

我相信问题在于您意外地在仰泳上画画。试试这个:

  for y在范围内(高度):
turtle.sety(y)

turtle.pendown()

为范围(宽度)x:
detLand(y,x)
turtle.setx(x)

turtle.penup()

turtle.setx(0)

我相信你的问题是这种分裂:

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

想想在行尾会发生什么,您只需设置Y,然后绕过X = 0并在Y正确定位之前画出刚完成的线。


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.

解决方案

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.

这篇关于龟本身绘制图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆