having a problem with booleans
in
Programming Questions
•
5 months ago
Hi there.
My purpose is to obtain a random number when a condition of proximity is fulfilled. But only once, and maintain that value while the condition is true. Then, when the condition becomes not true and after that, true again, make the same operation, I mean, obtain another random value.
But as a code say more than 1000 explanation... here is it:
- float dM, dP, cdX, cdY, posX, posY, pSX, pSY, timer, dPiX, dPiY;
- float X;
- float Y;
- float s=10;
- float fDX;
- float fDY;
- int numRep= 10;
- float[] repX=new float[numRep];
- float[] repY=new float[numRep];
- boolean act1;
- boolean act2;
- void setup() {
- size(400, 400);
- background(255);
- pSX=PI/2;
- pSY=PI/2;
- dPiX= random(70, 140);
- dPiY= random(70, 140);
- for (int i=0; i<repX.length; i++) {
- repX[i]= random(0, width);
- repY[i]= random(0, height);
- act2=false;
- // println("los valores de X son: "+repX[i]+" los valores de Y son: "+repX[i]);
- }
- }
- void draw() {
- background(255);
- act1= false;
- X+=sin(pSX);
- Y+=sin(pSY);
- dM= 40;
- posX= X;
- posY= Y;
- strokeWeight(5);
- stroke(0);
- point(posX, posY);
- // timer+=1;
- for (int i=0; i<repX.length; i++) {
- dP=dist(posX, posY, repX[i], repY[i]);
- stroke(0, 50);
- noFill();
- ellipse(repX[i], repY[i], dM*2, dM*2);
- if (dP<dM) {
- line(posX, posY, repX[i], repY[i]);
- act1= true;
- pSX+= PI/dPiX;
- pSY+= PI/dPiY;
- if (act1==true&&act2==false) {
- dPiX= random(140, 200);
- dPiY= random(140, 200);
- act2=true;
- println(dPiX+" y "+dPiY);
- }
- }else{
- act2= false;
- }
- }
- if (posX>width||posX<0) {
- pSX*=-1;
- }
- if (posY>height||posY<0) {
- pSY*=-1;
- }
- }
Is simple, I think, but...
I want to use the condition of the booleans to control the only one executed random.
Thanks.
1