0

Alright - so here's my story. I have this game called ShiftOS, and one of the parts of the game is the ability to fight with various networks in a Hacker Battle. In the background of the Hacker Battle, I have some royalty-free EDM/House music playing through a WMPLib.WindowsMediaPlayer object and it all works fine.

Now, because the music is kinda meant for dance, it should be easy to make flashy colors, right? Well, that's what I'm doing. At certain parts of each song I have different "visualizers" set, and each visualizer can either be a "Pulse", where the color values go from 0 to 255, and back, in a fast loop, or "BuildUp", where the color gets brighter throughout the section, or "CalmDown", where the color gets darker throughout the section. Cool. This works perfectly as I can get the current position of the song and what visualizer should happen at the current point.

The plan is to set the background color of a WinForms panel to the proper color of the visualizer, and for Pulses, I have that working perfectly. As for BuildUps and CalmDowns, well, this is tricky, and I have two problems.

For BuildUp, how can I take two 'minimum and maximum' values, say, 100 and 150, and then take a 'position' value between the two, say '125', and turn it into a color value, say, 'minimum' is 0, 'maximum' is 255, and 'position' is '127'?

And for CalmDown, how would I reverse that value so that the color gets darker over time?

  • 3
    [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation). – Mephy May 29 '16 at 21:13
  • Maybe easier and better looking would be adding some **FIR** filter to the color to simulate "color mass inertia" for example on each frame do `color=0.95*color + 0.05*new_color` and play with the constants so the change speed is visually pleasing (not too fast would flicker and not too slow will have a delay to the music). There a a lot of other ways like **PID** regulation ... but simple **FIR** filter is I think best for this – Spektre May 30 '16 at 07:05

0 Answers0