I want to create a Ball that could go bigger and smaller according to the Music Frequency. (I don’t want to use the sphere(), because it doesn’t create the dot points)
I made it work. But, it is a little bit laggy. At the moment, I could reduce the rows and cols or decrease the player analysis rate to relieve the situation. But, it is still laggy.
I think the main program is the three loops that I had. I tried to minimize them, but I have no idea what I can do.
Just a little bit more, instead of making the whole ball bigger and smaller. If there is anyway that I could make them like a “wave”? Something like perlin noise.
/***** IMPORT LIBRARIES *****/
import peasy.*; // Import Peasy Cam Library. Peasy Cam is a camera library.
import ddf.minim.analysis.*; // Import Minim Music Library
import ddf.minim.*; // Import Minim Music Library
/***** Define Some variables ****/
PeasyCam cam;
Minim minim;
AudioPlayer player;
FFT fft;
PVector[][] globe; // Create a Vector array to save all
int total = 50; // Rows and Cols of the ball
float angle; // Auto Rotate Ball
float c; // HSB Dynamic Color
void setup()
{
size(displayWidth, displayHeight, P3D); // Windows Size Not Correct
cam = new PeasyCam(this, 600); // Cam Size 600. Initial
minim = new Minim(this); // Initial Minim
globe = new PVector[total+1][total+1];
player = minim.loadFile("test.mp3", 128);
player.loop();
fft = new FFT( player.bufferSize(), player.sampleRate() );
}
void draw()
{
/***** Basic Setups *****/
background (0);
fft.forward( player.mix ); // Play the music forward
/***** START DRAWING THE BALL *****/
angle += PI/18; // + 10 Degree
rotateX(PI/2); // Rotate the Ball along the X
rotateY(angle); // Rotate the Ball along the Y with 10 degree
colorMode(HSB); // Set Color Mode to HSB
if (c >= 255) // Increase the c
{
c = 0;
} else
{
c++;
}
stroke(c, 255, 255); // Hue/Saturation/Brightness. Change the HUE and keep Saturation and Brighness 255
float r = 200; // Radius of the ball
for (int a = 0; a < fft.specSize(); a++)
{
/*****
Complicated Spherical Geometry Calculation
From YouTube The Coding Train: Spherical Geometry.
*****/
for (int i = 0; i < total+1; i++)
{
float lon = map(i, 0, total, -PI, PI);
for (int j = 0; j < total+1; j++)
{
float lat = map(j, 0, total, -HALF_PI, HALF_PI);
float x = r * sin(lon) * cos(lat);
float y = r * sin(lon) * sin(lat);
float z = r * cos(lon);
globe [i][j] = new PVector(x, y, z);
/*****
Returns the Perlin noise value at specified coordinates.
Perlin noise is a random sequence generator producing a more natural,
harmonic succession of numbers than that of the standard random() function.
*****/
point(x*noise(fft.getFreq(a)), y*noise(fft.getFreq(a)), z*noise(fft.getFreq(a)));
}
}
}
}