【问题标题】:Turtle Graphics with non-linear characters具有非线性字符的海龟图形
【发布时间】:2020-04-01 13:14:23
【问题描述】:

我目前正在尝试编写一个包含字母 X、数字 3 和 5 的 Python 程序。确切地说,“X35S”

我试图不使用 turtle.write 函数,而只使用命令。目前,我的代码如下:

import turtle

turtle.down ( )
turtle.color("red")
turtle.speed(0)
turtle.pensize(7)

turtle.right (45)
turtle.forward (70)
turtle.backward (140)
turtle.forward (70)
turtle.left (90)
turtle.forward (70)
turtle.backward (140) 

但我不确定如何绘制 5、3 或 S(我对非直线感到困惑)。谢谢!

【问题讨论】:

  • 使用更短的线条和更小的角度来获得更平滑的圆部分。这意味着您将不得不画更多的线 - 但使用for-loop 不会那么难。

标签: python turtle-graphics


【解决方案1】:

要绘制更平滑的圆角元素,您必须以更小角度绘制更多短线。
但是使用for-loop 没问题。我在圆圈上显示它。

import turtle

def circle(parts=360, line=1):
    for x in range(parts):
        turtle.forward(line)
        turtle.left(360/parts)

def move():
    turtle.up()
    turtle.forward(150)
    turtle.down()

turtle.tracer(False)

circle(6, 360/6)
move()
circle(10, 360/10)
move()
circle(20, 360/20)
move()
circle(30, 360/30)
move()
circle(360, 360/360)

turtle.update()    

与半圆类似

import turtle

def halfcircle(parts=360, line=1, direction=1):
    for x in range(parts//2):
        turtle.forward(line)
        turtle.left(360/parts * direction)

turtle.tracer(False)

for x in range(2):
    halfcircle(20, 360/30, 1)
    halfcircle(20, 360/30, -1)

turtle.update()   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-30
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 2011-11-05
    • 1970-01-01
    相关资源
    最近更新 更多