Bonus: Glitch



PImage img;
int min = 40, max = 80;
int r = 10;
 
void setup() {
  img = loadImage("https://s-media-cache-ak0.pinimg.com/736x/2c/f6/a5/2cf6a58f75b368949cf98db03b925f1b.jpg");
  size(img.width, img.height);
  image(img,0,0);
}
 
void draw() {
  int w = (int)random(min, max);
  int h = int(w*3);
  int x = (int)random(0, width-w);
  int y = (int)random(0, height-h);
  PImage tmp = createImage(w, h, RGB);
  tmp.loadPixels();
  float rd = random(1);
  for (int px=0; px < w; px++) {
    for (int py=0; py < h; py++) {
      if (rd>0.1) {
      tmp.pixels[py*w+px]=img.get(x+px, y+py);
      } else {
      tmp.pixels[py*w+px]=color(0);
      }
    }
  }
  tmp.updatePixels();
  
  int v = (int)random(-r, r);
  fill(100,100);
  noStroke();
  int e = 2;
  rect(x+v+1,y+v+1,w+e,h+e);
  fill(255,255);  
  rect(x+v-e/2,y+v-e/2,w+e,h+e);
  
  image(tmp, x+v, y+v);
}
 
void keyPressed() {
  save(random(123456)+".jpg");
 
}

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *