smooth descent of bars now after all averaging
This commit is contained in:
parent
e9d208ba55
commit
74e3a999c3
@ -21,6 +21,7 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
private int spaceBetweenBars;
|
private int spaceBetweenBars;
|
||||||
private Texture[] textures;
|
private Texture[] textures;
|
||||||
private Sprite[] bars;
|
private Sprite[] bars;
|
||||||
|
private float[] barHeights;
|
||||||
private int smoothRange;
|
private int smoothRange;
|
||||||
private float barHeightMultiplier;
|
private float barHeightMultiplier;
|
||||||
private float rotation;
|
private float rotation;
|
||||||
@ -40,6 +41,7 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
|
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
|
||||||
textures = new Texture[barCount];
|
textures = new Texture[barCount];
|
||||||
bars = new Sprite[barCount];
|
bars = new Sprite[barCount];
|
||||||
|
barHeights = new float[barCount];
|
||||||
|
|
||||||
for (int i = 0; i < textures.length; i++) {
|
for (int i = 0; i < textures.length; i++) {
|
||||||
textures[i] = new Texture(pixmap);
|
textures[i] = new Texture(pixmap);
|
||||||
@ -53,30 +55,19 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
@Override
|
@Override
|
||||||
public void render(Batch batch, float parentAlpha) {
|
public void render(Batch batch, float parentAlpha) {
|
||||||
if (mm != null) {
|
if (mm != null) {
|
||||||
//Drawing...
|
for (int i = 0; i < bars.length; i++) {
|
||||||
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));
|
|
||||||
bars[i].draw(batch);
|
bars[i].draw(batch);
|
||||||
|
for (int j = 0; j < mirrors.size; j++) {
|
||||||
|
mirrors.get(j).render(i, batch, parentAlpha, bars);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < mirrors.size; i++) {
|
|
||||||
mirrors.get(i).render(batch, parentAlpha, bars);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.render(batch, parentAlpha);
|
super.render(batch, parentAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void modify(float delta) {
|
public void modify(float delta) {
|
||||||
|
|
||||||
|
|
||||||
//Averaging bins together
|
//Averaging bins together
|
||||||
for (int i = 0; i < barCount; i++) {
|
for (int i = 0; i < barCount; i++) {
|
||||||
float barHeight = 2;
|
float barHeight = 2;
|
||||||
@ -85,7 +76,23 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
}
|
}
|
||||||
barHeight /= binsPerBar;
|
barHeight /= binsPerBar;
|
||||||
barHeight *= barHeightMultiplier;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +28,9 @@ public class MirrorVisualizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Batch batch, float parentAlpha, Sprite[] bars) {
|
public void render(int renderID, Batch batch, float parentAlpha, Sprite[] bars) {
|
||||||
for (int i = 0; i < this.bars.length; i++) {
|
this.bars[renderID].setSize(bars[renderID].getWidth(), bars[renderID].getHeight());
|
||||||
this.bars[i].setSize(bars[i].getWidth(), bars[i].getHeight());
|
this.bars[renderID].draw(batch);
|
||||||
this.bars[i].draw(batch);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void position(int barWidth, int spaceBetweenBars) {
|
public void position(int barWidth, int spaceBetweenBars) {
|
||||||
|
Loading…
Reference in New Issue
Block a user