コード例 #1
0
ファイル: Index.cs プロジェクト: MeenatchiKV/SPARS
    // Use this for initialization
    void Start()
    {
        HallButt = GameObject.Find("Hall").gameObject;
        HallButt.GetComponent <VirtualButtonBehaviour> ().RegisterEventHandler(this);
        HallButt.SetActive(true);
        BedButt = GameObject.Find("BedRoom");
        BedButt.GetComponent <VirtualButtonBehaviour> ().RegisterEventHandler(this);
        BedButt.SetActive(true);
        HLight = GameObject.Find("HallLight");
        HLight.GetComponent <VirtualButtonBehaviour> ().RegisterEventHandler(this);
        HLight.SetActive(false);
        HFan = GameObject.Find("HallFan");
        HFan.GetComponent <VirtualButtonBehaviour> ().RegisterEventHandler(this);
        HFan.SetActive(false);
        BLight = GameObject.Find("BedLight");
        BLight.GetComponent <VirtualButtonBehaviour> ().RegisterEventHandler(this);
        BLight.SetActive(false);
        BFan = GameObject.Find("BedFan");
        BFan.GetComponent <VirtualButtonBehaviour> ().RegisterEventHandler(this);
        BFan.SetActive(false);

        cli.Connect("172.16.16.187", 80);
    }
コード例 #2
0
ファイル: Effects.cs プロジェクト: carlhuth/GenXSource
        private void Highlight(Bitmap bitmap, double size, double sizevar, double radius, double radiusvar, double bright, int steps)
        {
            List <HLight> highlights = new List <HLight>();

            BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            unsafe
            {
                int  width  = bitmap.Width;
                int  height = bitmap.Height;
                int *pixels = (int *)data.Scan0;
                int  stride = data.Stride / 4;

                for (int y = 0; y < height; y += steps)
                {
                    for (int x = 0; x < width; x += steps)
                    {
                        double R = 0.0;
                        double G = 0.0;
                        double B = 0.0;

                        for (int j = -1; j < 2; j++)
                        {
                            for (int i = -1; i < 2; i++)
                            {
                                //System.Windows.Forms.Application.DoEvents();
                                int yj = y + j;
                                int xi = x + i;

                                if (xi >= width)
                                {
                                    xi = width - 1;
                                }
                                else if (xi < 0)
                                {
                                    xi = 0;
                                }

                                if (yj >= height)
                                {
                                    yj = height - 1;
                                }
                                else if (yj < 0)
                                {
                                    yj = 0;
                                }

                                Color col = Color.FromArgb(pixels[yj * stride + xi]);

                                if (j == 0 && i == 0)
                                {
                                    R -= 8 * col.R;
                                    G -= 8 * col.G;
                                    B -= 8 * col.B;
                                }
                                else
                                {
                                    R += col.R;
                                    G += col.G;
                                    B += col.B;
                                }
                            }
                        }

                        double L = 0.299 * R + 0.587 * G + 0.114 * B;

                        if (L >= 255)
                        {
                            HLight hl = new HLight();
                            hl.Location = new Point(x, y);

                            R /= 255.0;
                            G /= 255.0;
                            B /= 255.0;

                            R = (R + bright) - (R * bright);
                            G = (G + bright) - (G * bright);
                            B = (B + bright) - (B * bright);

                            R *= 255.0;
                            G *= 255.0;
                            B *= 255.0;

                            if (R > 255.0)
                            {
                                R = 255.0;
                            }
                            else if (R < 0.0)
                            {
                                R = 0.0;
                            }

                            if (G > 255.0)
                            {
                                G = 255.0;
                            }
                            else if (G < 0.0)
                            {
                                G = 0.0;
                            }

                            if (B > 255.0)
                            {
                                B = 255.0;
                            }
                            else if (B < 0.0)
                            {
                                B = 0.0;
                            }

                            hl.Color = Color.FromArgb((int)R, (int)G, (int)B);

                            highlights.Add(hl);
                        }
                    }
                }
            }

            bitmap.UnlockBits(data);

            Graphics g = Graphics.FromImage(bitmap);

            g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.InterpolationMode  = InterpolationMode.HighQualityBilinear;
            g.CompositingQuality = CompositingQuality.HighQuality;

            foreach (HLight highlight in highlights)
            {
                //System.Windows.Forms.Application.DoEvents();
                float s = (float)(size + rand.NextDouble() * sizevar);
                float r = (float)(radius + rand.NextDouble() * radiusvar);

                GraphicsPath gp = new GraphicsPath();
                gp.StartFigure();

                gp.AddLine(new PointF(-s, -s), new PointF(0, -r));

                gp.AddLine(gp.GetLastPoint(), new PointF(s, -s));
                gp.AddLine(gp.GetLastPoint(), new PointF(r, 0));

                gp.AddLine(gp.GetLastPoint(), new PointF(s, s));
                gp.AddLine(gp.GetLastPoint(), new PointF(0, r));

                gp.AddLine(gp.GetLastPoint(), new PointF(-s, s));
                gp.AddLine(gp.GetLastPoint(), new PointF(-r, 0));

                gp.CloseFigure();

                PathGradientBrush brush = new PathGradientBrush(gp);
                brush.CenterColor    = highlight.Color;
                brush.SurroundColors = new Color[] { Color.Transparent };

                g.ResetTransform();
                g.TranslateTransform(highlight.Location.X, highlight.Location.Y);
                g.RotateTransform((float)rand.NextDouble() * 90f);
                g.FillPath(brush, gp);
            }
        }
コード例 #3
0
ファイル: Index.cs プロジェクト: MeenatchiKV/SPARS
    public void OnButtonPressed(VirtualButtonAbstractBehaviour vb)
    {
        Debug.Log("Button Down!!");
        switch (vb.VirtualButtonName)
        {
        case "Hall":
            HallButt.SetActive(false);
            BedButt.SetActive(false);
            HLight.SetActive(true);
            HFan.SetActive(true);
            //Destroy (HallButt);
            //Destroy (BedButt);

            BLight.SetActive(false);
            BFan.SetActive(false);
            Debug.Log("Hall!!");

            break;

        case "BedRoom":

            HallButt.SetActive(false);
            BedButt.SetActive(false);
            BLight.SetActive(true);
            BFan.SetActive(true);
            //Destroy (HallButt);
            //Destroy (BedButt);
            HLight.SetActive(false);
            HFan.SetActive(false);


            Debug.Log("BedRoom!!");
            break;

        case "HallLight":
            HLight.SetActive(true);
            HFan.SetActive(true);
            BLight.SetActive(false);
            BFan.SetActive(false);
            if (HL == 0)
            {
                str = "$1";
                NetworkStream stm  = cli.GetStream();
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[]        bn   = asen.GetBytes(str);
                stm.Write(bn, 0, str.Length);
                Debug.Log("HallLightOn!!");
                HL = 1;
            }
            else
            {
                str = "$2";
                NetworkStream stm  = cli.GetStream();
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[]        bn   = asen.GetBytes(str);
                stm.Write(bn, 0, str.Length);
                Debug.Log("HallLightOff!!");
                HL = 0;
            }
            break;


        case "HallFan":
            HLight.SetActive(true);
            HFan.SetActive(true);
            BLight.SetActive(false);
            BFan.SetActive(false);
            if (HF == 0)
            {
                str = "$3";
                NetworkStream stm  = cli.GetStream();
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[]        bn   = asen.GetBytes(str);
                stm.Write(bn, 0, str.Length);
                Debug.Log("HallFanOn!!");
                HF = 1;
            }
            else
            {
                str = "$4";
                NetworkStream stm  = cli.GetStream();
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[]        bn   = asen.GetBytes(str);
                stm.Write(bn, 0, str.Length);
                Debug.Log("HallFanOff!!");
                HF = 0;
            }
            break;


        case "BedLight":
            BLight.SetActive(true);
            BFan.SetActive(true);
            HLight.SetActive(false);
            HFan.SetActive(false);
            if (BL == 0)
            {
                str = "$5";
                NetworkStream stm  = cli.GetStream();
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[]        bn   = asen.GetBytes(str);
                stm.Write(bn, 0, str.Length);
                Debug.Log("BedLightOn!!");
                BL = 1;
            }
            else
            {
                str = "$6";
                NetworkStream stm  = cli.GetStream();
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[]        bn   = asen.GetBytes(str);
                stm.Write(bn, 0, str.Length);
                Debug.Log("BedLightOff!!");
                BL = 0;
            }
            break;


        case "BedFan":
            BLight.SetActive(true);
            BFan.SetActive(true);
            HLight.SetActive(false);
            HFan.SetActive(false);
            if (BF == 0)
            {
                str = "$7";
                NetworkStream stm  = cli.GetStream();
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[]        bn   = asen.GetBytes(str);
                stm.Write(bn, 0, str.Length);
                Debug.Log("BedFanOn!!");
                BF = 1;
            }
            else
            {
                str = "$8";
                NetworkStream stm  = cli.GetStream();
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[]        bn   = asen.GetBytes(str);
                stm.Write(bn, 0, str.Length);
                Debug.Log("BedFanOff!!");
                BF = 0;
            }
            break;
        }
    }