python - turtle 图形在自身上绘制

标签 python python-3.x graphics turtle-graphics

这应该是一个非常简单的问题,然而,事实证明这对我来说很难。我对 turtle 图形相当陌生,因此,我正在尝试完成简单的绘图。我的 turtle 会画一行,拿起笔,向上移动一个像素,放下笔,然后继续绘画。到目前为止,这是我的代码:

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()

我认为这很容易,但是,它仍然超出了我的线条。

最佳答案

我认为问题在于您不小心在仰泳时画了画。试试这个:

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)

我相信你的问题是这种 split :

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

想想线末端会发生什么,你只需设置 Y,然后你就用 X = 0 来完成,并在 Y 正确定位之前过度绘制刚刚完成的线。

关于python - turtle 图形在自身上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40984799/

相关文章:

python - 使用Power方法从Python中的3x3矩阵获取特征值

python - 从已经运行的 python 脚本调用方法

c - Xiaolin Wu 的 C 线算法的源代码?

python - 根据 Django 中的模型, View /模板中项目的不同显示

python - 在Python中循环遍历文件目录

Mac OS Pycharm 上的 Python 给出框架错误 "import matplotlib.pyplot as plt"

python - 如何线程 Tweepy 流

python - 迭代列表以添加值

c++ - C++中的直线

cocoa - OpenGL 中的形状未正确设置在其他形状后面