Skip to content

Instantly share code, notes, and snippets.

@smcl
Created November 22, 2015 02:32
Show Gist options
  • Save smcl/bd6a1728aff90ab11133 to your computer and use it in GitHub Desktop.
Save smcl/bd6a1728aff90ab11133 to your computer and use it in GitHub Desktop.
int boxSize = 50;
boolean bitmap[][] = new boolean[3][8];
void setup() {
size(150, 400);
background(225, 219, 203);
// horizontal lines
for (int i=1; i<3; i++) {
line(i * boxSize, 0, i * boxSize, height);
}
// vertical lines
for (int i=1; i<8; i++) {
line(0, i*boxSize, width, i*boxSize);
}
for (int x=0; x<bitmap.length; x++) {
for (int y=0; y<bitmap[x].length; y++) {
bitmap[x][y] = false;
}
}
}
void draw() {
for (int x=0; x<bitmap.length; x++) {
for (int y=0; y<bitmap[x].length; y++) {
if (bitmap[x][y]) {
fill(88, 83, 85);
} else {
fill(225, 219, 203);
}
rect(x * boxSize, y * boxSize, boxSize, boxSize);
}
}
}
void mouseClicked() {
toggleBox(mouseX/boxSize, mouseY/boxSize);
}
void keyPressed() {
String[] character = new String[3];
for (int x=0; x<bitmap.length; x++) {
byte b = 0x0;
for (int y=0; y<bitmap[x].length; y++) {
if (bitmap[x][y]) {
b |= ((byte)1 << y);
}
}
character[x] = "0x" + hex(b);
}
println("\t" + join(character, ","));
}
void toggleBox(int x, int y) {
bitmap[x][y] = !bitmap[x][y];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment