示例#1
0
        public void Screenshot(Nanoleaf nanoleaf)
        {
            List <LCColor>   palette      = null;
            Bitmap           bitmap       = null;
            string           body         = lightController.Get(nanoleaf, "/panelLayout/layout")["body"];
            List <Panel>     panels       = Panel.GetPanels(body);
            int              paletteCount = panels.Count;
            Tuple <int, int> gcd          = ImageAnalysis.DivideScreen(paletteCount);

            palette = new List <LCColor>();
            bitmap  = ImageAnalysis.CaptureBitmap(0);

            if (bitmap == null)
            {
                palette.Add(new LCColor(Color.Black));
            }
            else
            {
                //palette = ImageAnalysis.ReduceColors(ImageAnalysis.GetAverageColors(bitmap, gcd.Item1, gcd.Item2), true, paletteCount);
                palette = ImageAnalysis.GetAverageColors(bitmap, gcd.Item1, gcd.Item2, borderReduction: 300);
            }

            lightController.CreateCustom(nanoleaf, PaletteController.ToJArray(palette));
        }
示例#2
0
        public void StreamingMode(Nanoleaf nanoleaf)
        {
            //UdpClient udp = new UdpClient();
            ////udp.EnableBroadcast = true;  //This was suggested in a now deleted answer
            //IPEndPoint groupEP = new IPEndPoint(ConvertIP("192.168.1.6"), 60221);
            //string str4 = "2 55 1 255 0 0 0 1 10 1 0 255 0 0 1 ";
            //byte[] sendBytes4 = Encoding.ASCII.GetBytes(str4);
            //udp.Send(sendBytes4, sendBytes4.Length, groupEP);
            //udp.Close();

            //get panel layout
            bool         first  = true;
            string       body   = lightController.Get(nanoleaf, "/panelLayout/layout")["body"];
            List <Panel> panels = Panel.GetPanels(body);

            List <LCColor> palette = null;
            Stopwatch      timer   = null;
            Bitmap         bitmap  = null;

            int paletteCount     = panels.Count;
            Tuple <int, int> gcd = ImageAnalysis.DivideScreen(paletteCount);

            while (true)
            {
                timer = new Stopwatch();
                timer.Start();

                palette = new List <LCColor>();
                bitmap  = ImageAnalysis.CaptureBitmap(0);

                if (bitmap == null)
                {
                    palette.Add(new LCColor(Color.Black));
                }
                else
                {
                    //palette = ImageAnalysis.ReduceColors(ImageAnalysis.GetAverageColors(bitmap, gcd.Item1, gcd.Item2), true, paletteCount);
                    palette = ImageAnalysis.GetAverageColors(bitmap, gcd.Item1, gcd.Item2, borderReduction: 300);
                }

                if (timer.ElapsedMilliseconds < 100)
                {
                    if (100 - timer.ElapsedMilliseconds > 0)
                    {
                        Thread.Sleep(100 - Convert.ToInt32(timer.ElapsedMilliseconds));
                    }
                }

                //TODO: change the position of some of the panels on shuffle, not all
                bool shuffle = true;
                if (shuffle && times.Count % 100 == 0)
                {
                    panels = Panel.Shuffle(panels);
                }

                lightController.CreateTemp(nanoleaf, panels, palette);

                timer.Stop();
                long ms = timer.ElapsedMilliseconds;

                if (!first)
                {
                    CalcAverage(ms);
                }
                first = false;
            }
        }