예제 #1
0
 public Rainbow2DEffect(
     NeoPixelSetup neoPixelSetup,
     NeoStripXYCoordinates coordinates)
 {
     this.neoPixelSetup = neoPixelSetup;
     this.coordinates   = coordinates;
 }
예제 #2
0
 public EffectFactory(
     NeoPixelSetup neoPixelSetup,
     NeoStripXYCoordinates coordinates)
 {
     this.neoPixelSetup = neoPixelSetup;
     this.coordinates   = coordinates;
 }
 private Vector2 CalculatePosition(NeoPixelSetup neoPixelSetup, NeoPixelStrip strip, int pixelNumber)
 {
     if (strip.StripPosition == StripPosition.Bottom)
     {
         if (strip.RowIndex % 2 == 0)
         {
             return(CalculateBottomLeftPosition(neoPixelSetup, strip, pixelNumber));
         }
         else
         {
             return(CalculateBottomRightPosition(neoPixelSetup, strip, pixelNumber));
         }
     }
     else
     {
         if (strip.RowIndex % 2 == 0)
         {
             return(CalculateTopLeftPosition(neoPixelSetup, strip, pixelNumber));
         }
         else
         {
             return(CalculateTopRightPosition(neoPixelSetup, strip, pixelNumber));
         }
     }
 }
        private byte[] GetBytes(NeoPixelSetup neoPixelSetup)
        {
            byte[] bytes = new byte[1 + 1 + 2 + CalculateNumberOfPixels(neoPixelSetup) * 3];
            bytes[0] = 0;
            bytes[1] = CommandType.Set8BitPixelColours;

            ushort length = (ushort)(bytes.Length - 4);

            bytes[2] = (byte)(length >> 8);
            bytes[3] = (byte)(length & 0x00FF);

            //bytes[2] = ; - Do not set
            //bytes[3] = ; - Do not set
            int stripOffset = 0;

            foreach (var driver in neoPixelSetup.Drivers)
            {
                foreach (var strip in driver.Strips)
                {
                    for (int i = 0; i < strip.Pixels.Length; i++)
                    {
                        bytes[4 + stripOffset + i * 3 + 0] = strip.Pixels[i].R;
                        bytes[4 + stripOffset + i * 3 + 1] = strip.Pixels[i].G;
                        bytes[4 + stripOffset + i * 3 + 2] = strip.Pixels[i].B;
                    }
                    stripOffset += strip.Pixels.Length * 3;
                }
            }
            return(bytes);
        }
        private Vector2 CalculateTopRightPosition(NeoPixelSetup neoPixelSetup, NeoPixelStrip strip, int pixelNumber)
        {
            float  distanceBetweenPixels = neoPixelSetup.StripLength / strip.Pixels.Length;
            double triangleSide          = CalculateIsoscelesRightTriangleSide(distanceBetweenPixels);
            float  y = (float)(pixelNumber * triangleSide + strip.Pixels.Length * triangleSide);
            float  x = (float)(pixelNumber * triangleSide + strip.RowIndex * neoPixelSetup.DistanceBetweenStrips);

            return(new Vector2(x, y));
        }
예제 #6
0
 public CurveEffect(
     NeoPixelSetup neoPixelSetup,
     IColorProvider colorProvider,
     IInterpolation interpolator)
 {
     this.neoPixelSetup = neoPixelSetup;
     this.ColorProvider = colorProvider;
     this.Interpolator  = interpolator;
 }
예제 #7
0
 public PulseEffect(
     NeoPixelSetup neoPixelSetup,
     int skipPixels,
     int numberOfPixels,
     IColorProvider colorProvider,
     float speed)
 {
     this.neoPixelSetup     = neoPixelSetup;
     this.AreaStartPosition = skipPixels;
     this.ColorProvider     = colorProvider;
     this.AreaLength        = numberOfPixels;
     this.Speed             = speed;
 }
        private int CalculateNumberOfPixels(NeoPixelSetup neoPixelSetup)
        {
            int numberOfPixel = 0;

            foreach (var driver in neoPixelSetup.Drivers)
            {
                foreach (var strip in driver.Strips)
                {
                    numberOfPixel += strip.Pixels.Length;
                }
            }
            return(numberOfPixel);
        }
 private void ResetColor(NeoPixelSetup neoPixelSetup)
 {
     foreach (var driver in neoPixelSetup.Drivers)
     {
         foreach (var strip in driver.Strips)
         {
             for (int i = 0; i < strip.Pixels.Length; i++)
             {
                 strip.Pixels[i] = Color.Black;
             }
         }
     }
 }
 public NeoStripXYCoordinates(NeoPixelSetup neoPixelSetup)
 {
     precalculatedPixelPositions = new Dictionary <NeoPixelStrip, Vector2[]>();
     foreach (var driver in neoPixelSetup.Drivers)
     {
         foreach (var strip in driver.Strips)
         {
             Vector2[] pixelPositions = new Vector2[strip.Pixels.Length];
             for (int i = 0; i < strip.Pixels.Length; i++)
             {
                 pixelPositions[i] = CalculatePosition(neoPixelSetup, strip, i + 1);
             }
             precalculatedPixelPositions.Add(strip, pixelPositions);
         }
     }
 }
 private bool IsBlack(NeoPixelSetup neoPixelSetup)
 {
     foreach (var driver in neoPixelSetup.Drivers)
     {
         foreach (var strip in driver.Strips)
         {
             foreach (var pixel in strip.Pixels)
             {
                 if (pixel != Color.Black)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
        public void Send(NeoPixelSetup neoPixelSetup)
        {
            var bytes = GetBytes(neoPixelSetup);

            opcStream.Write(bytes, 0, bytes.Length);
        }
 public ScrollImageEffect(NeoPixelSetup neoPixelSetup, Bitmap image)
 {
     this.neoPixelSetup = neoPixelSetup;
     this.image         = image;
 }
예제 #14
0
 public ColorWheelEffect(NeoPixelSetup neoPixelSetup)
 {
     this.neoPixelSetup = neoPixelSetup;
 }
        public PixelController(EffectController effectController)
        {
            neoPixelSender        = new NeoPixelSender("localhost", 80);
            this.effectController = effectController;

            neoPixelSetup = NeoPixelFactory.CreateNeoPixelSetup(Devices, 8, 45);
            coordinates   = new NeoStripXYCoordinates(neoPixelSetup);
            effectFactory = new EffectFactory(neoPixelSetup, coordinates);

            effectController.AddEffect(effectFactory.CreateDefaultCurveEffect(
                                           name: "Rainbow",
                                           isEnabled: false,
                                           colorProvider: new RainbowColorProvider(0.2f),
                                           areaStartPosition: 0,
                                           areaLength: 45,
                                           effectLength: 10,
                                           speed: 5
                                           ));

            effectController.AddEffect(effectFactory.CreateDefaultCurveEffect(
                                           name: "Small slow rainbow",
                                           isEnabled: false,
                                           colorProvider: new RainbowColorProvider(0.2f),
                                           areaStartPosition: 30,
                                           areaLength: 15,
                                           effectLength: 5,
                                           speed: 1
                                           ));


            effectController.AddEffect(effectFactory.CreateDefaultCurveEffect(
                                           name: "Green",
                                           isEnabled: false,
                                           colorProvider: new StaticColorProvider(Color.Green),
                                           areaStartPosition: 0,
                                           areaLength: 45,
                                           effectLength: 13,
                                           speed: 3
                                           ));


            effectController.AddEffect(effectFactory.CreateDefaultCurveEffect(
                                           name: "Red",
                                           isEnabled: false,
                                           colorProvider: new StaticColorProvider(Color.Red),
                                           areaStartPosition: 0,
                                           areaLength: 45,
                                           effectLength: 10,
                                           speed: 7
                                           ));

            effectController.AddEffect(effectFactory.CreateDefaultCurveEffect(
                                           name: "Blue",
                                           isEnabled: false,
                                           colorProvider: new StaticColorProvider(Color.Blue),
                                           areaStartPosition: 0,
                                           areaLength: 45,
                                           effectLength: 7,
                                           speed: 5
                                           ));

            effectController.AddEffect(new FullColorEffect(neoPixelSetup, new RainbowColorProvider(0.2f))
            {
                Name      = "Full white",
                IsEnabled = false
            });

            //effectController.AddEffect(effectFactory.CreateScrollEffectFromTestImage(
            //    name: "Test image",
            //    isEnabled: false,
            //    speed: 10));

            effectController.AddEffect(effectFactory.CreateScrollEffectFromFile(
                                           name: "Color Wheel From Image",
                                           isEnabled: false,
                                           horizontalDirection: false,
                                           file: resourceLoader.CreateFullFilePath("colorwheel_line.png"),
                                           speed: 500));

            effectController.AddEffect(effectFactory.CreateColorWheelEffect(
                                           name: "Color Wheel",
                                           isEnabled: false,
                                           speed: 100));

            effectController.AddEffect(effectFactory.CreateRainbow2DEffect(
                                           name: "2D Rainbow",
                                           isEnabled: true,
                                           zoom: 3f,
                                           speed: 100f));
        }
 public FullColorEffect(NeoPixelSetup neoPixelSetup, IColorProvider colorProvider)
 {
     this.neoPixelSetup = neoPixelSetup;
     this.ColorProvider = colorProvider;
 }