private void BuildShapes()
 {
     for (int i = 20; i < 71; i++)
     {
         StrutLayout[] layouts = StrutLayoutFactory.ConcentricFromStartingPoints(
             this.config,
             new HashSet <int>()
         {
             i
         },
             2
             );
         Shape shape = new Shape(this.dome, ShapeType.Polygon, layouts[0]);
         this.shapes[ShapeType.Polygon].Add(shape);
         foreach (int strutIndex in shape.struts)
         {
             if (!this.strutsToShapes.ContainsKey(strutIndex))
             {
                 this.strutsToShapes[strutIndex] = new List <Shape>();
             }
             this.strutsToShapes[strutIndex].Add(shape);
         }
     }
     // TODO do enums have order? can they be compared?
     // TODO build other kinds of shapes here
 }
Example #2
0
        public void Visualize()
        {
            //-----------------------------------------------------------------------
            // SETTING THE RACERS
            //-----------------------------------------------------------------------

            this.racer_spacing = this.config.domeRadialSize > 1 ? 1.0 : this.config.domeRadialSize;
            var curTicks = DateTime.Now.Ticks;

            if (this.lastTicks == -1)
            {
                this.lastTicks = curTicks;
            }
            else
            {
                double numSeconds = ((double)(curTicks - this.lastTicks)) / (1000 * 1000 * 10);
                foreach (Racer r in Racers)
                {
                    r.Move(numSeconds, audio, config);
                }
                this.lastTicks = curTicks;
            }

            //-----------------------------------------------------------------------
            // SETTING LEDS
            //-----------------------------------------------------------------------

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                Strut strut = Strut.FromIndex(this.config, i);
                var   leds  = LEDDomeOutput.GetNumLEDs(i);
                for (int j = 0; j < leds; j++)
                {
                    var pixel_p = StrutLayoutFactory.GetProjectedLEDPointParametric(i, j);
                    // Vertical height
                    var y   = 1.0 - pixel_p.Item4;
                    var rad = pixel_p.Item3;
                    Tuple <Racer, double, double, Racer> loc = this.GetRacer(y, rad);
                    if (loc == null)
                    {
                        // color = 0 is off.
                        this.dome.SetPixel(i, j, 0);
                    }
                    else
                    {
                        // Let the racer choose its color
                        var color = loc.Item4.Color(dome, config, loc.Item2, loc.Item3);
                        this.dome.SetPixel(i, j, color);
                    }
                }
            }

            // No messages will be sent to the Beaglebone until Flush is called. This
            // makes it imperative that you call Flush at the end of Visualize, or
            // whenever you want to update the LEDs. The LEDs themselves are stateful,
            // and will maintain whatever color you set them to until they lose power.
            this.dome.Flush();
        }
Example #3
0
        public void ParametricTest()
        {
            double progress = this.config.beatBroadcaster.ProgressThroughBeat(
                this.config.domeVolumeRotationSpeed
                );

            double level = this.audio.LevelForChannel(0);

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                Strut strut = Strut.FromIndex(this.config, i);
                var   leds  = LEDDomeOutput.GetNumLEDs(i);
                for (int j = 0; j < leds; j++)
                {
                    var    p = StrutLayoutFactory.GetProjectedLEDPointParametric(i, j);
                    double r = 0;
                    double g = 0;
                    double b = 0;

                    //radar effect
                    double a = (p.Item3 + Math.PI) / (Math.PI * 2);
                    r = progress - a;
                    if (r < 0)
                    {
                        r += 1;
                    }
                    if (r > 1)
                    {
                        r = 1;
                    }

                    //pulse effect
                    double dist = Math.Abs(progress - p.Item4);
                    r = 1 - dist;
                    if (r < 0.9)
                    {
                        r = 0;
                    }

                    //spiral effect
                    double m = p.Item4 - a;
                    if (m < 0)
                    {
                        m += 1;
                    }
                    double n = progress - m;
                    if (n < 0)
                    {
                        n += 1;
                    }
                    r = 1 - n;

                    this.dome.SetPixel(i, j, LEDColor.FromDoubles(r, g, b));
                }
            }
        }
        private static Tuple <int, int> GetPoint(int strutIndex, int point)
        {
            var p     = StrutLayoutFactory.GetProjectedPoint(strutIndex, point);
            int index = StrutLayoutFactory.lines[strutIndex, point];

            return(new Tuple <int, int>(
                       (int)(p.Item1 * 690) + 10,
                       (int)(p.Item2 * 690) + 10
                       ));
        }
 private void UpdateLayouts()
 {
     int[] points = new int[] { 22, 26, 30, 34, 38, 70 };
     for (int i = 0; i < 5; i++)
     {
         points[i] += this.centerOffset;
     }
     if (points[4] >= 40)
     {
         points[4] -= 20;
     }
     StrutLayout[] layouts = StrutLayoutFactory.ConcentricFromStartingPoints(
         this.config,
         new HashSet <int>(points),
         4
         );
     this.partLayout    = layouts[0];
     this.indexLayout   = layouts[1];
     this.sectionLayout = layouts[2];
 }
        void Render()
        {
            double progress = this.config.beatBroadcaster.ProgressThroughMeasure;

            currentAngle     += this.config.domeVolumeRotationSpeed * Wrap(progress - this.lastProgress, 0, 1);
            currentAngle      = Wrap(currentAngle, 0, 1);
            currentGradient  += this.config.domeGradientSpeed * Wrap(progress - this.lastProgress, 0, 1);
            currentGradient   = Wrap(currentGradient, 0, 1);
            this.lastProgress = progress;

            double level         = this.audio.LevelForChannel(0);
            double adjustedLevel = Map(level, 0, 1, 0.02, 1);

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                Strut strut = Strut.FromIndex(this.config, i);
                var   leds  = LEDDomeOutput.GetNumLEDs(i);
                for (int j = 0; j < leds; j++)
                {
                    var p = StrutLayoutFactory.GetProjectedLEDPointParametric(i, j);

                    // map angle to 0-1
                    var angle = MapWrap(p.Item3, -Math.PI, Math.PI, 0.0, 1.0);
                    var dist  = p.Item4;

                    double val         = 0;
                    double gradientVal = 0;

                    switch (this.config.domeRadialEffect)
                    {
                    case 0:
                        // radar mapping
                        val         = MapWrap(angle, currentAngle, 1 + currentAngle, 0, 1);
                        gradientVal = dist;
                        break;

                    case 1:
                        // pulse mapping
                        val         = MapWrap(dist, currentAngle, 1 + currentAngle, 0, 1);
                        gradientVal = Math.Abs(Map(angle, 0, 1, -1, 1));
                        break;

                    case 2:
                        // spiral mapping
                        val         = MapWrap(angle + dist / this.config.domeRadialFrequency, currentAngle, 1 + currentAngle, 0, 1);
                        gradientVal = dist;
                        break;
                    }

                    // scale val according to radial frequency
                    val = Wrap(val * this.config.domeRadialFrequency, 0, 1);
                    // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                    var centeredVal = Math.Abs(Map(val, 0, 1, -1, 1));

                    // size limit is scaled according the size slider and the current level
                    var  sizeLimit = this.config.domeRadialSize * adjustedLevel;
                    bool on        = centeredVal <= sizeLimit;

                    var color = on ? this.dome.GetGradientColor(0, gradientVal, currentGradient, true) : 0;

                    this.dome.SetPixel(i, j, color);
                }
            }
        }
Example #7
0
        void Render()
        {
            double level = this.audio.LevelForChannel(0);
            // Sqrt makes values larger and gives more resolution for lower values
            double adjustedLevel = Clamp(Math.Sqrt(level), 0.1, 1);

            double progress = this.config.beatBroadcaster.ProgressThroughMeasure;

            // rotation is scaled by 1/4 - otherwise it is way too fast and will make people vomit
            currentAngle     += this.config.domeVolumeRotationSpeed * Wrap(progress - this.lastProgress, 0, 1) * 0.25;
            currentAngle      = Wrap(currentAngle, 0, 1);
            currentGradient  += this.config.domeGradientSpeed * Wrap(progress - this.lastProgress, 0, 1);
            currentGradient   = Wrap(currentGradient, 0, 1);
            this.lastProgress = progress;

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                var leds = LEDDomeOutput.GetNumLEDs(i);
                for (int j = 0; j < leds; j++)
                {
                    var p = StrutLayoutFactory.GetProjectedLEDPointParametric(i, j);

                    // map angle to 0-1
                    var angle = MapWrap(p.Item3, -Math.PI, Math.PI, 0.0, 1.0);
                    var dist  = p.Item4;

                    double val         = 0;
                    double gradientVal = 0;

                    switch (this.config.domeRadialEffect)
                    {
                    case 0:
                        // radar mapping
                        val = MapWrap(angle, currentAngle, 1 + currentAngle, 0, 1);
                        // scale val according to radial frequency
                        val = Wrap(val * this.config.domeRadialFrequency, 0, 1);
                        // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                        val = Math.Abs(Map(val, 0, 1, -1, 1));

                        gradientVal = dist;
                        break;

                    case 1:
                        // pulse mapping
                        val = MapWrap(dist, currentAngle, 1 + currentAngle, 0, 1);
                        // scale val according to radial frequency
                        val = Wrap(val * this.config.domeRadialFrequency, 0, 1);
                        // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                        val = Math.Abs(Map(val, 0, 1, -1, 1));

                        gradientVal = Math.Abs(Map(angle, 0, 1, -1, 1));
                        break;

                    case 2:
                        // spiral mapping
                        val = MapWrap(angle + dist / this.config.domeRadialFrequency, currentAngle, 1 + currentAngle, 0, 1);
                        // scale val according to radial frequency
                        val = Wrap(val * this.config.domeRadialFrequency, 0, 1);
                        // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                        val = Math.Abs(Map(val, 0, 1, -1, 1));

                        gradientVal = dist;
                        break;

                    case 3:
                        // bubble mapping
                        var a = MapWrap(angle, currentAngle, 1 + currentAngle, 0, 1);
                        // scale val according to radial frequency
                        a = Wrap(a * this.config.domeRadialFrequency, 0, 1);
                        // center around val = 1/0 (0.5 maps to 0, 0 and 1 map to 1)
                        a   = Math.Abs(Map(a, 0, 1, -1, 1));
                        val = Clamp(dist - a, 0, 1);

                        gradientVal = dist;
                        break;
                    }

                    // size limit is scaled according the size slider and the current level
                    var  sizeLimit = this.config.domeRadialSize * adjustedLevel;
                    bool on        = val <= sizeLimit;

                    // use level to determine which colors to use
                    int whichGradient = (int)(level * 8);

                    var color = on ? this.dome.GetGradientColor(whichGradient, gradientVal, currentGradient, true) : 0;

                    this.dome.SetPixel(i, j, color);
                }
            }
        }