how can i modify only the last value from my array?
in
Programming Questions
•
11 months ago
hi lords,
i try to make a program on which i could create rect of copy() from my image, and i want to modify a value separetely from each other.
I'm using the wrong method, cuz my value is a simple int, but when i try to use an int[] the result is the same, when i modify the value
"longueur" control by the boolean
"agrandir" every img copy rect is modify.
My question is: how i can modify only the "longueur" value for each rect separetely?
////////////////////////////////////////////////////////////////////////////////
int mx, my, nmx, nmy;
int mode;
int[] pos;
int[] posY;
int[] npos;
int[] nposY;
int nombre;
int currentNombre=0;
int currentNombre2=0;
int[] longueur1;
boolean mouse, drag, agrandir;
PImage img;
int longueur;
void setup() {
size(800, 500);
mode = 0;
nombre=330;
pos = new int[nombre];
posY = new int[nombre];
npos = new int[nombre];
nposY = new int[nombre];
img=loadImage("333.jpg");
img.resize(800, 500);
longueur = 50;
longueur1 = new int[nombre];
}
void draw() {
background(255);
frameRate=1;
mx = mouseX;
my = mouseY;
noFill();
if (agrandir) {
for (int i=0; i< currentNombre2; i++) {
longueur1[i]=abs(pos[i]-mouseX);
longueur=abs(pos[i]-mouseX);
}
}
for (int i=0; i< currentNombre2; i++) {
println (i + ": "+npos[i] + ", " + nposY[i] ) ;
}
// paint the stored rects (they are locked)
for (int i=0; i< currentNombre; i++) {
nmx=mx;
if (keyPressed) {
translate(pos[i]-mouseX, posY[i]-mouseY);
copy(img, pos[i], posY[i], longueur, longueur, pos[i]-mouseX, posY[i]-mouseY, longueur, longueur);
}
else {
copy(img, pos[i], posY[i], longueur, longueur, pos[i], posY[i], longueur, longueur);
}
// rect(pos[i], posY[i], longueur, longueur);
//println (i + ": "+pos[i] + ", " + posY[i] ) ;
//println(agrandir);
//haut gauche rect
if (mouseX>pos[i]-5&&mouseX<pos[i]+5&&mouseY>posY[i]-5&&mouseY<posY[i]+5) {
pushStyle();
noFill();
rect(pos[i]-3, posY[i]-3, 6, 6);
popStyle();
if (drag) {
agrandir=true;
}
else {
agrandir=false;
}
}
//haut droit rect
if (mouseX>pos[i]-5+longueur&&mouseX<pos[i]+5+longueur&&mouseY>posY[i]-5&&mouseY<posY[i]+5) {
pushStyle();
noFill();
rect(pos[i]-3+longueur, posY[i]-3, 6, 6);
popStyle();
}
//bas gauche rect
if (mouseX>pos[i]-5&&mouseX<pos[i]+5&&mouseY>posY[i]-5+longueur&&mouseY<posY[i]+5+longueur) {
pushStyle();
noFill();
rect(pos[i]-3, posY[i]-3+longueur, 6, 6);
popStyle();
}
//bas droit rect
if (mouseX>pos[i]-5+longueur&&mouseX<pos[i]+5+longueur&&mouseY>posY[i]-5+longueur&&mouseY<posY[i]+5+longueur) {
pushStyle();
noFill();
rect(pos[i]-3+longueur, posY[i]-3+longueur, 6, 6);
popStyle();
}
// 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;
}
}
else if (mode>50) {
// mode=100;
fill(0);
pushStyle();
noFill();
rect(747, 438, 50, 10);
text("reset", 750, 450);
popStyle();
// store a rect
if (mousePressed&&mouse) {
mouse=!mouse;
// rect(mx, my, 50, 50);
pos[currentNombre]=mouseX;
posY[currentNombre]=mouseY;
currentNombre +=1;
currentNombre2+=1;
}
//reset
if (mousePressed&&mx>747&&mx<747+50&&my>438&&my<438+10) {
background(255);
currentNombre=0;
}
}
if (agrandir) {
for (int i =0;i<currentNombre;i++) {
for (int j=0;j<currentNombre2;j++) {
if (pos[i]-mouseX>0&&posY[i]-mouseY>0) {
// rect(mouseX,mouseY,abs(longueur+(pos[i]-mouseX)),abs(longueur+(posY[i]-mouseY)));
}
}
}
}
}
void mouseDragged() {
mouse=false;
drag=true;
if (agrandir) {
npos[currentNombre2]=mouseX;
nposY[currentNombre2]=mouseY;
}
}
void mouseReleased() {
mouse=true;
if (drag=true) {
drag= false;
}
if (agrandir) {
currentNombre2+=1;
agrandir=false;
}
}
void agrandir() {
}
1