SHOW:
|
|
- or go back to the newest paste.
| 1 | PImage img; | |
| 2 | ArrayList<Square> squares = new ArrayList<Square>(); | |
| 3 | - | int min = 64; //min size of the square |
| 3 | + | int min = 8; //min size of the square |
| 4 | int index = 0; | |
| 5 | ||
| 6 | void setup() {
| |
| 7 | img = loadImage("http://a4.mzstatic.com/us/r30/Purple/05/81/e6/mzm.kcjwvjip.jpg");
| |
| 8 | size(img.width, img.height); | |
| 9 | background(0); | |
| 10 | cuarto(0, 0, img.width); //recursion | |
| 11 | } | |
| 12 | ||
| 13 | void draw() {
| |
| 14 | ||
| 15 | //stroke(255, 0, 0); | |
| 16 | noStroke(); | |
| 17 | ||
| 18 | if (index < squares.size()) {
| |
| 19 | squares.get(index).draw(); | |
| 20 | index++; | |
| 21 | } | |
| 22 | ||
| 23 | } | |
| 24 | ||
| 25 | void cuarto(int x, int y, int tam) {
| |
| 26 | if (tam >= min) {
| |
| 27 | squares.add(new Square(x, y, tam, img.pixels[x+tam/2 + (y+tam/2)*img.width])); | |
| 28 | cuarto(x, y, tam/2); | |
| 29 | cuarto(x+tam/2, y, tam/2); | |
| 30 | cuarto(x, y+tam/2, tam/2); | |
| 31 | cuarto(x+tam/2, y+tam/2, tam/2); | |
| 32 | } | |
| 33 | } | |
| 34 | ||
| 35 | class Square {
| |
| 36 | int x, y; | |
| 37 | int tam; | |
| 38 | color c; | |
| 39 | ||
| 40 | Square(int _x, int _y, int _tam, color _c) {
| |
| 41 | x = _x; | |
| 42 | y = _y; | |
| 43 | tam = _tam; | |
| 44 | c = _c; | |
| 45 | } | |
| 46 | ||
| 47 | void draw() {
| |
| 48 | fill(c); | |
| 49 | rect(x, y, tam, tam); | |
| 50 | } | |
| 51 | } | |
| 52 | ||
| 53 | void keyPressed() {
| |
| 54 | if (key == '-') {
| |
| 55 | if (min > 2) {
| |
| 56 | min = min/2; | |
| 57 | } | |
| 58 | } | |
| 59 | if (key == '+') {
| |
| 60 | min = min*2; | |
| 61 | } | |
| 62 | println(key+"..."+min); //min size of the square | |
| 63 | ||
| 64 | background(0); | |
| 65 | squares = new ArrayList<Square>(); | |
| 66 | cuarto(0, 0, img.width); | |
| 67 | index = 0; | |
| 68 | } | |
| 69 | ||
| 70 | /* cuatro a la vez | |
| 71 | ||
| 72 | int total = squares.size(); | |
| 73 | for (int i=0; i<4; i++) {
| |
| 74 | squares.get(index + i*total/4).draw(); | |
| 75 | } | |
| 76 | if (index < total/4) index++; | |
| 77 | ||
| 78 | */ |