import turtle as t
import math


class circTrigo:

    def __init__(self):
        self.raio = 0
        self.grau = 0
        self.seno = 0
        self.cosseno = 0
        self.tangente = 0
        self.quadrante = 0
        self.tema = ''
        t.bgcolor("black")
        t.pencolor("white")
        
    def seta(self):
        # DESENHA UMA SETA
        t.left(90)
        t.forward(5)
        t.right(120)
        t.forward(10)
        t.right(120)
        t.forward(10)
        t.right(120)
        t.forward(5)
        t.right(90)

    def linha(self, pxls):
        # DESENHA UMA LINHA PONTILHADA
        pixels = int(pxls//1)
        if pixels % 2 == 0:
            pixels = pixels + 1
        for x in range(0, pixels//10):
            t.pendown()
            t.forward(5)
            t.penup()
            t.forward(5)
            t.pendown()
        t.forward(pixels%10)            
    
    def reset(self):
        # RETORNA PRA POSICAO INICIAL
        t.penup()
        t.home()
        t.pendown()
        t.speed(0)
        t.pensize(2)
        t.pencolor("white")

    def circulo(self, raio):
        # DESENHA O CIRCULO
        self.raio = raio
        t.right(90)
        t.penup()
        t.forward(self.raio)
        t.left(90)
        t.pendown()
        t.circle(self.raio)
        self.reset()

    def eixos(self):
        # EIXO X
        t.penup()
        t.backward(self.raio + 50)
        t.pendown()
        self.linha((self.raio*2)+100)
        self.seta()
        self.reset()
        # EIXO Y
        t.left(90)
        t.penup()
        t.backward(self.raio + 50)
        t.pendown()
        self.linha((self.raio*2)+100)
        self.seta()
        self.reset()

    def angulo(self, grau):
        # DESENHA O ANGULO
        self.grau = grau % 360
        t.left(self.grau)
        t.forward(self.raio)
        self.reset()
        # DEFINE O VALOR DO SENO, COSSENO E TANGENTE.
        self.seno = math.sin(math.radians(self.grau))
        self.cosseno = math.cos(math.radians(self.grau))
        self.tangente = math.tan(math.radians(self.grau))
        # DEFINE O QUADRANTE DO ANGULO
        vquad = self.grau
        if 0 < vquad < 90:
            self.quadrante = 1
        elif 90 < vquad < 180:
            self.quadrante = 2
        elif 180 < vquad < 270:
            self.quadrante = 3
        elif 270 < vquad < 360:
            self.quadrante = 4
        if vquad == 0 or vquad == 90 or vquad == 180 or vquad == 270 or vquad == 360:   # Quadrante 0 representa os angulos de resultados indefinidos
            self.quadrante = 0

    def sen(self):
        # DESENHA O SENO
        t.left(self.grau)
        t.forward(self.raio)
        t.pencolor("red")
        if self.quadrante == 1:
            t.left(180 - self.grau)
            self.linha(self.cosseno * self.raio)
            t.left(90)
            t.forward(self.seno * self.raio)
            print (self.seno)
        elif self.quadrante == 2:
            t.right(self.grau)
            self.linha((self.cosseno * self.raio) * -1)
            t.right(90)
            t.forward(self.seno * self.raio)
            print (self.seno)
        elif self.quadrante == 3:
            t.right(self.grau)
            self.linha(self.cosseno * self.raio * -1)
            t.left(90)
            t.forward(self.seno * self.raio * -1)
            print (self.seno)
        elif self.quadrante == 4:
            t.left(180 - self.grau)
            self.linha(self.cosseno * self.raio)
            t.left(90)
            t.forward(self.seno * self.raio)
            print (self.seno)
        else: 
            print("Erro: angulo invalido")
        self.reset()
    
    def csen(self):
        # DESENHA O COSSENO
        t.left(self.grau)
        t.forward(self.raio)
        t.pencolor("green")
        if self.quadrante == 1:
            t.right(self.grau + 90)
            self.linha(self.seno * self.raio)
            t.right(90)
            t.forward(self.cosseno * self.raio)
            print (self.cosseno)
        elif self.quadrante == 2:
            t.right(self.grau + 90)
            self.linha(self.seno * self.raio)
            t.right(90)
            t.forward(self.cosseno * self.raio)
            print (self.cosseno)
        elif self.quadrante == 3:
            t.right(self.grau - 90)
            self.linha(self.seno * self.raio * -1)
            t.right(90)
            t.forward(self.cosseno * self.raio * -1)
            print (self.cosseno)
        elif self.quadrante == 4:
            t.right(self.grau - 90)
            self.linha(self.seno * self.raio * -1)
            t.left(90)
            t.forward(self.cosseno * self.raio)
            print (self.cosseno)
        else: 
            print("Erro: angulo invalido")
        self.reset()
    
    def tan(self):
        # DESENHA A TANGENTE
        t.left(self.grau)
        t.penup()
        t.pencolor("blue")
        if self.quadrante == 1:
            t.forward(self.raio)
            t.pendown()
            self.linha(math.sqrt(((self.tangente*self.raio)**2) + (self.raio**2)) - self.raio)
            t.right(self.grau + 90)
            t.forward(self.tangente * self.raio)
            print (self.tangente)
        elif self.quadrante == 2:
            t.left(180)
            t.forward(self.raio)
            t.pendown()
            self.linha(math.sqrt(((self.tangente*self.raio)**2) + (self.raio**2)) - self.raio)
            t.left(90 - self.grau)
            t.forward(self.tangente * self.raio)
            print (self.tangente)
        elif self.quadrante == 3:
            t.left(180)
            t.forward(self.raio)
            t.pendown()
            self.linha(math.sqrt(((self.tangente*self.raio)**2) + (self.raio**2)) - self.raio)
            t.right(self.grau - 90)
            t.forward(self.tangente * self.raio)
            print (self.tangente)
        elif self.quadrante == 4:
            t.forward(self.raio)
            t.pendown()
            self.linha(math.sqrt(((self.tangente*self.raio)**2) + (self.raio**2)) - self.raio)
            t.right(90 + self.grau)
            t.forward(self.tangente * self.raio)
            print (self.tangente)
        else: 
            print("Erro: angulo invalido")
        self.reset()
    

[(15, 'turtle.bgcolor', 't.bgcolor', True, 'import turtle as t\n'), (16, 'turtle.pencolor', 't.pencolor', True, 'import turtle as t\n'), (20, 'turtle.left', 't.left', True, 'import turtle as t\n'), (21, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (22, 'turtle.right', 't.right', True, 'import turtle as t\n'), (23, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (24, 'turtle.right', 't.right', True, 'import turtle as t\n'), (25, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (26, 'turtle.right', 't.right', True, 'import turtle as t\n'), (27, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (28, 'turtle.right', 't.right', True, 'import turtle as t\n'), (41, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (45, 'turtle.penup', 't.penup', True, 'import turtle as t\n'), (46, 'turtle.home', 't.home', True, 'import turtle as t\n'), (47, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (48, 'turtle.speed', 't.speed', True, 'import turtle as t\n'), (49, 'turtle.pensize', 't.pensize', True, 'import turtle as t\n'), (50, 'turtle.pencolor', 't.pencolor', True, 'import turtle as t\n'), (55, 'turtle.right', 't.right', True, 'import turtle as t\n'), (56, 'turtle.penup', 't.penup', True, 'import turtle as t\n'), (57, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (58, 'turtle.left', 't.left', True, 'import turtle as t\n'), (59, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (60, 'turtle.circle', 't.circle', True, 'import turtle as t\n'), (65, 'turtle.penup', 't.penup', True, 'import turtle as t\n'), (66, 'turtle.backward', 't.backward', True, 'import turtle as t\n'), (67, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (72, 'turtle.left', 't.left', True, 'import turtle as t\n'), (73, 'turtle.penup', 't.penup', True, 'import turtle as t\n'), (74, 'turtle.backward', 't.backward', True, 'import turtle as t\n'), (75, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (83, 'turtle.left', 't.left', True, 'import turtle as t\n'), (84, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (105, 'turtle.left', 't.left', True, 'import turtle as t\n'), (106, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (107, 'turtle.pencolor', 't.pencolor', True, 'import turtle as t\n'), (138, 'turtle.left', 't.left', True, 'import turtle as t\n'), (139, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (140, 'turtle.pencolor', 't.pencolor', True, 'import turtle as t\n'), (171, 'turtle.left', 't.left', True, 'import turtle as t\n'), (172, 'turtle.penup', 't.penup', True, 'import turtle as t\n'), (173, 'turtle.pencolor', 't.pencolor', True, 'import turtle as t\n'), (36, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (37, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (38, 'turtle.penup', 't.penup', True, 'import turtle as t\n'), (39, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (40, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (87, 'math.radians', 'math.radians', False, 'import math\n'), (88, 'math.radians', 'math.radians', False, 'import math\n'), (89, 'math.radians', 'math.radians', False, 'import math\n'), (109, 'turtle.left', 't.left', True, 'import turtle as t\n'), (111, 'turtle.left', 't.left', True, 'import turtle as t\n'), (112, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (142, 'turtle.right', 't.right', True, 'import turtle as t\n'), (144, 'turtle.right', 't.right', True, 'import turtle as t\n'), (145, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (175, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (176, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (178, 'turtle.right', 't.right', True, 'import turtle as t\n'), (179, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (115, 'turtle.right', 't.right', True, 'import turtle as t\n'), (117, 'turtle.right', 't.right', True, 'import turtle as t\n'), (118, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (148, 'turtle.right', 't.right', True, 'import turtle as t\n'), (150, 'turtle.right', 't.right', True, 'import turtle as t\n'), (151, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (182, 'turtle.left', 't.left', True, 'import turtle as t\n'), (183, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (184, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (186, 'turtle.left', 't.left', True, 'import turtle as t\n'), (187, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (121, 'turtle.right', 't.right', True, 'import turtle as t\n'), (123, 'turtle.left', 't.left', True, 'import turtle as t\n'), (124, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (154, 'turtle.right', 't.right', True, 'import turtle as t\n'), (156, 'turtle.right', 't.right', True, 'import turtle as t\n'), (157, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (177, 'math.sqrt', 'math.sqrt', False, 'import math\n'), (190, 'turtle.left', 't.left', True, 'import turtle as t\n'), (191, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (192, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (194, 'turtle.right', 't.right', True, 'import turtle as t\n'), (195, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (127, 'turtle.left', 't.left', True, 'import turtle as t\n'), (129, 'turtle.left', 't.left', True, 'import turtle as t\n'), (130, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (160, 'turtle.right', 't.right', True, 'import turtle as t\n'), (162, 'turtle.left', 't.left', True, 'import turtle as t\n'), (163, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (185, 'math.sqrt', 'math.sqrt', False, 'import math\n'), (198, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (199, 'turtle.pendown', 't.pendown', True, 'import turtle as t\n'), (201, 'turtle.right', 't.right', True, 'import turtle as t\n'), (202, 'turtle.forward', 't.forward', True, 'import turtle as t\n'), (193, 'math.sqrt', 'math.sqrt', False, 'import math\n'), (200, 'math.sqrt', 'math.sqrt', False, 'import math\n')]