Skip to content

Instantly share code, notes, and snippets.

@Matsemann
Created October 1, 2017 12:54
Show Gist options
  • Save Matsemann/572c0e3901f70b283354597b8ccb9ec5 to your computer and use it in GitHub Desktop.
Save Matsemann/572c0e3901f70b283354597b8ccb9ec5 to your computer and use it in GitHub Desktop.
Telescope generator
public static int[][] blur(int[][] board, int blurSize) {
int radius = (blurSize - 1) / 2;
int[][] blurred = new int[board.length][board[0].length];
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
int sum = 0;
for (int y = i - radius; y <= i + radius; y++) {
for (int x = j - radius; x <= j + radius; x++) {
sum += getValue(board, x, y);
}
}
blurred[i][j] = sum / (blurSize * blurSize);
}
}
return blurred;
}
private static int getValue(int[][] board, int x, int y) {
if ( y < 0 || y > board.length - 1) {
return 0;
} else if (x < 0 || x > board[y].length - 1 ) {
return 0;
} else {
return board[y][x];
}
}
private void printGrid(int[][] grid) {
for (int[] ints : grid) {
for (int anInt : ints) {
System.out.print(pad(Integer.toString(anInt, 16)) + " ");
}
System.out.println();
}
}
private String pad(String nr) {
return "0000".substring(nr.length()) + nr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment