#include #include #include namespace VIZ { Random::Random(AudioGrabber *pGrabber, Vulcan121 *vulcan) : VIZ(pGrabber, vulcan) { m_random.setDist(0, keyboardData.num_keys); } void Random::onSetup() { keyboard->sendToLEDs({ 0, 0, 0, 0 }); Vulcan121::setColor(map, {255,155,0,255}); grabber->requestMode = AudioGrabber::ReqMode::FFT; } void Random::onTick(float /*delta*/) { double val = grabber->getBass(); double energy = val / 255.0; uint16_t half = val / 2; Vulcan121::fadeOutMap(map, (energy * 0.55) + 0.25); m_angle += energy; rgb nColor = Color::Generator::rgbFromHSV({ m_angle, 1.0, 1.0 }); if (m_angle > 360) m_angle -= 360; auto times = std::lround(energy * 4.5); auto factor = 1.0; // search for a less < halfPeak for (int i = 0; i < times; i++) { for (int j = 0; j < 3; j++) { auto key = static_cast(m_random.getFast()); auto &item = map.key[key]; if (item.a < half) { item.r = int16_t(nColor.r * 255); item.g = int16_t(nColor.g * 255); item.b = int16_t(nColor.b * 255); item.a = static_cast(val * factor); factor -= 0.2; break; } } } keyboard->sendLedMap(map); } const char *Random::name() { return "Random"; } }