smooth descent of bars now after all averaging

This commit is contained in:
Harrison Deng 2017-10-04 15:31:05 -05:00
parent e9d208ba55
commit 74e3a999c3
2 changed files with 29 additions and 24 deletions

View File

@ -21,6 +21,7 @@ public class BasicVisualizer extends VisualizerCore {
private int spaceBetweenBars;
private Texture[] textures;
private Sprite[] bars;
private float[] barHeights;
private int smoothRange;
private float barHeightMultiplier;
private float rotation;
@ -40,7 +41,8 @@ public class BasicVisualizer extends VisualizerCore {
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
textures = new Texture[barCount];
bars = new Sprite[barCount];
barHeights = new float[barCount];
for (int i = 0; i < textures.length; i++) {
textures[i] = new Texture(pixmap);
bars[i] = new Sprite(textures[i]);
@ -53,30 +55,19 @@ public class BasicVisualizer extends VisualizerCore {
@Override
public void render(Batch batch, float parentAlpha) {
if (mm != null) {
//Drawing...
for (int i = 0; i < barCount; i++) {
int avg = 0;
//Averaging the bars
for (int range = 0; range < smoothRange; range++) {
if (i+range < barCount) {
avg += bars[i+range].getHeight();
}
if (i-range >= 0) {
avg += bars[i-range].getHeight();
}
}
bars[i].setSize(barWidth, avg/(smoothRange*2));
for (int i = 0; i < bars.length; i++) {
bars[i].draw(batch);
}
for (int i = 0; i < mirrors.size; i++) {
mirrors.get(i).render(batch, parentAlpha, bars);
for (int j = 0; j < mirrors.size; j++) {
mirrors.get(j).render(i, batch, parentAlpha, bars);
}
}
}
super.render(batch, parentAlpha);
}
public void modify(float delta) {
//Averaging bins together
for (int i = 0; i < barCount; i++) {
float barHeight = 2;
@ -85,7 +76,23 @@ public class BasicVisualizer extends VisualizerCore {
}
barHeight /= binsPerBar;
barHeight *= barHeightMultiplier;
bars[i].setSize(barWidth, bars[i].getHeight() < barHeight ? barHeight : bars[i].getHeight() - 1.5f*Gdx.graphics.getHeight()*delta);
barHeights[i] = barHeight;
}
for (int i = 0; i < barCount; i++) {
int avg = 0;
//Averaging the bars
for (int range = 0; range < smoothRange; range++) {
if (i+range < barCount) {
avg += barHeights[i+range];
}
if (i-range >= 0) {
avg += barHeights[i-range];
}
}
avg /= smoothRange*2;
barHeights[i] = avg;
bars[i].setSize(barWidth, bars[i].getHeight() <= barHeights[i] ? barHeights[i] : bars[i].getHeight() - 1.1f*Gdx.graphics.getHeight()*delta);
}
}

View File

@ -28,11 +28,9 @@ public class MirrorVisualizer {
}
}
public void render(Batch batch, float parentAlpha, Sprite[] bars) {
for (int i = 0; i < this.bars.length; i++) {
this.bars[i].setSize(bars[i].getWidth(), bars[i].getHeight());
this.bars[i].draw(batch);
}
public void render(int renderID, Batch batch, float parentAlpha, Sprite[] bars) {
this.bars[renderID].setSize(bars[renderID].getWidth(), bars[renderID].getHeight());
this.bars[renderID].draw(batch);
}
public void position(int barWidth, int spaceBetweenBars) {