1

到目前为止我有

在页面上绘制三角形的形状,尺寸越来越大

from turtle import *
number_of_shapes = 4

for shapes in range(1, number_of_shapes + 1):
#draw a triangle
for side in range(1, 4):
    forward(30 + shapes * 10)
    left(120)

move forward to start position of next triangle
penup()
forward(40 + shapes *10)
pendown()

但我不知道如何在对角线上向上打印它们以实现>目标

4

1 回答 1

0

您可以在开始时添加一个旋转以朝正确的方向前进。然后把三角形画到右边而不是左边,你就有了。

from turtle import *
number_of_shapes = 4

left(60) # Added
for shapes in range(1, number_of_shapes + 1):
    for side in range(1, 4):
        forward(30 + shapes * 10)
        right(120) # Edited

    # move forward to start position of next triangle
    penup()
    forward(40 + shapes *10)
    pendown()
于 2020-04-16T16:12:52.997 回答