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(); }
public void Visualize() { if (this.stopwatch.ElapsedMilliseconds <= 250) { return; } this.stopwatch.Restart(); this.state = (this.state + 1) % 2; if (this.state == 0) { for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++) { Strut strut = Strut.FromIndex(this.config, i); for (int j = 0; j < strut.Length; j++) { this.dome.SetPixel(i, j, 0x000000); } } this.dome.Flush(); return; } byte brightnessByte = (byte)( 0xFF * this.config.domeMaxBrightness * this.config.domeBrightness ); int color = brightnessByte << 16 | brightnessByte << 8 | brightnessByte; for (int teensy = 0; teensy < 5; teensy++) { for (int localIndex = 0; localIndex < 38; localIndex++) { var strutIndex = LEDDomeOutput.FindStrutIndex(teensy, localIndex); Strut strut = Strut.FromIndex(this.config, strutIndex); if (this.state == 2) { for (int j = 1; j < strut.Length - 1; j++) { this.dome.SetPixel(strutIndex, j, 0x000000); } this.dome.SetPixel(strutIndex, 0, color); this.dome.SetPixel(strutIndex, strut.Length - 1, color); } else { for (int j = 0; j < strut.Length; j++) { this.dome.SetPixel(strutIndex, j, color); } } } } this.dome.Flush(); }
public DomeSimulatorWindow(Configuration config) { this.InitializeComponent(); this.config = config; this.rect = new Int32Rect(0, 0, 750, 750); this.bitmap = new WriteableBitmap( this.rect.Width, this.rect.Height, 96, 96, PixelFormats.Bgra32, null ); this.pixels = new byte[this.rect.Width * this.rect.Height * 4]; for (int x = 0; x < this.rect.Width; x++) { for (int y = 0; y < this.rect.Height; y++) { this.SetPixelColor(this.pixels, x, y, (uint)0xFF000000); } } RenderOptions.SetBitmapScalingMode( this.image, BitmapScalingMode.NearestNeighbor ); RenderOptions.SetEdgeMode( this.image, EdgeMode.Aliased ); this.strutLabels = new Label[LEDDomeOutput.GetNumStruts()]; var brush = new SolidColorBrush(Colors.White); for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++) { var pt1 = GetPoint(i, 0); var pt2 = GetPoint(i, 1); var centerX = (pt1.Item1 + pt2.Item1) / 2; var centerY = (pt1.Item2 + pt2.Item2) / 2; Label label = new Label(); label.Content = i; label.FontSize = 12; label.Visibility = Visibility.Collapsed; label.Foreground = brush; label.Margin = new Thickness( centerX - 10, centerY - 10, 0, 0 ); label.MouseDown += StrutLabelClicked; this.strutLabels[i] = label; this.canvas.Children.Add(label); } }
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 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); }
public void Static() { for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++) { Strut strut = Strut.FromIndex(this.config, i); for (int j = 0; j < strut.Length; j++) { this.dome.SetPixel(i, j, this.RandomColor()); } } }
public void Visualize() { if (this.wipeStrutsNextCycle) { for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++) { Strut strut = Strut.FromIndex(this.config, i); for (int j = 0; j < strut.Length; j++) { this.dome.SetPixel(i, j, 0x000000); } } this.wipeStrutsNextCycle = false; } //this.StaticRingsAnimated(); this.ParametricTest(); //this.wipeStrutsNextCycle = true; this.dome.Flush(); }
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; }
public void Visualize() { if (this.wipeStrutsNextCycle) { for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++) { Strut strut = Strut.FromIndex(this.config, i); for (int j = 0; j < strut.Length; j++) { this.dome.SetPixel(i, j, 0x000000); } } this.wipeStrutsNextCycle = false; } this.UpdateCenter(); this.UpdateAnimationSize(this.config.domeVolumeAnimationSize); int subdivisions = this.partLayout.NumSegments / 2; int totalParts = this.config.domeVolumeAnimationSize; int volumeSplitInto = 2 * ((totalParts - 1) / 2 + 1); for (int part = 0; part < totalParts; part += 2) { var outwardSegment = this.partLayout.GetSegment(part); double startRange = (double)part / volumeSplitInto; double endRange = (double)(part + 2) / volumeSplitInto; double level = this.audio.LevelForChannel(0); double scaled = (level - startRange) / (endRange - startRange); scaled = Math.Max(Math.Min(scaled, 1.0), 0.0); startRange = Math.Min(startRange / level, 1.0); endRange = Math.Min(endRange / level, 1.0); foreach (Strut strut in outwardSegment.GetStruts()) { this.UpdateStrut(strut, scaled, startRange, endRange); } if (part + 1 == totalParts) { break; } for (int i = 0; i < 6; i++) { StrutLayoutSegment segment = this.sectionLayout.GetSegment(i + part * 3); double gradientStartPos = 0.0; double gradientStep = 1.0 / segment.GetStruts().Count; foreach (Strut strut in segment.GetStruts()) { double gradientEndPos = gradientStartPos + gradientStep; this.UpdateStrut( strut, scaled == 1.0 ? 1.0 : 0.0, gradientStartPos, gradientEndPos ); gradientStartPos = gradientEndPos; } } } this.dome.Flush(); }
public void Visualize() { if (this.stopwatch.ElapsedMilliseconds <= 1000) { return; } this.stopwatch.Restart(); this.lastIndex++; byte brightnessByte = (byte)( 0xFF * this.config.domeMaxBrightness * this.config.domeBrightness ); int whiteColor = brightnessByte << 16 | brightnessByte << 8 | brightnessByte; if (this.lastIndex == 38) { this.lastIndex = 0; this.lastTeensy = (this.lastTeensy + 1) % 5; // Reset every LED to blue for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++) { Strut blueStrut = Strut.FromIndex(this.config, i); for (int j = 0; j < blueStrut.Length; j++) { this.dome.SetPixel(i, j, 0x0000FF); } } if (this.lastTeensy == 0) { if (this.color == 0xFF0000) { this.color = 0x00FF00; } else if (this.color == 0x00FF00) { this.color = 0x0000FF; } else if (this.color == 0x0000FF) { this.color = 0xFFFFFF; } else if (this.color == 0xFFFFFF) { this.color = 0xFF0000; } } } var strutIndex = LEDDomeOutput.FindStrutIndex( this.lastTeensy, this.lastIndex ); Strut strut = Strut.FromIndex(this.config, strutIndex); for (int i = 0; i < strut.Length; i++) { this.dome.SetPixel(strutIndex, i, this.color & whiteColor); } this.dome.Flush(); }
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); } } }
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); } } }
public void Visualize() { var commands = this.midi.GetCommandsSinceLastTick(); bool valueSet = false; foreach (MidiCommand command in commands) { if (command.type != MidiCommandType.Note) { continue; } if (command.index < 48 || command.index > 51) { continue; } valueSet = true; if (this.strutStates.ContainsKey(command.index)) { var existingStrutIndex = this.strutStates[command.index]; Strut existingStrut = Strut.FromIndex(this.config, existingStrutIndex); for (int i = 0; i < existingStrut.Length; i++) { this.dome.SetPixel(existingStrutIndex, i, 0x000000); } this.strutStates.Remove(command.index); if (command.value == 0.0) { continue; } } int color = 0; int brightnessByte = (int)( 0xFF * this.config.domeMaxBrightness * this.config.domeBrightness * command.value ); if (command.index == 48) { color = brightnessByte << 16; } else if (command.index == 49) { color = brightnessByte << 8; } else if (command.index == 50) { color = brightnessByte; } else if (command.index == 51) { color = brightnessByte | brightnessByte << 8 | brightnessByte << 16; } int strutIndex = -1; while (strutIndex == -1) { int candidateStrutIndex = (int)(this.rand.NextDouble() * LEDDomeOutput.GetNumStruts()); if (this.strutStates.ContainsValue(candidateStrutIndex)) { continue; } strutIndex = candidateStrutIndex; } Strut strut = Strut.FromIndex(this.config, strutIndex); for (int i = 0; i < strut.Length; i++) { this.dome.SetPixel(strutIndex, i, color); } this.strutStates[command.index] = strutIndex; } if (valueSet) { this.dome.Flush(); } }
public void Visualize() { if (this.stopwatch.ElapsedMilliseconds <= 1000) { return; } this.stopwatch.Restart(); this.state = (this.state + 1) % 4; if (this.state == 0) { for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++) { Strut strut = Strut.FromIndex(this.config, i); for (int j = 0; j < strut.Length; j++) { this.dome.SetPixel(i, j, 0x000000); } } this.dome.Flush(); return; } byte brightnessByte = (byte)( 0xFF * this.config.domeMaxBrightness * this.config.domeBrightness ); int whiteColor = brightnessByte << 16 | brightnessByte << 8 | brightnessByte; int[] colors = { whiteColor& 0xFF0000, whiteColor& 0x00FF00, whiteColor& 0x0000FF, whiteColor& 0xFFFF00, whiteColor& 0xFF00FF, whiteColor& 0x00FFFF, }; for (int controlBox = 0; controlBox < 5; controlBox++) { int colorIndex = 0; for (int localIndex = 0; localIndex < 38; localIndex++) { var strutIndex = LEDDomeOutput.FindStrutIndex(controlBox, localIndex); Strut strut = Strut.FromIndex(this.config, strutIndex); if (this.state == 2) { for (int j = 1; j < strut.Length - 1; j++) { this.dome.SetPixel(strutIndex, j, 0x000000); } this.dome.SetPixel(strutIndex, 0, colors[colorIndex]); this.dome.SetPixel(strutIndex, strut.Length - 1, colors[colorIndex]); } else { for (int j = 0; j < strut.Length; j++) { this.dome.SetPixel(strutIndex, j, colors[colorIndex]); } } colorIndex = (colorIndex + 1) % colors.Length; } } this.dome.Flush(); }