Created
November 13, 2015 13:20
-
-
Save yoggy/560ef54dcf5fcf15040b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int w = 50; | |
| boolean [][] matrix = new boolean[8][8]; | |
| void setup() { | |
| size(400, 400); | |
| } | |
| void draw() { | |
| background(0, 0, 0); | |
| stroke(0, 255, 0); | |
| for (int y = 0; y < 8; ++y) { | |
| for (int x = 0; x < 8; ++x) { | |
| if (matrix[y][x] == true) { | |
| fill(0, 255, 0); | |
| } else { | |
| fill(0, 0, 0); | |
| } | |
| rect(x * w, y * w, w, w); | |
| } | |
| } | |
| } | |
| void mousePressed() { | |
| int x = (int)(mouseX / w); | |
| int y = (int)(mouseY / w); | |
| matrix[y][x] = !matrix[y][x]; | |
| } | |
| void keyPressed() { | |
| if (key == 0x20) { | |
| dump(); | |
| } | |
| else if (key == 'c') { | |
| clear(); | |
| } | |
| } | |
| void dump() { | |
| for (int y = 0; y < 8; ++y) { | |
| String str = "B"; | |
| for (int x = 0; x < 8; ++x) { | |
| if (matrix[y][x] == true) { | |
| str += "1"; | |
| } else { | |
| str += "0"; | |
| } | |
| } | |
| print(str + ","); | |
| } | |
| println(); | |
| } | |
| void clear() { | |
| for (int y = 0; y < 8; ++y) { | |
| for (int x = 0; x < 8; ++x) { | |
| matrix[y][x] = false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment