Comment/label generator for the game "Human Resource Machine"
October 21, 2015 ยท View on GitHub
import java.util.Arrays; import java.util.Base64; import java.util.zip.Deflater;
public class LabelGen {
public static void main(String[] args) { // 1028 bytes final byte[] data = new byte[1028];
// we're going to draw 15 lines
final int n = 15;
// first 4 bytes is the number of instructions, little endian (max is 256)
// dot is 2 instructions: position of the dot, "end-of-line" indicator (all zero coordinates)
// line is 3 instructions: position of line start, position of line end, "end-of-line" indicator
// etc...
// top left coordinate is (1, 1)
// top right: (1, 65535)
// bottom left: (65535, 1)
// bottom right: (65535, 65535)
data[0] = n * 3;
// if length > 256 the drawing will be replaced with a single dot in the middle of the canvas
data[1] = 0;
data[2] = 0;
data[3] = 0;
int offset = 4;
for (int i = 0; i < n; i++) {
int x = 0x1000 * (i + 1) + 0xff;
int y1 = 0x0001;
int y2 = 0xffff;
// line start: x coordinate, little endian
data[offset + 12 * i + 0] = (byte) (x & 0xff);
data[offset + 12 * i + 1] = (byte) ((x >> 8) & 0xff);
// line start: y coordinate, little endian
data[offset + 12 * i + 2] = (byte) (y1 & 0xff);
data[offset + 12 * i + 3] = (byte) (y1 >> 8 & 0xff);
// line end: x coordinate, little endian
data[offset + 12 * i + 4] = (byte) (x & 0xff);
data[offset + 12 * i + 5] = (byte) ((x >> 8) & 0xff);
// line end: y coordinate, little endian
data[offset + 12 * i + 6] = (byte) (y2 & 0xff);
data[offset + 12 * i + 7] = (byte) (y2 >> 8 & 0xff);
// 8-11 -> all zero: "end-of-line"
}
// deflate the data
final Deflater deflater = new Deflater();
deflater.setInput(data);
deflater.finish();
final byte[] comp = new byte[1024];
final int len = deflater.deflate(comp);
// base64 the stuff we actually need
final byte[] out = Arrays.copyOfRange(comp, 0, len);
final Base64.Encoder encoder = Base64.getMimeEncoder(80, new byte[]{'\r', '\n'});
final String encoded = encoder.encodeToString(out);
// crop the padding and append a semicolon
System.out.println(encoded.replaceFirst("=+$", "") + ";");
}
}