Basically I have a 2D array that has binary grey colors stored in them from 0-25
ID: 3637671 • Letter: B
Question
Basically I have a 2D array that has binary grey colors stored in them from 0-255. I would go through the array and if it was set at 255 I would want to change that color to a random color between 50-250. That is what this for loop would do. But once it calls the doRecursion method I need for that method to do a recursive call to check north,west,south,and east of the current position and change it to a random color if it was set at 255. I'm having problems with it going out of bounds and can't seem to get an algorithm to work. Seems like it is going in an infinite loop with the recursion.
for(int i = 0;i<img.length;++i){
for(int j = 0;j<img[0].length;++j){
if(binaryImg[i][j] == 255){
startRecursion(binary, i,j,50+r.nextInt(200));
}
}
}
private static void startRecursion(short[][] binary, int row, int col, int color)
{
if(binaryImg[row][col] == 255)
{
binaryImg[row][col] = (short)color;
}
startRecursion(binary, row-1,col,color);
startRecursion(binary, row+1,col,color);
startRecursion(binary, row,col-1,color);
startRecursion(binary, row,col+1,color);
}
Explanation / Answer
for(int i = 0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.