We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey everyone! I'm working on making a sphere out of individual points and calculating the radius of each point by the volume of the music. If you load my code you can see my problem. There is a big mark that indicates where the sphere starts and stops. Is there a way to make these two connected so it doesnt look as ugly? Any help is appreciated!!
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
PeasyCam cam;
Minim minim;
AudioPlayer player;
AudioMetaData meta;
BeatDetect beat;
FFT fft;
PVector[][] globe;
color[][] colormap;
float[][] r;
int total = 100;
float rad = 25;
float nI=0;
float nJ=0;
float hu;
float minRad = 30;
float maxRad = 100;
boolean calculated = false;
boolean up=true;
void setup() {
cam = new PeasyCam(this, 50);
minim = new Minim(this);
//player = minim.loadFile("D:/programeer gedoe/Programs/Music visualiser/PROCESSING VISUALIZER/Audio/SAIL - AWOLNATION.mp3");
//player = minim.loadFile("D:/programeer gedoe/Programs/Music visualiser/PROCESSING VISUALIZER/Audio/Ganja White Night - Mr Nice.mp3");
player = minim.loadFile("D:/programeer gedoe/Programs/Music visualiser/PROCESSING VISUALIZER/Audio/Imagine Dragons, Radioactive HD.mp3");
size(1000, 1000, P3D);
r = new float[total+1][total+1];
colormap = new color[total+1][total+1];
globe = new PVector[total+1][total+1];
colorMode(HSB);
smooth();
frameRate(30);
meta = player.getMetaData();
beat = new BeatDetect();
fft = new FFT(player.bufferSize(), player.sampleRate());
player.play(35000);
}
void draw() {
background(0);
lights();
noStroke();
// if (!calculated) {
//float nJ=0;
println("nI: " + nI);
println("nJ: " + nJ);
for (int i = 0; i < total+1; i++) {
float lat = map(i, 0, total, 0, PI);
for (int j = 0; j < total+1; j++) {
r[i][j] = map(player.left.get(i)*player.left.get(j), -1, 1, minRad, maxRad);
//r[i+1][j] = map(player.left.get(i)*player.left.get(j), 0, 1, minRad, maxRad);
//if (j == total && i == total) {
// r[i][j] = map(player.left.get(0)*player.left.get(0), 0, 3.5, minRad, maxRad);
//}
if (nI > 15 && up) {
up = false;
}
if (nI >= 15) {
up = false;
} else if (nI <= 0) {
up = true;
}
if (up) {
nI+=0.0000002;
nJ+=0.0000002;
} else {
nI-=0.0000005;
nJ-=0.0000005;
}
hu = map(r[i][j], minRad, maxRad, 0, 255);
colormap[i][j] = color(hu, 255, 255);
//fill(hu, 255, 255);
float lon = map(j, 0, total, 0, TWO_PI);
//float x = rad*cos(lon)*sin(lat);
//float y = rad*sin(lat)*sin(lon);
//float z = rad*cos(lat);
float x = r[i][j]*cos(lon)*sin(lat);
float y = r[i][j]*sin(lat)*sin(lon);
float z = r[i][j]*cos(lat);
globe[i][j] = new PVector(x, y, z);
}
}
calculated = true;
//}
for (int i =0; i < total; i++) {
beginShape(TRIANGLE_STRIP);
for (int j = 0; j < total + 1; j++) {
fill(colormap[i][j]);
PVector v = globe[i][j];
PVector v2 = globe[i+1][j];
vertex(v.x, v.y, v.z);
fill(colormap[i+1][j]);
vertex(v2.x, v2.y, v2.z);
}
endShape();
}
}
Answers
I can't run the code without all the classes. Could you provide a download link to the whole sketch?
@Moeemoee -- I can't test your sketch, but this might be helpful -- does this relate to your issue?
A general overview of two approaches to creating a sphere out of points. Z-projection creates a ragged edge at the meridian -- a Fibonacci sphere does not.