# Particles and if/else statements

Hi!
I am creating an interaction and I need to say “if all 8 particles are inside this circle, then change the opacity of the circle from 0 to 100.”

My code is here: https://github.com/evejweinberg/SFPC/tree/master/RuleTwo/src
Image ref attached! I’ve got the circle’s opacity holding at 50% right now, just as a placeholder What problem(s) are you running into right now, specifically?

I’m a super beginner and I just don’t know what syntax to use, to write this if/else concept, and then where to put it. I’m assuming it put it in the draw function, and maybe a separate if/else statement of each circle?

In my draw function is the code pasted below. I have 7 circles total, but i’ve pasted the code for one of them below. I have a variable ‘opacityPressed’ that I can use in the if/else statement.

``````//---------------draw the circle and outer ring of circle----------------------
ofSetColor(243,167,153); //pink
ofSetColor(243,167,153,opacityPressed);

//---------------springs and particles----------------
ofSetColor(brown);
for (int i = 0; i < particles.size(); i++){
particles[i].draw();
}

for (int i = 0; i < springs.size(); i++){
springs[i].draw();
}

//this is where I think I should put the if/else.``````

you need a variable to represent the circle’s position (say an ofPoint called circlePos) and its radius (say float radius…), then you could do:

``````bool bAnyNotInMe = false;
for (int i = 0; i < particles.size(); i++){
if (  (circlePos - particles[i].pos).length() > radius){
bAnyNotInMe = true;
}
}

if (bAnyNotInMe == false){  // ok all particles are inside:
// do something
} else {
// do something else
}
``````

this is just for one circle, but you can get the idea… we are trying to see if any particles are not in the circle, and that gives us a true / false if all are in the circle.