# Lab5.py

# Name 1: Arianna Tolerton 

# Name 2: Meagan G. 



from graphics import *

import math 

def cupConverter():

    # Author: RoxAnn H. Stalvey, modified by Walter Pharr

    # Illustrates getting numeric input through graphics window

    winWidth = 300

    winHeight = 200

    win = GraphWin("Convert cups to milliliters", winWidth, winHeight)



    #Specify the message for the input box

    boxDesc = Text(Point(100, 50), "Input cups: ")

    boxDesc.draw(win)



    #Create the Entry object and set its default text to a number

    #  allowing the user to see what type of value is expected

    inp = Entry(Point(200, 50), 5)

    inp.setText("0")

    inp.draw(win)



    #Create a Text object for outputting the result

    output = Text(Point(150, 150), "")

    output.draw(win)



    #This button isn't necessary, but it makes a nice point for the user

    #  to click.  If you click anywhere in the window, the code reacts

    #  the same way.

    btPtX = winWidth/2

    btPtY = winHeight/2

    button = Text(Point(btPtX, btPtY), "Click")

    button.draw(win)

    border = Rectangle(Point(btPtX-35, btPtY-20), Point(btPtX+35, btPtY+20))

    border.draw(win)



    # Wait for a mouse click

    win.getMouse()



    # Discover intput and convert it to a number

    # If numeric input wasn't needed, simply omit the eval()

    cups = eval(inp.getText())



    #Calculate milliliter equivalent here

    CUP_TO_OUNCE_CONVERTER = 8

    OUNCE_TO_ML_CONVERTER = 29.57

    ounces= cups*CUP_TO_OUNCE_CONVERTER

    milliliters = ounces*OUNCE_TO_ML_CONVERTER



    # Display output and change button

    output.setText(str(cups) + " Cups = " + str(milliliters) + " ML")

    button.setText("Quit")

    

    # Wait for another click to exit

    win.getMouse()

    win.close()





def target():

    winWidth = 500

    winHeight = winWidth

    win = GraphWin("Archery Target", winWidth, winHeight)

    win.setBackground("green")



    # Add code here to get the dimensions and draw the target

    centerPoint=Point(winWidth/2,winHeight/2)

    whiteCirc=Circle(centerPoint,(winWidth/2))

    whiteCirc.draw(win)

    whiteCirc.setFill("white")



    blackCirc=Circle(centerPoint,(winWidth*(2/5)))

    blackCirc.setFill("black")

    blackCirc.draw(win)



    blueCirc=Circle(centerPoint,(winWidth*(3/10)))

    blueCirc.setFill("blue")

    blueCirc.draw(win)



    redCirc=Circle(centerPoint,(winHeight*(1/5)))

    redCirc.setFill("red")

    redCirc.draw(win)



    yellowCirc=Circle(centerPoint,(winHeight*(1/10)))

    yellowCirc.setFill("yellow")

    yellowCirc.draw(win)



    instPt = Point((winWidth/2),(winHeight-10))

    instructions = Text(instPt,"Click to Exit")

    instructions.setFill("black")

    instructions.draw(win)

    

    # Wait for another click to exit

    win.getMouse()

    win.close()

    







def triangle():

    winWidth = 500

    winHeight = 500

    win = GraphWin("Draw a Triangle", winWidth, winHeight)



    # Add code here to accept the mouse clicks, draw the triangle.

    instPt = Point(winWidth/2, winHeight -10)

    instructions = Text(instPt, "Click to get Point A")

    instructions.draw(win)

    ptA=win.getMouse()

    instructions.setText("Click to get Point B")

    ptB= win.getMouse()

    instructions.setText("Click to get Point C")

    ptC= win.getMouse()

    shape = Polygon(ptA,ptB,ptC)

    shape.setFill("purple")

    shape.draw(win)

    # and display its area in the graphics window.

    clickX = ptA.getX()

    clickY = ptA.getY()

    clickX2 = ptB.getX()

    clickY2 = ptB.getY()

    clickX3 = ptC.getX()

    clickY3 = ptC.getY()



    lengthAToB = math.sqrt(((clickX2-clickX)**2)+((clickY2-clickY)**2))

    lengthBToC = math.sqrt(((clickX3-clickX2)**2)+((clickY3-clickY2)**2))

    lengthCToA = math.sqrt(((clickX3-clickX)**2)+((clickY3-clickY)**2))



    perimeter = lengthAToB + lengthBToC + lengthCToA





    side = (lengthAToB + lengthBToC + lengthCToA) / 2

    area = math.sqrt((side*(side-lengthAToB)*(side-lengthBToC)*(side-lengthCToA)))



    instructions.setText("Perimeter = " + str(perimeter) + " , " + "Area = " + str(area))

    instructions.draw(win)



    



    # Wait for another click to exit

    win.getMouse()

    win.close()



def colorShape():

    '''Create code to allow a user to color a shape by entering rgb amounts'''



    #create window

    winWidth = 400

    winHeight = 400

    win = GraphWin("Color Shape", winWidth, winHeight)

    win.setBackground("white")



    #create text instructions

    msg = "Enter color values between 0 - 255\nClick window to color shape"

    inst = Text(Point(winWidth/2, winHeight-20), msg)

    inst.draw(win)



    #create circle in window's center

    shape = Circle(Point(winWidth/2, winHeight/2 - 30), 50)

    shape.draw(win)



    #redTexPt is 50 pixels to the left and forty pixels down from center

    redTextPt = Point(winWidth/2 - 50, winHeight/2 + 40)

    redText = Text(redTextPt, "Red: ")

    redText.setTextColor("red")

    redBox=Entry(Point((winWidth/2), (winHeight/2 +40)),5)

    redBox.draw(win)

    



    #greenTextPt is 30 pixels down from red

    greenTextPt = redTextPt.clone()

    greenTextPt.move(0,30)

    greenText = Text(greenTextPt, "Green: ")

    greenText.setTextColor("green")

    greenBox=redBox.clone()

    greenBox.move(0,30)

    greenBox.draw(win)

    

    



    #blueTextPt is 60 pixels down from red

    blueTextPt = redTextPt.clone()

    blueTextPt.move(0,60)

    blueText = Text(blueTextPt, "Blue: ")

    blueText.setTextColor("blue")

    blueBox= redBox.clone()

    blueBox.move(0,60)

    blueBox.draw(win)

   

    



    #display rgb text

    redText.draw(win)

    greenText.draw(win)

    blueText.draw(win)

    for i in range (5):

        win.getMouse()

        red=redBox.getText()

        redInt=eval(red)

        green=greenBox.getText()

        greenInt=eval(green)

        blue=blueBox.getText()

        blueInt=eval(blue)

        color=color_rgb(redInt,greenInt,blueInt)

        shape.setFill(color)



    

    inst.setText("Click to close window")

    win.getMouse()

    win.close()



def anotherSeries():

    numTerms = eval(input("Enter number of terms in sequence: "))

    total = 0 

    for i in range (numTerms):

        modVal = i%3

        total = total + (modVal+1)*2

    print("Total: " , total)



def anotherSeriesPartner():

    numTerms=eval(input("Enter number of terms in sequence: "))

    denom=1.5

    total=1

    num=-1

    for i in range(numTerms):

        num=num+2

        denom=denom*2

        total=total*(num/denom)

    print("Total = ", total)



    

def main():

    cupConverter()

    target()

    triangle()

    colorShape()















