We are about to switch to a new forum software. Until then we have removed the registration on this forum.
how to set the position so the yellow and green balls keep a fix distance with the grey? is there any way to achieve that...
do i need a calculation for this poisition (where to freeze)? or make the balls go into the space(gap) between the grey branch and freeze ?
ArrayList<Dot> dots = new ArrayList();
int frozen_red_counter;
color[] valid_colors = {
color(128), color(255, 128, 0), color(0, 255, 128)//, color(0,128,0), color(255,128,0)
};
int INITIAL_DOTS = 300;
int MAX_DOTS = 500;
void setup() {
size(400, 400);
int frozen_red_counter=0;
for (int i=0; i<INITIAL_DOTS; i++) {
dots.add(new Dot());
}
dots.get(0).x_position = width/2;
dots.get(0).y_position = height/2;
dots.get(0).is_frozen = true;
dots.get(0).type = 0;
noStroke();
}
void draw() {
background(0);
for (int i=0; i<dots.size (); dots.get(i++).draw());
}
void mousePressed () {
if (key == 'e'){
saveFrame("viruses-###.tif");
}
}
class Dot {
float x_position;
float y_position;
float x_velocity;
float y_velocity;
int type;
boolean is_frozen;
int my_id;
Dot() {
x_position = 0; //random(width);
y_position = 0; //random(height);
x_velocity = random( -3, 3 );
y_velocity = random( -3, 3 );
type = int(random(valid_colors.length));
is_frozen = false;
my_id = dots.size();
}
void draw() {
render();
display();
}
void render() {
// Draw this dot.
if ( type == 0 ) {
fill(valid_colors[0]);
noStroke();
ellipse(x_position, y_position, 8, 8);
}
if ( type == 1 ) {
fill(valid_colors[1]);
noStroke();
ellipse(x_position, y_position, 8, 8);
}
if ( type == 2 ) {
fill(valid_colors[2]);
noStroke();
ellipse(x_position, y_position, 8, 8);
}
}
void display() {
if (is_frozen) return;
x_position += x_velocity + width;
y_position += y_velocity + height;
x_position %= width;
y_position %= height;
// If this dot should freeze...
if (should_i_freeze()) {
// Freeze it.
is_frozen = true;
// And also add a new dot if there's space for more.
// if ( dots.size() < MAX_DOTS ) {
// dots.add(new Dot());
// }
}
}
// This function determines if this dot should freeze.
boolean should_i_freeze() {
// Dots that are already frozen do not need to freeze again.
if (is_frozen) {
return(false);
}
for (int i=0; i<dots.size (); i++) {
// But only look at dots that are frozen...
if (dots.get(i).is_frozen ) {
// Now we find the distance between ourself and that frozen dot.
float distance = dist(x_position, y_position, dots.get(i).x_position, dots.get(i).y_position);
// And if we are red and the other dot is also red...
if (frozen_red_counter < 80) {
//control number of red
if (type == 0 && distance <= 12 && dots.get(i).type == 0) {
// We need to freeze this dot!
frozen_red_counter++;
return(true);
}
}
if (frozen_red_counter >= 80 && frozen_red_counter <= 100) { //control number of grey andgreen
// If we are non-red and touching a frozen red dot...
if (type >= 1 && distance <= 12 && dots.get(i).type == 0) {
// We need to freeze this dot!
frozen_red_counter++;
return(true);
}
// If we are non-red and touching a non-red frozen dot...
if (type >= 1 && distance <= 10 && dots.get(i).type >= 1) {
// We need to freeze this dot!
frozen_red_counter++;
return(true);
}
}
}
}
// If we've looked at all the other dots and determined that we are not near a frozen one, we do not need to freeze.
return(false);
}
}
Answers
the problem is how to get rid of the overlapping
http://forum.processing.org/two/discussions/tagged/overlap
@GoToLoop,does this work...i will see ,thanks,anyhow.
still do not know how to do it, can anyone give me some idea?
Your colored (yellow, green) dots do not freeze until a certain number of grey dots have frozen.
Once a certain number of grey dots has frozen, any colored dot that is already overlapping with a grey dot will freeze immediately.
Could you possibly drawn the sort of result you are expecting? Post it here as an image.
i think the result will be like this...
what i do not know is how can i 1.make the colored(yellow,green) dots at least keep some distance with the grey branch (as if repel).? 2.yellow and green stick closely to each other?(which i have done) 3.yellow and green dots look like embeded into the grey branch
do i need to start a new code or change some behaviour of dots so that can achieve this result?
i am thinking about can i....avoid overlap by adjust distance between dots or when it's candidate to be frozen check if it's not overlap with other moving and then change eg. direction
leave the above image, you can make so that...make the grey dots form a river not like branch first..then the colored dots near to it and freeze ....(get rid of overlapping)..
yes, good ,thanks. but how can i do that.
i am trying to make so that. 1. grey dots collide the curve and freeze 2. then the color(green and yellow ) collide and freeze. is there any easier way to do the 1 one. (grey dot can recognise the curve)??