import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; public final class GenerateBlockTextures { private static final Path OUT = Path.of("src/main/resources/assets/blocodex/textures/block"); private static final int BODY = 0xFFE0D7C6; private static final int BODY_MID = 0xFFCABFAC; private static final int BODY_DARK = 0xFF80776A; private static final int BODY_LIGHT = 0xFFF8F0DD; private static final int OUTLINE = 0xFF2A2723; private static final int BLACK = 0xFF050706; private static final int SCREEN = 0xFF0B2A25; private static final int SCREEN_GLOW = 0xFF5BFFB5; private static final int SLOT = 0xFF191611; private static final int RED = 0xFFC8403C; private static final int GREEN = 0xFF5DC462; private static final int YELLOW = 0xFFE3C34B; private static final int WHITE = 0xFFEAE3D5; private static final int METAL = 0xFF9FA5A2; private GenerateBlockTextures() { } public static void main(String[] args) throws Exception { Files.createDirectories(OUT); write("computer_front.png", front()); write("computer_right.png", right()); write("computer_left.png", left()); write("computer_back.png", back()); write("computer_top.png", top()); write("computer_bottom.png", bottom()); } private static BufferedImage front() { BufferedImage image = base(); rect(image, 2, 2, 12, 10, OUTLINE); rect(image, 3, 3, 11, 9, BLACK); rect(image, 4, 4, 10, 8, SCREEN); set(image, 4, 4, 0xFF17463C); set(image, 9, 7, SCREEN_GLOW); set(image, 8, 7, SCREEN_GLOW); set(image, 5, 5, 0xFF2E836D); rect(image, 2, 11, 10, 13, BODY_LIGHT); line(image, 3, 12, 9, 12, SLOT); set(image, 8, 11, 0xFF6DA6C8); set(image, 9, 11, 0xFF3B657D); rect(image, 12, 11, 14, 13, GREEN); set(image, 12, 11, 0xFFA9F1A7); rect(image, 14, 11, 15, 13, RED); line(image, 3, 14, 7, 14, SLOT); line(image, 9, 14, 13, 14, SLOT); set(image, 2, 14, BODY_DARK); return image; } private static BufferedImage right() { BufferedImage image = base(); rect(image, 2, 2, 14, 14, BODY_MID); line(image, 3, 3, 13, 3, BODY_LIGHT); line(image, 13, 3, 13, 13, BODY_DARK); line(image, 3, 5, 7, 5, BODY_DARK); line(image, 3, 8, 7, 8, BODY_DARK); line(image, 3, 11, 7, 11, BODY_DARK); rca(image, 10, 4, YELLOW); rca(image, 10, 8, WHITE); rca(image, 10, 12, RED); screw(image, 3, 3); screw(image, 3, 12); return image; } private static BufferedImage left() { BufferedImage image = base(); rect(image, 2, 2, 14, 14, BODY_MID); line(image, 3, 3, 13, 3, BODY_LIGHT); line(image, 13, 3, 13, 13, BODY_DARK); line(image, 3, 5, 12, 5, SLOT); line(image, 3, 7, 12, 7, SLOT); line(image, 3, 9, 12, 9, SLOT); line(image, 3, 11, 12, 11, SLOT); set(image, 12, 5, BODY_LIGHT); set(image, 12, 7, BODY_LIGHT); set(image, 12, 9, BODY_LIGHT); set(image, 12, 11, BODY_LIGHT); screw(image, 3, 3); screw(image, 12, 12); return image; } private static BufferedImage back() { BufferedImage image = base(); rect(image, 2, 2, 14, 14, BODY_MID); line(image, 3, 3, 13, 3, BODY_LIGHT); rect(image, 4, 4, 12, 10, OUTLINE); rect(image, 5, 5, 11, 9, BLACK); set(image, 7, 6, METAL); set(image, 9, 6, METAL); set(image, 8, 8, BODY_DARK); line(image, 4, 12, 7, 12, SLOT); line(image, 9, 12, 12, 12, SLOT); line(image, 4, 14, 12, 14, SLOT); screw(image, 3, 3); screw(image, 13, 3); return image; } private static BufferedImage top() { BufferedImage image = base(); rect(image, 2, 2, 14, 14, BODY); line(image, 3, 3, 13, 3, BODY_LIGHT); line(image, 3, 3, 3, 13, BODY_LIGHT); line(image, 3, 13, 13, 13, BODY_DARK); line(image, 13, 3, 13, 13, BODY_DARK); line(image, 5, 6, 11, 6, SLOT); line(image, 5, 8, 11, 8, SLOT); line(image, 5, 10, 11, 10, SLOT); set(image, 12, 12, BODY_LIGHT); return image; } private static BufferedImage bottom() { BufferedImage image = base(); rect(image, 2, 2, 14, 14, BODY_DARK); rect(image, 4, 4, 7, 7, OUTLINE); rect(image, 10, 4, 13, 7, OUTLINE); rect(image, 4, 10, 7, 13, OUTLINE); rect(image, 10, 10, 13, 13, OUTLINE); line(image, 7, 8, 9, 8, SLOT); line(image, 7, 9, 9, 9, SLOT); return image; } private static BufferedImage base() { BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); rect(image, 0, 0, 16, 16, BODY); line(image, 0, 0, 15, 0, OUTLINE); line(image, 0, 0, 0, 15, OUTLINE); line(image, 0, 15, 15, 15, OUTLINE); line(image, 15, 0, 15, 15, OUTLINE); line(image, 1, 1, 14, 1, BODY_LIGHT); line(image, 1, 1, 1, 14, BODY_LIGHT); line(image, 1, 14, 14, 14, BODY_DARK); line(image, 14, 1, 14, 14, BODY_DARK); return image; } private static void rca(BufferedImage image, int x, int y, int color) { set(image, x, y - 1, OUTLINE); set(image, x - 1, y, OUTLINE); set(image, x, y, color); set(image, x + 1, y, OUTLINE); set(image, x, y + 1, OUTLINE); set(image, x - 1, y - 1, METAL); } private static void screw(BufferedImage image, int x, int y) { set(image, x, y, OUTLINE); set(image, x + 1, y, METAL); set(image, x, y + 1, METAL); set(image, x + 1, y + 1, BODY_DARK); } private static void rect(BufferedImage image, int x1, int y1, int x2, int y2, int color) { for (int y = Math.max(0, y1); y < Math.min(image.getHeight(), y2); y++) { for (int x = Math.max(0, x1); x < Math.min(image.getWidth(), x2); x++) { image.setRGB(x, y, color); } } } private static void line(BufferedImage image, int x1, int y1, int x2, int y2, int color) { if (x1 == x2) { rect(image, x1, Math.min(y1, y2), x1 + 1, Math.max(y1, y2) + 1, color); return; } if (y1 == y2) { rect(image, Math.min(x1, x2), y1, Math.max(x1, x2) + 1, y1 + 1, color); } } private static void set(BufferedImage image, int x, int y, int color) { if (x >= 0 && y >= 0 && x < image.getWidth() && y < image.getHeight()) { image.setRGB(x, y, color); } } private static void write(String name, BufferedImage image) throws IOException { ImageIO.write(image, "png", OUT.resolve(name).toFile()); } }