int rectSize = 25; int x = 0, y = 0; //x and y offsets int[] buttons = new int[2]; boolean[][] buttonsPressed = new boolean[8][8]; boolean[][] buttonsOver = new boolean[8][8]; boolean[][][][] buttonsOn = new boolean[8][8][7][7]; void setup() { size(500,500); clearScreen(); } void loop() { check(); } void check() { for (int i=0; i<8; i++) { for (int j=0; j<8; j++) { if (overRect(20+(25*i),20+(j*25),25,25)) { set(20+(i*25)+i, 20+(j*25)+j, 0xFFFFFF, 25); buttonsOver[i][j] = true; } else { set(20+(i*25)+i, 20+(j*25)+j, 0x000000, 25); buttonsOver[i][j] = false; } } } } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } void mousePressed() { for (int i=0; i<8; i++) { for (int j=0; j<8; j++) { if (buttonsOver[i][j]) { if (buttonsOn[i][j][x/26][y/26]) { set(300+(i*3)+x, 100+(j*3)+y, 0x757575, 3); buttonsOn[i][j][x/26][y/26] = false; } else { set(300+(i*3)+x, 100+(j*3)+y, 0x000000, 3); buttonsOn[i][j][x/26][y/26] = true; } } } } if (overRect(90,280,60,30))//reset button { clearScreen(); } if (overRect(190,280,50,30))//advance left button { if (x > 0) { x -= 26; } else { y -= 26; x = 156; } } if (overRect(250,280,50,30))//advance right button { if (x < 156) { x += 26; } else { if (y < 156) { x = 0; y += 26; } } } if (overRect(140,330,75,30))//encode button { int[] colors = new int[4]; for (int i=0; i<7; i++) { for (int j=0; j<7; j++) { for (int k=0; k<4; k++) { byte[] bitCode = {0,0,0,0}; for (int l=0; l<8; k++) { if(buttonsOn[k][l][i][j]) { bitCode [l] = 1; } else { bitCode [l] = 0; } } colors[k] = byteToInt(bitCode); println(colors[k]); } } } } delay(10); } void set(int x, int y, int myColor, int howBig) { for (int k = 0; k<(howBig); k++) { for (int l = 0; l<(howBig); l++) { set(x+k,y+l,myColor); } } } void clearScreen() { stroke(0x757575); background(0x757575); fill(0,0,0); for (int i=0; i<8; i++) { for (int j=0; j<8; j++) { set(20+(i*25)+i, 20+(j*25)+j, 0x000000, 25); } } for (int i=0; i<8; i+=1) { for (int j=0; j<8; j+=1) { buttonsPressed[i][j] = false; } } BFont metaBold; BFont times = loadFont("times.vlw"); textFont(times, 36); text("reset", 100, 300); text("<<", 204, 304); text(">>", 264, 304); text("encode", 150, 350); noFill(); stroke(0x000000); rect(90,280,60,30); rect(190,280,50,30); rect(250,280,50,30); rect(140,330,75,30); x = y = 0; } // [toxi040304] Targa bitmap loader for 24/32bit RGB(A) BImage loadTarga(String file) { // load image file as byte array byte[] buffer=loadBytes(file); // check if it's a TGA and has 8bits/colour channel if (buffer[2] == 2 && buffer[17] == 8) { // get image dimensions int w=(b2i(buffer[13])<<8) + b2i(buffer[12]); int h=(b2i(buffer[15])<<8) + b2i(buffer[14]); // check if image has alpha boolean hasAlpha=(buffer[16] == 32); // setup new image object BImage img=new BImage(w,h); img.format=(hasAlpha ? RGBA : RGB); // targa's are written upside down, so we need to parse it in reverse int index = (h-1) * w; // actual bitmap data starts at byte 18 int offset=18; // read out line by line for (int y = h-1; y >= 0; y--) { for (int x = 0; x < w; x++) { img.pixels[index + x] = b2i(buffer[offset++]) | b2i(buffer[offset++])<<8 | b2i(buffer[offset++])<<16; // set alpha based on alpha data or revert to 100% (if there's only a 24bit image) if (hasAlpha) img.pixels[index + x]|=b2i(buffer[offset++])<<24; else img.pixels[index + x]|=0xff000000; } index -= w; } return img; } println("loadTarga(): wrong image format"); return null; } // byte to integer conversion int b2i(byte b) { return (int)(b<0 ? 256+b : b); } int byteToInt(byte[] b) { int number = 0; for (int i=0; i < b.length; i++) { if (b[i] == 1) { number += (2^i); } } return number; }