int cellWidth = 10, cellHeight = 10; int maxCols = 11, maxRows = 128; int white = 255, black = 0; /** * Converts a natural binary 32 bit value to Gray code. * @param natural The natural binary value to convert. * @return The Gray code equivalent value. */ int encodeGray(int natural) { return natural ^ natural >>> 1; } void setup() { size(maxRows * cellWidth, maxCols * cellHeight); } void draw() { background(white); for (int row = 0; row < maxRows; row++) { drawCell(0, row, 0); drawCell(maxCols - 1, row, 0); int temp = encodeGray(row); for(int bit = 0; bit < 8; bit++) { // if the bit is set, use black, otherwise use white. int fill = (temp & 1) != 0 ? black : white; temp = temp >> 1; drawCell(maxCols - bit - 3, row, fill); } } } void drawCell(int x, int y, int fill) { fill(fill); noStroke(); rect(y * cellWidth, x * cellWidth, cellHeight, cellWidth); }