Hello! I need your help!
i have a perlin noise particle funktion, where every particle connects with their nearest neighbour. the connection, which is currently a line, should be a box, to have it as a volume. it would be awesome if you guys can help me!!!! //line from one vector to his nearest neighbor line(pos.x, pos.y , pos.z, npos.x, npos.y, npos.z);
import peasy.test.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
float depth = 500;
PVector[] nOffset;
float nScale = 0.01;
float stepSize = 3;
ArrayList<Particle> particles;
ArrayList<Connection> cn=new ArrayList<Connection>();
PeasyCam cam;
void setup(){
size(1500,1000, P3D);
frameRate(25);
cam=new PeasyCam(this, 300);
nOffset = new PVector[3];
for(int i = 0; i < 3; i++){
nOffset[i] = new PVector(random(1), random(10000), random(10000));
}
particles = new ArrayList<Particle>();
for(int i = 0; i <300; i++){
particles.add(new Particle());
}
noFill();
background(0);
}
void draw(){
background(0);
stroke(255);
for(Particle p: particles){p.update();}
for (Connection c : cn) c.display();
stroke(255);
translate(750,700,200);
box(1500,1500,400);
if (frameCount%10==0)for (Particle p : particles)p.connect();
}
class Particle {
PVector pos;
Particle() {
pos = new PVector(random(1500), random(1500), random(400));
}
void update() {
float x = pos.x + map(noise(nOffset[0].x + pos.x * nScale, nOffset[0].y + pos.y * nScale, nOffset[0].z + pos.z * nScale), 0, 1, -stepSize, stepSize);
float y = pos.y + map(noise(nOffset[1].x + pos.x * nScale, nOffset[1].y + pos.y * nScale, nOffset[1].z + pos.z * nScale), 0, 1, -stepSize, stepSize);
float z = pos.z + map(noise(nOffset[2].x + pos.x * nScale, nOffset[2].y + pos.y * nScale, nOffset[2].z + pos.z * nScale), 0, 1, -stepSize, stepSize);
PVector npos = new PVector(x, y, z);
pushMatrix();
//translate(0, 0, 0);
//line(pos.x, pos.y , pos.z, npos.x, npos.y, npos.z);
popMatrix();
if ((0 <= npos.x && npos.x <1500 && 0 <= npos.y && npos.y <1500 && 0 <= npos.z && npos.z < 400) &&
(random(1) < 0.995)) {
pos = npos;
} else {
pos = new PVector(random(1500), random(1500), random(400));
}
}
void connect() {
for (Particle p : particles) {
if (p.pos.dist(pos)<150&&p!=this)cn.add(new Connection(p.pos, this.pos));//check for any particles closer than 200, if there are any add a new Connection by providing two positions
}
}
}
class Connection {// this class describes the connections between particles, "connect" function inside of the "Particle" class creates new Connection objects
PVector pos, npos;//a connection needs a beginning and end vector
Connection(PVector p1, PVector p2) {// in order to create a connection, we need to provide two vectors... check "connect" function inside of the "Particle" class
pos=p1.get();
npos=p2.get();
}
void display() {
stroke(255, 100);
strokeWeight(0.3);
line(pos.x, pos.y , pos.z, npos.x, npos.y, npos.z); //line from one vector to his nearest neighbor
}
}