diff --git a/clue2.png b/clue2.png new file mode 100644 index 0000000..74638a2 Binary files /dev/null and b/clue2.png differ diff --git a/clue2_output.png b/clue2_output.png new file mode 100644 index 0000000..9a270ee Binary files /dev/null and b/clue2_output.png differ diff --git a/src/clue0/Main.java b/src/clue0/Main.java index 3e2aa32..c526241 100644 --- a/src/clue0/Main.java +++ b/src/clue0/Main.java @@ -12,6 +12,7 @@ public class Main { try { FileInputStream stream = new FileInputStream("clue0.png"); BufferedImage image = ImageIO.read(stream); + stream.close(); int width = image.getWidth(); int height = image.getHeight(); int[] raw = image.getRGB(0, 0, width, height, null, 0, width); @@ -47,14 +48,12 @@ public class Main { image.setRGB(0, 0, width, height, output, 0, width); ImageIO.write(image, "png", new File("clue0_output.png")); - - stream.close(); } catch (IOException e) { e.printStackTrace(); } } - public static int rotate(int index, int shift, int mod) { + private static int rotate(int index, int shift, int mod) { return (((index % mod + shift % mod) % mod) + mod) % mod; } } diff --git a/src/clue1/Main.java b/src/clue1/Main.java index efedc31..72a120a 100644 --- a/src/clue1/Main.java +++ b/src/clue1/Main.java @@ -12,6 +12,7 @@ public class Main { try { FileInputStream stream = new FileInputStream("clue1.png"); BufferedImage image = ImageIO.read(stream); + stream.close(); int width = image.getWidth(); int height = image.getHeight(); int[] raw = image.getRGB(0, 0, width, height, null, 0, width); diff --git a/src/clue2/Main.java b/src/clue2/Main.java new file mode 100644 index 0000000..778253a --- /dev/null +++ b/src/clue2/Main.java @@ -0,0 +1,54 @@ +package clue2; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class Main { + + public static void main(String[] args) { + try { + FileInputStream stream = new FileInputStream("clue2.png"); + BufferedImage image = ImageIO.read(stream); + stream.close(); + int width = image.getWidth(); + int height = image.getHeight(); + int[] raw = image.getRGB(0, 0, width, height, null, 0, width); + int[] output = new int[width * height]; + + int x = 0; + int y = 0; + int dir = 1; + for (int i = 0; i < width * height; ++i) { + output[i] = raw[x + y * width]; + if (dir == -1 && y == height - 1) { + ++x; + dir = -dir; + } + else if (dir == -1 && x == 0) { + ++y; + dir = -dir; + } + else if (dir == 1 && x == width - 1) { + ++y; + dir = -dir; + } + else if (dir == 1 && y == 0) { + ++x; + dir = -dir; + } + else { + x += dir; + y -= dir; + } + } + + image.setRGB(0, 0, width, height, output, 0, width); + ImageIO.write(image, "png", new File("clue2_output.png")); + } catch (IOException e) { + e.printStackTrace(); + } + } +}