Esempio n. 1
0
        public static void TrigonometrieOneColorDemo(APA102LEDStrip ledStrip)
        {
            var wait = GetWaitTimeUnit(ledStrip);

            if (ledStrip.MaxLed <= 10)
            {
                wait *= 3;
            }

            var maxLed = ledStrip.MaxLed;
            var quit   = false;

            ledStrip.Brightness = 16;
            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Trigonometrie Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            var _4Sin_div_PI   = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(radianV) / (1 * Math.PI), colorMinValue: 64);
            var _4Sin3_div_3PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(3 * radianV) / (3 * Math.PI), colorMinValue: 64);
            var _4Sin5_div_5PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(5 * radianV) / (5 * Math.PI), colorMinValue: 32);
            var _4Sin7_div_7PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(7 * radianV) / (7 * Math.PI), colorMinValue: 32);

            // Green
            var greenColorVariation0 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin_div_PI, null);
            var greenColorVariation1 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin3_div_3PI, null);
            var greenColorVariation2 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin5_div_5PI, null);
            var greenColorVariation3 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin7_div_7PI, null);

            while (!quit)
            {
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation0, "4*Math.Sin(radianV)  /(1*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation1, "4*Math.Sin(3*radianV)/(3*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation2, "4*Math.Sin(5*radianV)/(5*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation3, "4*Math.Sin(7*radianV)/(7*Math.PI)"))
                {
                    break;
                }

                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }
            ledStrip.AllOff();
        }
Esempio n. 2
0
        public static void TrigonometrieMultiColorEvolutionDemo(APA102LEDStrip ledStrip)
        {
            APA102LEDStrip.CombineSPIDataAndClockOnSameCycle = true;

            var wait = GetWaitTimeUnit(ledStrip);

            if (ledStrip.MaxLed <= 10)
            {
                wait *= 3;
            }

            var maxLed = ledStrip.MaxLed;
            var quit   = false;

            ledStrip.Brightness = 16;
            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Trigonometrie Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            var trigoCircleMax  = Math.PI / 2;
            var amplitude       = 4;
            var amplitudeStep   = 0.1;
            var amplitudeFactor = amplitudeStep;

            amplitudeFactor = 1;

            var minPhaseOffSet  = 0.0;
            var maxPhaseOffSet  = Math.PI;
            var phaseOffSetStep = maxPhaseOffSet / 100;
            var phaseOffSet     = 0.0;

            var _4Sin3_div_3PI = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax,
                                                                       radianV => (amplitudeFactor * amplitude) * Math.Sin((3 * radianV)) / (3 * Math.PI),
                                                                       colorMinValue: 128, diplayData: true);

            var _4Sin5_div_5PI_Phase2 = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax,
                                                                              radianV => (amplitudeFactor * amplitude) * Math.Sin((5 * radianV)) / (5 * Math.PI),
                                                                              colorMinValue: 128, diplayData: true);

            var _4Sin7_div_7PI_Phase3 = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax,
                                                                              radianV => (amplitudeFactor * amplitude) * Math.Sin((7 * radianV)) / (7 * Math.PI),
                                                                              colorMinValue: 128, diplayData: true);

            List <System.Drawing.Color> colorVariation = null;
            int loopIndex = 0;

            while (!quit)
            {
                Console.WriteLine("amplitudeFactor:{0}, phaseOffSet:{1}", amplitudeFactor, phaseOffSet);

                switch (loopIndex % 3)
                {
                case 0: colorVariation = RGBHelper.GenerateListOfColor(maxLed, _4Sin3_div_3PI, _4Sin5_div_5PI_Phase2, null); break;

                case 1: colorVariation = RGBHelper.GenerateListOfColor(maxLed, _4Sin3_div_3PI, null, _4Sin5_div_5PI_Phase2); break;

                case 2: colorVariation = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin3_div_3PI, _4Sin5_div_5PI_Phase2); break;
                }
                //loopIndex += 1;

                if (!PlayTrigonometrieVariation(ledStrip, wait, colorVariation, "Experiment", 1))
                {
                    break;
                }

                //amplitudeFactor += amplitudeStep;
                if (amplitudeFactor > 3)
                {
                    amplitudeFactor = amplitudeStep;
                }

                //phaseOffSet = phaseOffSet + phaseOffSetStep;
                //if (phaseOffSet > maxPhaseOffSet)
                //    phaseOffSet = minPhaseOffSet;

                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }
            ledStrip.AllOff();
        }