Exemple #1
0
    def onSpeech():
        for process in Process.GetProcesses():
            if process.ProcessName.Equals("BouyomiChan"):
                tcpClient = tryConnect("127.0.0.1", 50001)

                if tcpClient is not None:
                    ns = None
                    bs = None
                    bw = None
                    bytes = Encoding.UTF8.GetBytes(text)

                    try:
                        ns = tcpClient.GetStream()
                        bs = BufferedStream(ns)
                        bw = BinaryWriter(bs)
                        bw.Write(Convert.ToInt16(0x0001))
                        bw.Write(Convert.ToInt16(-1))
                        bw.Write(Convert.ToInt16(-1))
                        bw.Write(Convert.ToInt16(-1))
                        bw.Write(Convert.ToInt16(1))
                        bw.Write(Convert.ToByte(0))
                        bw.Write(Convert.ToInt32(bytes.Length))
                        bw.Write(bytes)

                    finally:
                        if bs is not None:
                            bs.Close()

                        if bw is not None:
                            bw.Close()

                        if ns is not None:
                            ns.Close()

                        tcpClient.Close()

                break
Exemple #2
0
def colorFromAhsb(a, h, s, b):
	if 0 > a or 255 < a:
		return Colors.Transparent

	if 0 > h or 360 < h:
		return Colors.Transparent

	if 0 > s or 1 < s:
		return Colors.Transparent

	if 0 > b or 1 < b:
		return Colors.Transparent;

	if 0 == s:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(b * Byte.MaxValue), Convert.ToByte(b * Byte.MaxValue), Convert.ToByte(b * Byte.MaxValue))
		
	fMax = b - (b * s) + s if 0.5 < b else b + (b * s)
	fMin = b + (b * s) - s if 0.5 < b else b - (b * s)
	iSextant = Convert.ToInt32(Math.Floor(h / 60.0))

	if 300 <= h:
		h -= 360

	h = h / 60.0
	h -= 2 * Convert.ToSingle(Math.Floor(((iSextant + 1) % 6.0) / 2))

	fMid = h * (fMax - fMin) + fMin if 0 == iSextant % 2 else fMin - h * (fMax - fMin)
	iMax = Convert.ToInt32(fMax * Byte.MaxValue)
	iMid = Convert.ToInt32(fMid * Byte.MaxValue)
	iMin = Convert.ToInt32(fMin * Byte.MaxValue)
	
	if iSextant == 1:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMid), Convert.ToByte(iMax), Convert.ToByte(iMin))

	elif iSextant == 2:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMin), Convert.ToByte(iMax), Convert.ToByte(iMid))

	elif iSextant == 3:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMin), Convert.ToByte(iMid), Convert.ToByte(iMax))

	elif iSextant == 4:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMid), Convert.ToByte(iMin), Convert.ToByte(iMax))

	elif iSextant == 5:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMax), Convert.ToByte(iMin), Convert.ToByte(iMid))

	return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMax), Convert.ToByte(iMid), Convert.ToByte(iMin))