Exemple #1
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();
        }
Exemple #2
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));
                }
            }
        }
Exemple #3
0
        private void ShowKey(object sender, RoutedEventArgs e)
        {
            this.keyMode = !this.keyMode;
            foreach (Label strutLabel in this.strutLabels)
            {
                strutLabel.Visibility = this.keyMode
          ? Visibility.Visible
          : Visibility.Collapsed;
            }
            this.showKey.Content = this.keyMode
        ? "Hide Key"
        : "Show Key";
            this.directionLabel.Visibility = this.keyMode
        ? Visibility.Visible
        : Visibility.Collapsed;
            this.previewBox.Visibility = this.keyMode
        ? Visibility.Visible
        : Visibility.Collapsed;

            if (!this.keyMode)
            {
                this.bitmap.WritePixels(this.rect, this.pixels, this.rect.Width * 4, 0);
                return;
            }

            var strutPixels = new byte[rect.Width * rect.Height * 4];

            for (int x = 0; x < rect.Width; x++)
            {
                for (int y = 0; y < rect.Height; y++)
                {
                    this.SetPixelColor(strutPixels, x, y, (uint)0xFF000000);
                }
            }

            uint color = (uint)SimulatorUtils.GetComputerColor(0xFFFFFF)
                         | (uint)0xFF000000;

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                var    pt1     = GetPoint(i, 0);
                var    pt2     = GetPoint(i, 1);
                int    numLEDs = LEDDomeOutput.GetNumLEDs(i);
                double deltaX  = (pt1.Item1 - pt2.Item1) / (numLEDs + 2.0);
                double deltaY  = (pt1.Item2 - pt2.Item2) / (numLEDs + 2.0);
                for (int j = 0; j < numLEDs * 3 / 4; j++)
                {
                    int x = pt1.Item1 - (int)(deltaX * (j + 1));
                    int y = pt1.Item2 - (int)(deltaY * (j + 1));
                    this.SetPixelColor(strutPixels, x, y, color);
                }
            }

            this.bitmap.WritePixels(this.rect, strutPixels, this.rect.Width * 4, 0);
        }
Exemple #4
0
        private void Update(object sender, EventArgs e)
        {
            int queueLength = this.config.domeCommandQueue.Count;

            if (queueLength == 0)
            {
                return;
            }

            //Stopwatch stopwatch = Stopwatch.StartNew();

            bool shouldRedraw = false;

            for (int k = 0; k < queueLength; k++)
            {
                DomeLEDCommand command;
                bool           result =
                    this.config.domeCommandQueue.TryDequeue(out command);
                if (!result)
                {
                    throw new Exception("Someone else is dequeueing!");
                }
                if (command.isFlush)
                {
                    shouldRedraw = true;
                    continue;
                }
                var    pt1     = GetPoint(command.strutIndex, 0);
                var    pt2     = GetPoint(command.strutIndex, 1);
                int    numLEDs = LEDDomeOutput.GetNumLEDs(command.strutIndex);
                double deltaX  = (pt1.Item1 - pt2.Item1) / (numLEDs + 2.0);
                double deltaY  = (pt1.Item2 - pt2.Item2) / (numLEDs + 2.0);
                int    x       = pt1.Item1 - (int)(deltaX * (command.ledIndex + 1));
                int    y       = pt1.Item2 - (int)(deltaY * (command.ledIndex + 1));
                uint   color   = (uint)SimulatorUtils.GetComputerColor(command.color)
                                 | (uint)0xFF000000;
                this.SetPixelColor(this.pixels, x, y, color);
            }

            if (shouldRedraw && !this.keyMode)
            {
                this.bitmap.WritePixels(this.rect, this.pixels, this.rect.Width * 4, 0);
            }

            //Debug.WriteLine("DomeSimulator took " + stopwatch.ElapsedMilliseconds + "ms to update");
        }
Exemple #5
0
        private void Draw()
        {
            uint color = (uint)SimulatorUtils.GetComputerColor(0x000000)
                         | (uint)0xFF000000;

            for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++)
            {
                var    pt1     = GetPoint(i, 0);
                var    pt2     = GetPoint(i, 1);
                int    numLEDs = LEDDomeOutput.GetNumLEDs(i);
                double deltaX  = (pt1.Item1 - pt2.Item1) / (numLEDs + 2.0);
                double deltaY  = (pt1.Item2 - pt2.Item2) / (numLEDs + 2.0);
                for (int j = 0; j < numLEDs; j++)
                {
                    int x = pt1.Item1 - (int)(deltaX * (j + 1));
                    int y = pt1.Item2 - (int)(deltaY * (j + 1));
                    this.SetPixelColor(this.pixels, x, y, color);
                }
            }
            this.bitmap.WritePixels(this.rect, this.pixels, this.rect.Width * 4, 0);
            this.image.Source = this.bitmap;
        }
        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);
                }
            }
        }
Exemple #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);
                }
            }
        }