Skip to content

Commit

Permalink
Port paintbrush to use dome buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
larryfenn committed Aug 23, 2022
1 parent b362529 commit c1e1c9f
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions Spectrum/Visualizers/LEDDomeQuaternionPaintbrushVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LEDDomeQuaternionPaintbrushVisualizer : Visualizer {
private AudioInput audio;
private OrientationInput orientation;
private LEDDomeOutput dome;
private LEDDomeOutputBuffer buffer;
private Vector3 spot = new Vector3(0, 1, 0);

public LEDDomeQuaternionPaintbrushVisualizer(
Expand All @@ -25,6 +26,7 @@ LEDDomeOutput dome
this.orientation = orientation;
this.dome = dome;
this.dome.RegisterVisualizer(this);
this.buffer = this.dome.MakeDomeOutputBuffer();
}

public int Priority {
Expand All @@ -40,24 +42,23 @@ public Input[] GetInputs() {
}

void Render() {
for (int i = 0; i < LEDDomeOutput.GetNumStruts(); i++) {
var leds = LEDDomeOutput.GetNumLEDs(i);
for (int j = 0; j < leds; j++) {
var p = StrutLayoutFactory.GetProjectedLEDPoint(i, j); // centered on (.5, .5), [0, 1] x [0, 1]
var x = 2 * p.Item1 - 1; // now centered on (0, 0) and with range [0, 1]
var y = 1 - 2 * p.Item2; // this is because in the original mapping x, y come "out of" the top left corner
float z = (float)Math.Sqrt(1 - x * x - y * y);
Vector3 pixelPoint = new Vector3((float)x, (float)y, z);
// Calibration assigns (0, 1, 0) to be 'forward'
// So we want the post-transformed pixel closest to (0, 1, 0)?
Color color = new Color(0, 0, 0);
if(Vector3.Distance(Vector3.Transform(pixelPoint, orientation.rotation), spot) < .25) {
color = new Color((256 * (orientation.rotation.W + 1)) / 256d, 1, 1);
}
// todo : rework to use jan karls buffer
this.dome.SetPixel(i, j, color.ToInt());
buffer.Fade(1 - Math.Pow(10, -this.config.domeGlobalFadeSpeed), 0);
buffer.HueRotate(Math.Pow(10, -this.config.domeGlobalHueSpeed));
for (int i = 0; i < buffer.pixels.Length; i++) {
var p = buffer.pixels[i];
var x = 2 * p.x - 1; // now centered on (0, 0) and with range [0, 1]
var y = 1 - 2 * p.y; // this is because in the original mapping x, y come "out of" the top left corner
float z = (float)Math.Sqrt(1 - x * x - y * y);
Vector3 pixelPoint = new Vector3((float)x, (float)y, z);
// Calibration assigns (0, 1, 0) to be 'forward'
// So we want the post-transformed pixel closest to (0, 1, 0)?
if(Vector3.Distance(Vector3.Transform(pixelPoint, orientation.rotation), spot) < .25) {
Color color = new Color((256 * (orientation.rotation.W + 1) / 2) / 256d, 1, 1);
buffer.pixels[i].color = color.ToInt();
}
}
this.dome.WriteBuffer(buffer);

}

public void Visualize() {
Expand Down

0 comments on commit c1e1c9f

Please # to comment.