turtle graphics - spacing drawing shapes

Viewed 492

In the code below, how can I give some space after drawing each shape and then draw the next shape.

from turtle import *

color('black','green')
shape('turtle')
pensize(5)
speed(1)

def makeShape (numSides):
    for i in range(numSides):
        forward(100)
        left(360.0/numSides)
        i += 1
        

for i in range(3,13):
    makeShape(i)
2 Answers

For example, you can change the code like this:

space = [10, 30, 50]
for i in range(3,6):
    makeShape(i)
    up()
    setpos(space[i-3], space[i-3])
    down()

The numbers are test and you can change the numbers for the distances according to your needs.

Use the penup() and pendown() functions, which stop and start the 'Drawing mode' respectively.

Then just move the pen forward in the direction needed!

A function might look something like this:

def somespace(spaceamount):
    penup()
    forward(spaceamount)
    pendown()

then just call it with the rest of your code:

--snip--
for i in range(3,13):
    makeShape(i)
    # orientate shape here if needed
    somespace(50) # give space of 50
Related