2014-10-18 2 views
1

반복되는 모양을 원하는면의 수, 반복해야하는 횟수 및 배경의 색상을 묻는 반복 패턴 프로그램을 파이썬에서 만들려고합니다. 모양 채우기. 측면을 360으로 나누기 전에 모양을 그려야합니다. 그러나 계속해서 그 자리에서 계속 반복됩니다. 내 코드는 아래와 같습니다.파이썬에서 변수가있는 반복 패턴

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 

답변

0

봅니다 수정할 수 while -loop

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

end_fill() 후 어쩌면 다른 위치에 다음 모양을 그릴 goto(100, 100)를 사용하여 다른 위치로 이동합니다.