简体   繁体   中英

repeating pattern with variables in python

I'm trying to make a repeating pattern program in Python that asks you for how many sides you want the repeated shape to be, how many times it should be repeated and the color of the background and shape fill. It should draw the shape before turning by 360 divided by the amount of sides. However, it keeps repeating on the spot continually. My code is below.

from turtle import*

bgColor = input("What colour background do you want?:  ")
fillColor = input("What colour shape fill do you want?:  ")
numberOfSides = int(input("How many sides?:  "))
rotationsWanted = int(input("How many rotations?:  "))
rotationsCompleted = 0

def drawshape():
    fillcolor(fillColor)
    bgcolor(bgColor)
    begin_fill()
    while (rotationsCompleted < rotationsWanted):

        for x in range(numberOfSides):

            forward (100)
            right(360/numberOfSides)

        end_fill()

drawshape()
right(360/rotationsWanted)
rotationsCompleted = rotationsCompleted + 1

Try to modify the while -loop

rotationsCompleted = 0
while (rotationsCompleted < rotationsWanted):
    rotationsCompleted = rotationsCompleted + 1

and after end_fill() you should go to an other position maybe using goto(100, 100) to draw the next shape at a different position.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM