Completed clue2
This commit is contained in:
parent
66cf575ca2
commit
46ce42a2d5
5 changed files with 57 additions and 3 deletions
BIN
clue2.png
Normal file
BIN
clue2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 MiB |
BIN
clue2_output.png
Normal file
BIN
clue2_output.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
|
@ -12,6 +12,7 @@ public class Main {
|
||||||
try {
|
try {
|
||||||
FileInputStream stream = new FileInputStream("clue0.png");
|
FileInputStream stream = new FileInputStream("clue0.png");
|
||||||
BufferedImage image = ImageIO.read(stream);
|
BufferedImage image = ImageIO.read(stream);
|
||||||
|
stream.close();
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
int height = image.getHeight();
|
int height = image.getHeight();
|
||||||
int[] raw = image.getRGB(0, 0, width, height, null, 0, width);
|
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);
|
image.setRGB(0, 0, width, height, output, 0, width);
|
||||||
ImageIO.write(image, "png", new File("clue0_output.png"));
|
ImageIO.write(image, "png", new File("clue0_output.png"));
|
||||||
|
|
||||||
stream.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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;
|
return (((index % mod + shift % mod) % mod) + mod) % mod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ public class Main {
|
||||||
try {
|
try {
|
||||||
FileInputStream stream = new FileInputStream("clue1.png");
|
FileInputStream stream = new FileInputStream("clue1.png");
|
||||||
BufferedImage image = ImageIO.read(stream);
|
BufferedImage image = ImageIO.read(stream);
|
||||||
|
stream.close();
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
int height = image.getHeight();
|
int height = image.getHeight();
|
||||||
int[] raw = image.getRGB(0, 0, width, height, null, 0, width);
|
int[] raw = image.getRGB(0, 0, width, height, null, 0, width);
|
||||||
|
|
54
src/clue2/Main.java
Normal file
54
src/clue2/Main.java
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue