Beispiel #1
0
        public void Pull(ControlDevice controlDevice)
        {
            foreach (var ledUnit in leds)
            {
                if (ledUnit.Color == null)
                {
                    ledUnit.Color = new LEDColor(255, 0, 0);
                }

                ledUnit.Color = ledUnit.Color.LerpTo(new LEDColor(255, 0, 0), 0.01f);
            }

            foreach (Particle particle in Particles.ToList())
            {
                int top  = particle.Y - particle.Distance;
                int left = particle.X - particle.Distance;

                int bottom = particle.Y + particle.Distance;
                int right  = particle.X + particle.Distance;

                for (int x = left; x < right; x++)
                {
                    for (int y = top; y < bottom; y++)
                    {
                        if (x == left || x + 1 == right || y == top || y + 1 == bottom)
                        {
                            myControlDevice.SetGridLED(x, y, new LEDColor((int)((float)particle.R * particle.Strength), (int)((float)particle.G * particle.Strength), (int)((float)particle.B * particle.Strength)));
                        }
                    }
                }

                particle.Distance++;
                particle.Strength = particle.Strength * 0.95f;
            }

            List <Particle> deadParticles = Particles.ToList().Where(x => x.Strength < 0.05f).ToList();

            foreach (var deadParticle in deadParticles)
            {
                Particles.Remove(deadParticle);
            }
        }