We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi guys,
A few days ago you helped me on this topic: Processing 2.0 Random without duplicate as interger is it possible?
you send in your code to shuffle values in an array. could you help me implement it in this.
greetings,
Ben
int value=0;
int abc = 0;
int cols = 10;
int rows = 10;
int[][] myArray = new int[cols][rows];
void setup() {
size(550, 550);
}
void draw() {
while (abc < 100) {
background(255, 0, 0);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
fill(255);
myArray[i][j] = abc++;
rect(25+50*i, 50*j, 25, 25);
rect(width/3,height/18*17,width/3,height/18); // shuffle value
fill(0);
text(i+","+j, 30+ 50*j, 20+ 50*i);
text("shuffle",width/2 -20,height/18*17.7);
text(myArray[i][j], 30+ 50*j, 40+ 50*i);
}
}
}
}
void mouseReleased() {
if (value == 0 && mouseX > width/3 && mouseX < width/3 + width/3 && mouseY > height/18*17 && mouseY < height/18*17 + height/18){
//Shuffle Action
}
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
if (value == 0 && mouseX > 25+(50*i) && mouseX < 25+(50*i) +25 && mouseY > 50*j && mouseY < (50*j)+25) {
value = 255;
println("1st value"+ j);
println("2nd value"+ i );
fill(0, 255, 0);
rect(25+(50*i), 50*j, 25, 25);
int getal = myArray[j][i] ;
println("number: "+ getal);
if (j == 3 && i == 5) {
println("oki!");
}
rect(25+(50*i), 50*j, 25, 25);
}
else {
value = 0;
}
}
}
}
Answers
I have modified your code the array is initialised in setup and drawn in draw. I have removed the while(abc... loop because it is not needed.
The shuffleArray method will work with any 2D integer array.
That's a perfect solution many thanks!!
An alternative approach for shuffleArray() function: ;))