def bisectoare(p1, p2, p3):
    d1, d2 = abs(p2 - p3), abs(p1 - p3)
    return (p1 * d1 + p2 * d2) / (d1 + d2)

def triunghi_bisectoare():
    C.setXminXmaxYminYmax(-10, 10, -10, 10)


    A = complex(-9, -4)
    B = complex(6, -4)
    D = complex(0, 6)




    I = (A + B + D) / 3

    b1 = bisectoare(A, B, D)
    b2 = bisectoare(B, D, A)
    b3 = bisectoare(D, A, B)




    for z in C.screenAffixes():
        x, y = z.real, z.imag
        cond1 = (y - A.imag) * (I.real - A.real) - (x - A.real) * (I.imag - A.imag) > 0
        cond2 = (y - B.imag) * (I.real - B.real) - (x - B.real) * (I.imag - B.imag) > 0
        cond3 = (y - D.imag) * (I.real - D.real) - (x - D.real) * (I.imag - D.imag) > 0

        if cond1 and cond2 and cond3:
            col = Color.Yellow
        elif cond1 and cond2:
            col = Color.Cyan
        elif cond2 and cond3:
            col = Color.Magenta
        elif cond1 and cond3:
            col = Color.Orange
        elif cond1:
            col = Color.Green
        elif cond2:
            col = Color.Blue
        else:
            col = Color.Red

        C.setPixel(z, col)

    C.drawLine(A, B, Color.Black)
    C.drawLine(B, D, Color.Black)
    C.drawLine(D, A, Color.Black)
    C.refreshScreen()
