I tried to create some random points inside a boundary defined by color (RGB(100,100,100)). If each new point's relating pixel is RGB(100,100,100), then create the point; vice versa. However, I find it really hard to work with this array. anybody has an suggestion?
PImage b;
PImage c;
float envSize = 280;
int population = 1000;
color[] imgPixels = new color[parseInt(envSize*2)*parseInt(envSize)];
kVec strPt;
//setup
void setup() {
smooth();
b = loadImage("background.gif");
size(b.width,b.height,P3D);
c = loadImage("boundary.png");
image(c,-width/2,-height/2);
loadPixels();
for(int i = 0; i < envSize*2*envSize; i++){
imgPixels[i] = pixels[i];
}
for(int i = 0; i < population; i++) {
strPt = new kVec(random(0,envSize),random(0,envSize/2),random(0,envSize/3));
colorMode(RGB);
if(pixels[parseInt(strPt.y)* width + parseInt(strPt.x)] == color(100,100,100)){
//create the point here;
}
}
I am using your library for rendering. It works pretty well with basic geometry. However, when I try to instance a huge amount of boxes to cloud of points, it doesn't work. I am wondering which step I went wrong, or it does has something problem with huge amount of geometries.
I am using control P5 and peasycam to create 3d agent based system. However, my controlP5's font is quite blurry. And I also don't know how could I move the camera to the center of my object in peasycam.
size(1200,800,P3D); //frameRate(30); smooth(); world1 = new kWorld(); population();
g3 = (PGraphics3D)g; cam = new PeasyCam(this, 2000); controlP5 = new ControlP5(this); control(); controlP5.setAutoDraw(false);
}
void population(){
world1 = new kWorld(); for (int i = 0; i < population; i++) { world1.addAgent(new kAgent(new PVector(random(150,width),random(0,height)), new PVector(random(-1,1),random(-1,1)),random(3,5), random(0.1,0.3))); } }
// add acc to vel vel.add(acc); // limit vel to maxVel vel.limit(maxVel); // add vel to pos pos.add(vel); acc.set(0,0,0); // reset acc to 0 each iteration
// separation PVector separate (ArrayList pop) { float desiredseparation = 25.0; PVector sum = new PVector(0,0,0); int count = 0;
for (int i = 0 ; i < pop.size(); i++) { kAgent other = (kAgent) pop.get(i); float dist = pos.dist(other.pos); // if the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) if ((dist > 0) && (dist < desiredseparation)) { // calculate vector pointing away from neighbor PVector diff = new PVector(pos.x, pos.y); diff.sub(other.pos); diff.normalize(); diff.mult(1/dist); // weight by distance sum.add(diff); count++; // keep track of how many } } // average -- divide by how many if (count > 0) { sum.mult(1/(float)count); } return sum; }
// alignment PVector align (ArrayList pop) { float neighbordist = 50.0; PVector sum = new PVector(0,0); int count = 0; for (int i = 0 ; i < pop.size(); i++) { kAgent other = (kAgent) pop.get(i); float dist = pos.dist(other.pos); if ((dist > 0) && (dist < neighbordist)) { sum.add(other.vel); count++; } } if (count > 0) { sum.mult(1/(float)count); sum.limit(maxForce); } return sum; }
// cohesion PVector cohesion (ArrayList pop) { float neighbordist = 50.0; PVector sum = new PVector(0,0); int count = 0; for (int i = 0 ; i < pop.size(); i++) { kAgent other = (kAgent) pop.get(i); float dist = pos.dist(other.pos); if ((dist > 0) && (dist < neighbordist)) { sum.add(other.pos); // Add location count++; } } if (count > 0) { sum.mult(1/(float)count); return steer(sum); // steer towards the location } return sum; }
kWorld() { population = new ArrayList(); // initialize the arraylist }
// cycles through each agent passing the population to it void run(){ for (int i = 0; i < population.size(); i++) { kAgent a = (kAgent) population.get(i); a.update(population); } }
// add agent void addAgent(kAgent a) { population.add(a); }