Search code examples
pythonpython-turtle

Using turtle import to print shapes diagonally


So far I have

draw the shape of triangles across the page of increasing size

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

but I can't figure out how to print them in a straight diagonal line upwards to achieve > the aim


Solution

  • You can add a rotation to go in the right direction at the beginning. Then draw the triangle to the right instead of the left and you have it.

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