import { MovingHeadState } from "rust_native_module";
import { Pattern, PatternOutput, Time } from "./proto";
import { startAddresses } from "./stage";

export class TestPattern implements Pattern {

  rgbw = [
    [255, 0, 0, 0],
    [0, 255, 0, 0],
    [0, 0, 255, 0],
    [0, 0, 0, 255],
  ]

  render(time: Time): PatternOutput {
    let t = time.absolute % this.rgbw.length;
    let second = Math.floor(t);
    let brightness = 1 - (t % 1);

    return startAddresses.map((startAddress) => {

      let [r, g, b, w] = this.rgbw[second];

      let state: MovingHeadState = {
        startAddress: startAddress,
        pan: 0,
        tilt: 0,
        brightness: {
          type: "dimmer",
          value: brightness,
        },
        rgbw: [r, g, b, w],
        speed: 1,
        reset: false
      }
      return state;
    })
  }

}
