How i can lock the value of a dynamic value like mouseX in an array?
in
Programming Questions
•
11 months ago
Hi,
I want to lock a value in my array , named pos. The array will capture the 2D position on the screen.
If i mousePress i create a rect in the X,Y mouse position, but i want to catch this position on a constant value in the array pos[].
I don't understand, because my array dont get any informations, all values are zero egual...
Could you explain me why and how i can get the mouse X pos locked in my array?
Kind regards
-----------------------------
int mx,my,nmx,nmy;
int mode;
int[] pos;
int nombre;
void setup(){
size(800,500);
mode = 0;
nombre=0;
}
void draw(){
pos = new int[nombre];
frameRate=1;
println(pos);
mx = mouseX;
my = mouseY;
for(int i=0; i< nombre; i++){
nmx=mx;
pos[i]=nmx;}
//mode rect
if(mode<50){
background(75);
fill(255); stroke(0);text("you need to click on the rect to begin",50,50);
rect(50,150,80,80);
if(mousePressed&&mx>50&&mx<50+80&&my<150+80&&my>150){
background(255);mode=100;}
}
if(mode>50){mode=100;
fill(0);
pushStyle();
noFill();
rect(747,438,50,10);
text("reset",750,450);
popStyle();
if(mousePressed){rect(mx,my,50,50);nombre+=1;}
if(mousePressed&&mx>747&&mx<747+50&&my>438&&my<438+10){background(255);nombre=0;
}
}
}
1