コード例 #1
0
        public int GetGradientColor(
            int index,
            double pixelPos,
            double focusPos,
            bool wrap
            )
        {
            if (this.config.beatBroadcaster.CurrentlyFlashedOff)
            {
                return(0x000000);
            }
            int absoluteIndex = LEDColor.GetAbsoluteColorIndex(
                index,
                this.config.colorPaletteIndex
                );

            if (this.config.colorPalette.colors[absoluteIndex] == null)
            {
                return(0x000000);
            }
            if (!this.config.colorPalette.colors[absoluteIndex].IsGradient)
            {
                return(this.GetSingleColor(absoluteIndex));
            }
            return(LEDColor.ScaleColor(
                       this.config.colorPalette.GetGradientColor(
                           absoluteIndex,
                           pixelPos,
                           focusPos,
                           wrap
                           ),
                       this.config.stageBrightness
                       ));
        }
コード例 #2
0
        public override void Animate(LEDDomeOutput dome)
        {
            double intensity          = this.AnimationIntensity;
            double scaleColor         = Math.Min(intensity * 2 * this.velocity, 1.0);
            int    totalParts         = this.shape.layout.NumSegments;
            int    animationSplitInto = 2 * ((totalParts - 1) / 2 + 1);

            for (int part = 0; part < totalParts; part += 2)
            {
                double startRange = (double)part / animationSplitInto;
                double endRange   = (double)(part + 2) / animationSplitInto;
                double scaled     = (intensity - startRange) /
                                    (endRange - startRange);
                scaled     = Math.Max(Math.Min(scaled, 1.0), 0.0);
                startRange = Math.Min(startRange / intensity, 1.0);
                endRange   = Math.Min(endRange / intensity, 1.0);

                var spokeSegment = this.shape.layout.GetSegment(part);
                foreach (var strut in spokeSegment.GetStruts())
                {
                    for (int i = 0; i < strut.Length; i++)
                    {
                        double gradientPos =
                            strut.GetGradientPos(scaled, startRange, endRange, i);
                        int color1 = gradientPos != -1.0
              ? LEDColor.ScaleColor(
                            dome.GetGradientColor(this.pad, gradientPos, 0.0, false),
                            scaleColor
                            )
              : 0x000000;
                        dome.SetPixel(strut.Index, i, color1);
                    }
                }

                if (part + 1 == totalParts)
                {
                    break;
                }

                var circleSegment = this.shape.layout.GetSegment(part + 1);
                var color2        = scaled == 1.0
          ? LEDColor.ScaleColor(dome.GetSingleColor(this.pad), scaleColor)
          : 0x000000;
                foreach (var strut in circleSegment.GetStruts())
                {
                    for (int i = 0; i < strut.Length; i++)
                    {
                        dome.SetPixel(strut.Index, i, color2);
                    }
                }
            }
        }
コード例 #3
0
        public void Visualize()
        {
            if (this.stopwatch.ElapsedMilliseconds <= 1000)
            {
                return;
            }
            this.stopwatch.Restart();
            int triangles = this.config.stageSideLengths.Length / 3;

            for (int i = 0; i < triangles; i++)
            {
                int tracerIndex = LEDStageTracerVisualizer.TracerLEDIndex(
                    this.config,
                    i
                    );
                int triangleCounter    = 0;
                int maxTriangleCounter = this.config.stageSideLengths[i * 3] +
                                         this.config.stageSideLengths[i * 3 + 1] +
                                         this.config.stageSideLengths[i * 3 + 2];
                for (int j = 0; j < 3; j++)
                {
                    for (
                        int k = 0;
                        k < this.config.stageSideLengths[i * 3 + j];
                        k++, triangleCounter++
                        )
                    {
                        bool secondPart = this.sideParts[i * 3 + j] ^
                                          (this.config.beatBroadcaster.ProgressThroughBeat(0.25) > 0.5);
                        int color = this.stage.GetGradientColor(
                            secondPart ? 1 : 0,
                            (double)triangleCounter / maxTriangleCounter,
                            (double)tracerIndex / maxTriangleCounter,
                            true
                            );
                        int dimmedColor = LEDColor.ScaleColor(
                            color,
                            this.audio.LevelForChannel(secondPart ? 2 : 1)
                            );
                        for (int l = 0; l < 3; l++)
                        {
                            this.stage.SetPixel(i * 3 + j, k, l, dimmedColor);
                        }
                    }
                }
            }
            this.stage.Flush();
        }
コード例 #4
0
        public int GetSingleColor(int index)
        {
            if (this.config.beatBroadcaster.CurrentlyFlashedOff)
            {
                return(0x000000);
            }
            int absoluteIndex = LEDColor.GetAbsoluteColorIndex(
                index,
                this.config.colorPaletteIndex
                );

            return(LEDColor.ScaleColor(
                       this.config.colorPalette.GetSingleColor(absoluteIndex),
                       this.config.stageBrightness
                       ));
        }
コード例 #5
0
 public int Color(LEDDomeOutput dome, Configuration config, double loc_y, double loc_ang)
 {
     if (conf.coloring == Coloring.Fade)
     {
         return(LEDColor.ScaleColor(dome.GetSingleColor(this.idx), loc_ang));
     }
     else if (conf.coloring == Coloring.FadeExp)
     {
         var s = 4 * loc_ang - 4;
         return(LEDColor.ScaleColor(
                    dome.GetSingleColor(this.idx),
                    1.0 / (1 + Math.Pow(Math.E, -s))
                    ));
     }
     else if (conf.coloring == Coloring.Multi)
     {
         var end_index = config.colorPalette.colors.Length - 1;
         return(dome.GetGradientBetweenColors(end_index - 4, end_index, loc_ang, 0.0, false));
     }
     return(dome.GetSingleColor(this.idx));
 }
コード例 #6
0
        public int GetGradientBetweenColors(
            int minIndex,
            int maxIndex,
            double pixelPos,
            double focusPos,
            bool wrap
            )
        {
            // Return a color evenly scaled between min index and max index, based on the pixel position.
            if (pixelPos < 0 || pixelPos > 1)
            {
                throw new ArgumentException("Pixel Position out of range: " + pixelPos.ToString());
            }
            if (this.config.beatBroadcaster.CurrentlyFlashedOff)
            {
                return(0x000000);
            }
            var num_colors  = maxIndex - minIndex;
            int minColorIdx = (int)(pixelPos * num_colors);
            int maxColorIdx = (int)(pixelPos * num_colors + 1);
            // Rescale the position, so it's between the colors
            // (pixelPos - min_color_idx/num_colors)*num_colors
            double scaledPixelPos = (pixelPos - 1.0 * minColorIdx / num_colors) * num_colors;

            if (scaledPixelPos < 0 || scaledPixelPos > 1)
            {
                throw new ArgumentException("Pixel Position out of range: " + pixelPos.ToString());
            }
            int absoluteIndexMin = LEDColor.GetAbsoluteColorIndex(
                minColorIdx, this.config.colorPaletteIndex
                );
            int absoluteIndexMax = LEDColor.GetAbsoluteColorIndex(
                maxColorIdx, this.config.colorPaletteIndex
                );

            if (
                this.config.colorPalette.colors == null ||
                this.config.colorPalette.colors.Length <= absoluteIndexMin ||
                this.config.colorPalette.colors[absoluteIndexMin] == null
                )
            {
                return(0x000000);
            }
            if (
                this.config.colorPalette.colors == null ||
                this.config.colorPalette.colors.Length <= absoluteIndexMax ||
                this.config.colorPalette.colors[absoluteIndexMax] == null
                )
            {
                return(0x000000);
            }
            if (!this.config.colorPalette.colors[absoluteIndexMin].IsGradient)
            {
                return(this.GetSingleColor(absoluteIndexMin));
            }
            LEDColor color = new LEDColor(
                this.GetSingleColor(minColorIdx),
                this.GetSingleColor(maxColorIdx));

            return(LEDColor.ScaleColor(
                       color.GradientColor(scaledPixelPos, focusPos, wrap),
                       this.config.domeMaxBrightness * this.config.domeBrightness
                       ));
        }