예제 #1
0
        public static void Main(string[] args)
        {
            NetworkHelper nh      = new NetworkHelper(UDP_HOST, UDP_PORT);
            PixelsHelper  ph      = new PixelsHelper();
            Palette       palette = new Palette();

            Color[] pixels = new Color[FRAME_SIZE];

            // Get the name of the gif file from the command line
            Image          gifImage   = Image.FromFile(path);
            FrameDimension dimension  = new FrameDimension(gifImage.FrameDimensionsList[0]);
            int            frameCount = gifImage.GetFrameCount(dimension);

            // Check that it's at least 24px wide and 91px tall
            // (same resolution as the grid)
            if (!(gifImage.Width >= 24 && gifImage.Height >= 91))
            {
                Console.WriteLine("Image has to be at least 24px wide by 91px high.");
                System.Environment.Exit(-1);
            }

            //For each frame in the gif
            for (int frameIdx = 0; frameIdx < frameCount; frameIdx++)
            {
                gifImage.SelectActiveFrame(dimension, frameIdx);
                Bitmap frame = (Bitmap)gifImage.Clone();
                Bitmap tmp;

                //get every width/24 column
                for (int x = 0; x < gifImage.Width; x += (int)(gifImage.Width / 24))
                {
                    //get every width/94 row of that column
                    // TODO get rid of the magic resolution numbers
                    for (int y = 0; y < gifImage.Height; y += (int)(gifImage.Height / 91))
                    {
                        tmp.SetPixel(x, y, frame.GetPixel(x, y));
                    }
                }

                pixelFrames.Add(tmp);
            }
            //While true
            while (true)
            {
                foreach (Bitmap data in pixelFrames)
                {
                    for (int x = 0; x < data.Width; x++)
                    {
                        for (int y = 0; y < data.Height; y++)
                        {
                            ph.SetOnePixel(data.GetPixel(x, y), ph.getPixelIdx(x, y), pixels);
                            nh.SendFrame(pixels);
                            Thread.Sleep(delay);
                        }
                    }
                }
            }
        }
예제 #2
0
        public const int delay = 1000 / 24; //delay in ms

        public static void Main(string[] args)
        {
            Console.WriteLine("Setting up pixel helper and network helper");
            NetworkHelper nh      = new NetworkHelper(UDP_HOST, UDP_PORT);
            PixelsHelper  ph      = new PixelsHelper();
            Palette       palette = new Palette();

            Color[] test_pattern = { Color.Aquamarine, Color.Chartreuse, Color.Chocolate, Color.HotPink };
            Color[] pixels       = new Color[FRAME_SIZE];
            Color[] adbasic      = palette.adbasic;

            try
            {
                int iter = 0;
                int mod  = 4;
                while (true)
                {
                    //ph.SetOnePixel(adbasic[iter%adbasic.Length], iter % 91, iter % 11, false, ref pixels);
                    //ph.FillFromCenter(adbasic, 24, 91, iter, ref pixels);

                    /*for(int i =0;i<pixels.Length;i++)
                     * {
                     *  if ((i % 4) == 0)
                     *      ph.SetOnePixel(adbasic[i%adbasic.Length], i, ref pixels);
                     * }*/

                    for (int x = 0; x < 91; x++)
                    {
                        for (int y = 0; y < 24; y++)
                        {
                            ph.SetOnePixel(adbasic[(y + iter) % adbasic.Length], x, y, false, ref pixels);
                        }
                    }
                    nh.SendFrame(pixels);
                    Thread.Sleep(delay);

                    /** undulating palette
                     * ph.FillFromSequence(adbasic, iter % adbasic.Length, ref pixels);
                     *
                     * nh.SendFrame(pixels);
                     * Thread.Sleep(delay);
                     */

                    /** Pixels on mod 'mod'
                     * ph.SetAllPixels(Color.Black, ref pixels);
                     * for(int x = 0; x < 91; x++)
                     * {
                     *  for(int y = 0; y < 24; y++)
                     *  {
                     *      if((iter+ph.GetPixelIdx(x,y)) % mod ==0)
                     *          ph.SetOnePixel(adbasic[iter % adbasic.Length], x, y, false, ref pixels);
                     *  }
                     * }
                     *
                     * nh.SendFrame(pixels);
                     * Thread.Sleep(delay);
                     *
                     * if(iter%24==0)
                     * {
                     *  mod++;
                     *  if(mod == 10)
                     *      mod = 4;
                     * }
                     */

                    iter++;
                    iter %= pixels.Length;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error with passing data to host: {e.Message}");
            }
            finally
            {
                nh.Close();
            }
        }