Advertisement
xeromino

glitch

May 8th, 2015
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. PImage img;
  2. int min = 40, max = 80;
  3. int r = 10;
  4.  
  5. void setup() {
  6.   img = loadImage("https://s-media-cache-ak0.pinimg.com/736x/2c/f6/a5/2cf6a58f75b368949cf98db03b925f1b.jpg");
  7.   size(img.width, img.height);
  8.   image(img,0,0);
  9. }
  10.  
  11. void draw() {
  12.   int w = (int)random(min, max);
  13.   int h = int(w*3);
  14.   int x = (int)random(0, width-w);
  15.   int y = (int)random(0, height-h);
  16.   PImage tmp = createImage(w, h, RGB);
  17.   tmp.loadPixels();
  18.   float rd = random(1);
  19.   for (int px=0; px<w; px++) {
  20.     for (int py=0; py<h; py++) {
  21.       if (rd>0.1) {
  22.       tmp.pixels[py*w+px]=img.get(x+px, y+py);
  23.       } else {
  24.       tmp.pixels[py*w+px]=color(0);
  25.       }
  26.     }
  27.   }
  28.   tmp.updatePixels();
  29.   /*
  30.   int v = (int)random(-r, r);
  31.   fill(100,100);
  32.   noStroke();
  33.   int e = 2;
  34.   rect(x+v+1,y+v+1,w+e,h+e);
  35.   fill(255,255);  
  36.   rect(x+v-e/2,y+v-e/2,w+e,h+e);
  37.   */
  38.   image(tmp, x+v, y+v);
  39. }
  40.  
  41. void keyPressed() {
  42.   save(random(123456)+".jpg");
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement