Advertisement
xeromino

frac

Jan 19th, 2016
337
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int cols = 8, rows = cols, w, h;
  2. Square[] squares = new Square[rows*cols];
  3. PImage img;
  4. long rs = (long) 123564;
  5.  
  6. void setup() {
  7.   size(100, 100);
  8.   img = loadImage("https://s-media-cache-ak0.pinimg.com/736x/b9/09/fb/b909fb80abb83d4386e45b79002b68fb.jpg");
  9.   w = 540/cols;
  10.   h = 540/rows;
  11.   surface.setResizable(true);
  12.   surface.setSize(img.width+int(w*1.5), img.height+int(h*1.25));
  13.   int i=0;
  14.   for (int x=0; x<rows; x++) {
  15.     for (int y=0; y<cols; y++) {
  16.       squares[i] = new Square(x*w, y*h);
  17.       i++;
  18.     }
  19.   }
  20. }
  21.  
  22. void draw() {
  23.   //rs = (long) random(1234567);
  24.   randomSeed(rs);
  25.   background(255);
  26.   for (int i=0; i<cols*rows; i++) {
  27.     squares[i].update();
  28.     squares[i].display();
  29.   }
  30.   //if (frameCount<=10) saveFrame("image-###.jpg");
  31. }
  32.  
  33. void mouseReleased() {
  34.   rs = (long) random(1234567);
  35. }
  36.  
  37. class Square {
  38.  
  39.   PGraphics square;
  40.   PImage temp;
  41.   int x, y;
  42.  
  43.   Square(int _x, int _y) {
  44.     x = int(_x+w*.75);
  45.     y = _y+25;
  46.     square = createGraphics(w, h);
  47.   }
  48.  
  49.   void update() {
  50.     square.beginDraw();
  51.     //square.background(255);
  52.     //square.fill(0);
  53.     square.copy(img,x-w,y-h,w*2,h*2,int(random(-w/2)),int(random(-h/2)),w*2,h*2);
  54.     square.endDraw();
  55.   }
  56.  
  57.   void display() {
  58.     //tint(255,125);
  59.     image(square, x, y);
  60.   }
  61. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement