GMU:Processing im Park/Emilio Aguas/Code Collages

From Medien Wiki
< GMU:Processing im Park‎ | Emilio Aguas
Revision as of 23:18, 17 December 2015 by EmilioAguas (talk | contribs) (Created page with "====--- Processing3.0 Code--- ==== <source lang="java"> //Creating and Initializing variables PImage pic; int horizontal=50; int vertical=40; int cuts= horizontal * vertical; P...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

--- Processing3.0 Code---

//Creating and Initializing variables
PImage pic;
int horizontal=50;
int vertical=40;
int cuts= horizontal * vertical;
PImage [] jigsaw = new PImage[cuts];
int cutX;
int cutY;

void setup() {
  size(500, 400);
  //webimage
  String link="https://c1.staticflickr.com/1/695/22845688014_54ee4fad33_k.jpg";
  pic = loadImage(link, "jpg");
  image (pic, 0, 0, width, height);

  //slices size
  cutX= width / horizontal;
  cutY= height / vertical;

  //taking the cuts

  for (int i=0; i<cuts; i++) {
    int x= (i % horizontal) * cutX;
    int y= (i / vertical) * cutY;

    // fill the array
    jigsaw [i] = get (x, y, cutX, cutY);
  }
  noLoop();
}

void draw() {
  //background(0);

  //New cordinates for the pices
  for (int i=0; i<cuts; i++) {
    int x= (i % horizontal) * cutX;
    int y= (i / vertical) * cutY;

    //random interger

    int puzzle = int(random(cuts));
    //puzzle= puzzle % cuts;
    
    //create the jigsaw
    image(jigsaw[puzzle], x, y);
  }
}