import princeton.introcs.Picture; import java.awt.Color; import java.io.PrintStream; public class Test2F { public static void main(String[] args) { PrintStream out = System.out; Picture tile = new Picture("tile.png"); final int TILE_WIDTH = tile.width(); final int TILE_HEIGHT = tile.height(); final int PIC_WIDTH = Integer.parseInt(args[0]); final int PIC_HEIGHT = Integer.parseInt(args[1]); Picture pic = new Picture(PIC_WIDTH, PIC_HEIGHT); /* If you managed to solve the easier version of the problem, then all you needed to do to complete the full version is to compute the amount to offset the tile in the horizontal and vertical directions. */ // how many pixels are leftover after using whole tiles? final int X_LEFTOVER = PIC_WIDTH % TILE_WIDTH; final int Y_LEFTOVER = PIC_HEIGHT % TILE_HEIGHT; // how much to offset the first tile? int X_OFFSET = TILE_WIDTH - X_LEFTOVER / 2; int Y_OFFSET = TILE_HEIGHT - Y_LEFTOVER / 2; for (int i = 0; i < PIC_WIDTH; i++) { // get the x-position in the tile int x = (i + X_OFFSET) % TILE_WIDTH; for (int j = 0; j < PIC_HEIGHT; j++) { // get the y-position in the tile int y = (j + Y_OFFSET) % TILE_HEIGHT; // get the color in the tile at (x, y) Color col = tile.get(x, y); // set the color in the picture at (i, j) pic.set(i, j, col); } } pic.show(); } }