void setup() {
// size(8560/5,5398/5);
size(9525/5,5715/5);
background(255);
// 3.75" x 2.25
// 3.5" x 2
rectMode(CORNER);
// Business card bleed:
// fill(255,0,0);
// rect(map((3.75-3.5)/2,0,3.75,0,width) , map((2.25-2)/2,0,2.25,0,height), map(3.5,0,3.75,0,width) , map(2,0,2.25,0,height));
float xmin = map((3.75-3.5)/2,0,3.75,0,width) , xmax = xmin + map(3.5,0,3.75,0,width) - width/40, ymin = map((2.25-2)/2,0,2.25,0,height), ymax = height - ymin - height/40;
for(int row = -1; row < 8; row++) {
for(int col = -1; col < 16; col++) {
int number = row*16 + col;
float w = (xmax-xmin) / (16+1), h = (ymax-ymin) / (8+1);
float x = xmin + (col+1) * w, y = ymin + (row+1) * h;
rectMode(CORNER);
if(row >= 0 && col >= 0) {
fill(getColor(number));
rect(x,y,w,h);
}
float cx = x + w/2, cy = y + h/2;
char cHead = toHex(col);
char rHead = toHex(row);
String val = "";
if(row < 0 && col >= 0 || row >= 0 && col < 0) {
if(row < 0) val += cHead;
if(col < 0) val += rHead;
}else if(row >= 0 && col >= 0){
val += toVal(number);
}
if( row < 0 && col < 0) continue;
fill(0);
textFont(createFont("Courier Bold",5));
if(row >= 0 && col >= 0 && (number < 32 || number == 127)) textSize(width/40);
else textSize(width/30);
textAlign(CENTER,CENTER);
text(val,cx,y + h * 2 / 3);
if( row < 0 || col < 0) continue;
fill(150,0,0);
textFont(createFont("Courier Bold",5));
textSize(width/50);
// textAlign(LEFT,TOP);
// text(number,x,y);
textAlign(CENTER,CENTER);
text(number,cx,y + h * 1 / 4);
}
}
}
color getColor(int i) {
if((i/10)%2==0) {
return color(200);
}
return color(255);
}
String toVal(int i) {
String[] vals = "NUL,SOH,STX,ETX,EOT,ENQ,ACK,BEL,BS,HT,LF,VT,FF,CR,SO,SI,DLE,DC1,DC2,DC3,DC4,NAK,SYN,ETB,CAN,EM,SUB,ESC,FS,GS,RS,US,SP".split(",");
if(i==127) return "DEL";
if(i <= 32) return vals[i];
return ""+(char)i;
}
char toHex(int i) {
return i < 10 ? (char)(i+(int)'0') : (char)(i-10+(int)'A');
}