GMU:Processing im Park/Sina Stolp/raster code

From Medien Wiki
< GMU:Processing im Park‎ | Sina Stolp
Revision as of 17:33, 2 January 2016 by Stolpertz (talk | contribs) (Created page with " <source lang="java"> PImage img; int columns = 10; int rows = 15; int tiles = columns * rows; PImage[] parts = new PImage[tiles]; int dx; int dy; void setup() { size(4...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
PImage img;
int columns = 10;
int rows = 15;
int tiles = columns * rows;


PImage[] parts = new PImage[tiles];

int dx;
int dy;

void setup() {
   
  size(480, 720);
  dx = 480 / columns;
  dy = 720 / rows;
  
  img = loadImage("r09.jpg");
  image(img, 0, 0, width, height);
 
  // get the parts
  for(int i=0; i < tiles; i++) {
    int x = (i % columns) * dx;
    int y = (i / columns) * dy;
    parts[i] = get(x, y, dx, dy);
  }
  
  noLoop();
}

void draw() {
  
  background(0);
  
 for(int i=0; i < tiles; i++) {
   
 int x = (i % columns) * dx;
 int y = (i / columns) * dy;
 
 int index = int(random(tiles));
 //int index = int(random(tiles));
 
 index = index % tiles;
 
 image(parts[index], x, y);
 }
}