"Stretching" a 2D Array in Java -
i need "stretch" 2d array filled chars of ' ', , '*'. stretching based on "int factor" passed in through method.
current image looks this:
***** * * * *** * * * * ***** need this: (assuming factor 2)
********** ** ** ** ****** ** ** ** ** ********** i started write loop have no idea if i'm on right track or not, struggling one.
edit: i've gotten array col length stretch, need image stretch now.
public void stretch ( int factor ) { factor = 2; char[][] pixelstretch = new char[pixels.length][pixels[0].length * factor]; (int row = 0; row < pixels.length; row++) { (int col = 0; col < pixels[0].length; col+= factor) { for(int i=0; i<factor; i++) { pixelstretch[row][col+i] = pixels[row][col]; } } } pixels = pixelstretch; } image printed this:
**** ** ** ****
you're there. have do, change code you're copying pixels[row][column] new array factor times
// make sure factor not 0 before (int col = 0; col < pixels[0].length; col++) { for(int i=0; i<factor; i++) { pixelstretch[row][col*factor+i] = pixels[row][col]; } }
Comments
Post a Comment