1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Update nyan rainbow scaling and painting.

This is the last time, promise :)
This commit is contained in:
Tyler Rhodes 2011-06-23 15:14:39 +00:00
parent 663e5916dd
commit 5792c114e8
2 changed files with 6 additions and 14 deletions

View File

@ -24,7 +24,7 @@
#include <QBrush>
const char* NyanCatAnalyzer::kName = "Nyan nyan nyan";
const float NyanCatAnalyzer::kPixelScale = 0.03f;
const float NyanCatAnalyzer::kPixelScale = 0.02f;
NyanCatAnalyzer::NyanCatAnalyzer(QWidget* parent)
@ -35,10 +35,9 @@ NyanCatAnalyzer::NyanCatAnalyzer(QWidget* parent)
background_brush_(QColor(0x0f, 0x43, 0x73))
{
memset(history_, 0, sizeof(history_));
memset(mean_history_, 0, sizeof(mean_history_));
for (int i=0 ; i<kRainbowBands ; ++i) {
colors_[i] = QPen(QColor::fromHsv(i * 255 / kRainbowBands, 255, 255), 4.5);
colors_[i] = QPen(QColor::fromHsv(i * 255 / kRainbowBands, 255, 255), kCatHeight/kRainbowBands);
}
}
@ -68,10 +67,6 @@ void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s) {
// And set the new frame to 0.
band_start[kHistorySize-1] = 0;
}
// adjust mean history
memmove(mean_history_, mean_history_ + 1, (kHistorySize - 1) * sizeof(float));
mean_history_[kHistorySize-1] = 0;
// Now accumulate the scope data into each band. Should maybe use a series
// of band pass filters for this, so bands can leak into neighbouring bands,
@ -83,11 +78,7 @@ void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s) {
for (int i=0 ; i<samples_per_band ; ++i) {
*accumulator += s[sample++];
}
const float band_scale = std::pow(2.0, band);
*accumulator *= band_scale;
mean_history_[kHistorySize-1] += *accumulator;
}
mean_history_[kHistorySize-1] /= kRainbowBands;
// Create polylines for the rainbows.
const float px_per_frame = float(width() - kCatWidth + kRainbowOverlap) / kHistorySize;
@ -99,10 +90,12 @@ void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s) {
for (int band=0 ; band<kRainbowBands ; ++band) {
// Calculate the Y position of this band.
const float y = float(kCatHeight) / (kRainbowBands + 2) * (band + 0.5) + top_of_cat;
// pow constants computed so that
// | band_scale(0) | ~= .5 and | band_scale(5) | ~= 32
const float band_scale = -std::cos(M_PI*band/(kRainbowBands-1))*.5*std::pow(2.3, band);
// Add each point in the line.
for (int x=0 ; x<kHistorySize; ++x) {
*dest = QPointF(px_per_frame * x, y + (*source - mean_history_[x]) * kPixelScale);
// qLog(Debug) << y+ *source *kPixelScale << mean;
*dest = QPointF(px_per_frame * x, y + *source * kPixelScale * band_scale);
++ dest;
++ source;
}

View File

@ -60,7 +60,6 @@ private:
int frame_;
float history_[kHistorySize * kRainbowBands];
float mean_history_[kHistorySize * kRainbowBands];
QPen colors_[kRainbowBands];
QBrush background_brush_;