import turtle
import math
turtle.speed(6)
#set to "fast" speed

## Color
colorList1 = ["#4D5558", "#F2E3B6", "#FFDF85", "#F29966", "#D95252"]
colorList2 = ["#F2F2F2", "#C6E070", "#91C46C", "#287D7D", "#1C344C"]
colorList3 = ["#F2F2E9", "#D9D7C5", "#A69580", "#736766", "#734854"]
colorList4 = ["#FDEDD0", "#BCF1ED", "#FF634D", "#FD795B", "#FFF0AA"]
colorList5 = ["#655499", "#6093BF", "#68D4D4", "#56BF95", "#17996B"]
colorList6 = ["#48474A", "#5F5266", "#99718B", "#CF8998", "#FFADBF"]
colorSet = [colorList1, colorList2, colorList3, colorList4, colorList5, colorList6]

##Visual Settings
eachLineNum = 1
rowNum = 1
quiltWidth = 800
glbLineWidth = 2
glbPenColor = ("#333333")


##Viarables
colorCount = 6
patternCount = 5 # don't change this
glbBlockLength = quiltWidth / eachLineNum
gap = glbBlockLength/10
turtle.color(glbPenColor)
turtle.width(glbLineWidth)
beginPos = turtle.pos()
quiltFrameWidth = gap * 5
quiltBGWidth = glbBlockLength * eachLineNum + gap * ( eachLineNum - 1)
quiltBGHeight = glbBlockLength * rowNum + gap * ( rowNum - 1)

##set initial position
turtle.penup()
##turtle.setpos(-glbBlockLength*(eachLineNum/2),glbBlockLength*(eachLineNum/2))
turtle.setpos(-(glbBlockLength*eachLineNum+gap*eachLineNum+quiltFrameWidth*2)/2,(glbBlockLength*rowNum+gap*rowNum+quiltFrameWidth*2)/2)
turtle.setpos(-glbBlockLength/2, glbBlockLength/2)
turtle.pendown()


####################
#### FUNCTIONs #####
####################

##
##Define Block Square, etc
def drawBlockSq():
    for i in range (0,4):
        turtle.forward(glbBlockLength)
        turtle.right(90)

def drawSquare(length):
    for i in range (0,4):
        turtle.forward(length)
        turtle.right(90)

def gotoBlockCenter(degree, halfsize):
    turtle.penup()
    turtle.forward(glbBlockLength/halfsize)
    turtle.right(90*degree)
    turtle.forward(glbBlockLength/halfsize)
    turtle.pendown()

def moveRightHalfBlock():
    turtle.penup()
    turtle.seth(0)
    turtle.forward(glbBlockLength/2)
    turtle.pendown()

def drawHalfBlock(color):
    turtle.begin_fill ()
    turtle.fillcolor(color)
    drawSquare(glbBlockLength/2)
    turtle.end_fill ()

def gotoBeginPos():
    turtle.penup()
    turtle.goto(beginPos)
    turtle.seth(0)
    turtle.pendown()

def moveit(position):
    turtle.penup()
    turtle.goto(position)
    turtle.pendown()

def moveDivide(divide):
    turtle.penup()
    turtle.forward(glbBlockLength/divide)
    turtle.pendown()

###########################
####PATTERN Library
####
        
## No.1 Winding Ways
def windingWays(color1, color2, color3, color4, color5):
    beginPos = turtle.pos()
    turtle.write("Winding Ways")
    drawBlockSq()

    def drawArcPiece(color):
        turtle.begin_fill ()
        turtle.fillcolor(color)
        turtle.circle(glbBlockLength/2, 360/12)
        turtle.right(360/6)
        turtle.circle(glbBlockLength/2, -(360/12))
        turtle.right(360/6)
        turtle.circle(glbBlockLength/2, 360/12)
        turtle.end_fill ()

    def drawArcBlock(color):
        for i in range(0,2):
            drawArcPiece(color)
            turtle.right(90)
            drawArcPiece(color)
        gotoBlockCenter(-1,4)
        
    #1
    drawHalfBlock(color1)
    gotoBlockCenter(1,4)
    drawArcBlock(color2)
    
    moveRightHalfBlock()

    #2
    drawHalfBlock(color2)
    gotoBlockCenter(1,4)
    drawArcBlock(color1)

    turtle.penup()
    turtle.seth(0)
    turtle.backward(glbBlockLength/2)
    turtle.right(90)
    turtle.forward(glbBlockLength/2)
    turtle.right(-90)
    turtle.pendown()

    #3
    drawHalfBlock(color2)
    gotoBlockCenter(1,4)
    drawArcBlock(color1)

    moveRightHalfBlock()

    #4
    drawHalfBlock(color1)
    gotoBlockCenter(1,4)
    drawArcBlock(color2)

    #reset position
    gotoBeginPos()

###################### Pattern Library Ends here #################
         
##
##Define Fuction : Move turtle to the next position            
def nextPos():
    ## saved position + offset
    turtle.penup()
    turtle.goto(currentPos)
    turtle.seth(0)
    turtle.forward(glbBlockLength+gap)
    turtle.pendown()

##################### FUNCTIONS End here ###############################


##test drawing action
##draw a line of pattern from list       

colorChoice = colorList1
print "current color set", colorChoice
windingWays (colorChoice[0], colorChoice[1], colorChoice[2], colorChoice[3], colorChoice[4])

print " YEAH! "
turtle.exitonclick ()
