Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage img;
- ArrayList<Square> squares = new ArrayList<Square>();
- int min = 8; //min size of the square
- int index = 0;
- void setup() {
- img = loadImage("http://a4.mzstatic.com/us/r30/Purple/05/81/e6/mzm.kcjwvjip.jpg");
- size(img.width, img.height);
- background(0);
- cuarto(0, 0, img.width); //recursion
- }
- void draw() {
- //stroke(255, 0, 0);
- noStroke();
- if (index < squares.size()) {
- squares.get(index).draw();
- index++;
- }
- }
- void cuarto(int x, int y, int tam) {
- if (tam >= min) {
- squares.add(new Square(x, y, tam, img.pixels[x+tam/2 + (y+tam/2)*img.width]));
- cuarto(x, y, tam/2);
- cuarto(x+tam/2, y, tam/2);
- cuarto(x, y+tam/2, tam/2);
- cuarto(x+tam/2, y+tam/2, tam/2);
- }
- }
- class Square {
- int x, y;
- int tam;
- color c;
- Square(int _x, int _y, int _tam, color _c) {
- x = _x;
- y = _y;
- tam = _tam;
- c = _c;
- }
- void draw() {
- fill(c);
- rect(x, y, tam, tam);
- }
- }
- void keyPressed() {
- if (key == '-') {
- if (min > 2) {
- min = min/2;
- }
- }
- if (key == '+') {
- min = min*2;
- }
- println(key+"..."+min); //min size of the square
- background(0);
- squares = new ArrayList<Square>();
- cuarto(0, 0, img.width);
- index = 0;
- }
- /* cuatro a la vez
- int total = squares.size();
- for (int i=0; i<4; i++) {
- squares.get(index + i*total/4).draw();
- }
- if (index < total/4) index++;
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement