counting problem
in
Contributed Library Questions
•
2 years ago
hi guys,
i think my friend tried to post this earlier but didn't explain it well...
i'm trying to write a script which seperates a list into those which are at X pixels away and those are more than X pixels away then count both arraylists. I've been trying this for quite some time but cant get the points grouped up correctly, any help would be appreciated!
i'm using toxic libs geometry library for the vector math.
- import toxi.geom.*;
- PFont f;
Closestpoint AdrClosePoint;- ArrayList pointCollection;
- ArrayList templist;
- void setup() {
- size (1400, 900);
background(255);
f = createFont("Arial", 12, true);
textFont(f);
- f = createFont("Arial",16,true); // Loading font
pointCollection = new ArrayList();
templist = new ArrayList();
-
for (int i = 0; i<1000; i++){
Vec3D origin = new Vec3D(random(width), random(height), 0);
Closestpoint mypoint = new Closestpoint(origin);
pointCollection.add(mypoint);
}
} - void draw() {
for (int i = 0; i< pointCollection.size(); i++){
Closestpoint cp = (Closestpoint) pointCollection.get(i);
cp.display();
cp.distancenear();
- }
text(pointCollection.size()- templist.size(), width/2, height/2);
- class Closestpoint {
- //global variables
- Vec3D pos = new Vec3D (0, 0, 0);
- //constructor
Closestpoint(Vec3D _pos) {
pos = _pos;
} - //functions
- void display() {
- stroke(0);
strokeWeight(1);
point(pos.x, pos.y);
} - void distancenear() {
- int count=0;
- for (int i = 0; i < pointCollection.size();i++) {
Closestpoint other = (Closestpoint) pointCollection.get(i);
float distance = pos.distanceTo(other.pos);
if ( distance >0 && distance < 20) {
fill(0,0,255);
ellipse(pos.x, pos.y, 20,20);
if(count < pointCollection.size()){
templist.add(pos);
count++;
}
}else{
getpoints(distance, pos, other.pos);
}
}
}
} - void getpoints(float distance, Vec3D pos, Vec3D other) {
- fill(255, 100, 0);
- ellipse(pos.x, pos.y, 10, 10);
- }
}
2