Scaling text
in
Core Library Questions
•
10 months ago
Hello, I am trying to create text that changes in size according to the frequency of the song being played. I have managed to get it to work, however one problem that I am facing is that the text does not scale in a center alignment (I want the size of the text to change but the position remain the same), but rather it scales outwards, is there any way I can work around this? Thank you so much for reading this and helping!
Here is my code:
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
Minim minim;
AudioPlayer song;
FFT fft;
PFont Header;
int leftcol = 50;
int row1 = 35;
float[] Channel = new float[10];
void setup(){
size(600,600);
Header = loadFont("font1.vlw");
minim = new Minim(this);
song = minim.loadFile("craveyou.mp3", 512);
song.play();
song.mute();
fft = new FFT(song.bufferSize(), song.sampleRate());
fft.logAverages(32,1);
}
void draw(){
calculateFFT();
background(0);
smooth(8);
textFont(Header, Channel[4]);
fill(255);
textAlign(CENTER,CENTER);
text("a", width/2, height/2);
}
void stop(){
song.close();
minim.stop();
super.stop();
}
void calculateFFT(){
fft.forward(song.mix);
Channel[0] = map(fft.getAvg(0), 0, 69, 0, 255);
Channel[1] = map(fft.getAvg(1), 0, 106, 0, 225);
Channel[2] = map(fft.getAvg(2), 0, 119, 0, 255);
Channel[3] = map(fft.getAvg(3), 0, 66, 0, 255);
Channel[4] = map(fft.getAvg(4), 0, 29, 0, 255);
Channel[5] = map(fft.getAvg(5), 0, 16, 0, 255);
Channel[6] = map(fft.getAvg(6), 0, 15, 0, 255);
Channel[7] = map(fft.getAvg(7), 0, 7, 0, 255);
Channel[8] = map(fft.getAvg(8), 0, 3, 0, 255);
Channel[9] = map(fft.getAvg(9), 0, 0, 0, 255);
}
1