import javax.swing.*;
import java.awt.*;
public class Render {
record vec3d(float x, float y, float z) {
public vec2d project(final float FIELD_OF_VIEW, final float PROJECTION_CENTER_X, final float PROJECTION_CENTER_Y) {
float scaleProjected = FIELD_OF_VIEW / (FIELD_OF_VIEW + z);
float xProjected = (x * scaleProjected) + PROJECTION_CENTER_X;
float yProjected = (y * scaleProjected) + PROJECTION_CENTER_Y;
return new vec2d(xProjected, yProjected);
}
}
record vec2d(float x, float y) {
}
private static Color getColor(final int index, final int level) {
float a = (level + 1) / 5f;
return switch (index) {
case 0 -> new Color(1f, 0f, 0f, a);
case 1 -> new Color(1f, 1f, 0f, a);
case 2 -> new Color(0f, 0f, 1f, a);
default -> null;
};
}
public Render(final int[][][] solution, final int maxCandidates) {
int widthAndHeight = 800;
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(widthAndHeight, widthAndHeight);
frame.add(new Canvas() {
@Override
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
int len = 95;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
int x = k * len;
int y = j * len;
int z = i * len;
float centerX = (x + len) / 2f;
float centerY = (y + len) / 2f;
vec2d v1 = new vec3d(x, y, z).project((float) widthAndHeight, centerX, centerY);
vec2d v2 = new vec3d(x + len - 1, y, z).project((float) widthAndHeight, centerX, centerY);
vec2d v3 = new vec3d(x + len - 1, y + len - 1, z).project((float) widthAndHeight, centerX, centerY);
vec2d v4 = new vec3d(x, y + len - 1, z).project((float) widthAndHeight, centerX, centerY);
Color color = getColor(solution[i][j][k] / maxCandidates, i);
g.setColor(color);
g.drawLine((int) v1.x, (int) v1.y, (int) v2.x, (int) v2.y);
g.drawLine((int) v2.x, (int) v2.y, (int) v3.x, (int) v3.y);
g.drawLine((int) v3.x, (int) v3.y, (int) v4.x, (int) v4.y);
g.drawLine((int) v4.x, (int) v4.y, (int) v1.x, (int) v1.y);
}
}
}
}
});
frame.setVisible(true);
}
public static void main(final String[] args) {
new Render(new int[][][]{
{{13, 6, 6, 6, 6}, {7, 6, 6, 6, 6}, {7, 0, 0, 1, 1}, {7, 0, 0, 1, 1}, {7, 0, 0, 8, 8}},
{{9, 9, 2, 2, 2}, {7, 14, 2, 2, 2}, {7, 0, 0, 1, 1}, {7, 0, 0, 1, 1}, {7, 0, 0, 8, 8}},
{{9, 9, 2, 2, 2}, {3, 3, 2, 2, 2}, {3, 3, 12, 1, 1}, {4, 4, 4, 1, 1}, {4, 4, 4, 8, 8}},
{{9, 9, 5, 5, 10}, {3, 3, 5, 5, 10}, {3, 3, 5, 5, 10}, {4, 4, 4, 15, 10}, {4, 4, 4, 8, 8}},
{{9, 9, 5, 5, 10}, {3, 3, 5, 5, 10}, {3, 3, 5, 5, 10}, {11, 11, 11, 11, 10}, {11, 11, 11, 11, 16}},
}, 6);
}
}