summaryrefslogtreecommitdiff
path: root/Year_2/IandM/negative/negative.pde
blob: c7c4475e252df78fc4d48402309330a469641b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void setup() {
  size(512, 256);
  PImage img = loadImage("lena.png");
  img.resize(256, 256);
  
  image(img, 0, 0);
  image(negative(img), 256, 0);
}

PImage negative(PImage I) {
  PImage out = I.copy();
  out.loadPixels();
  float r, g, b;

  for (int i = 0; i < out.pixels.length; ++i) {
    r= 255-red(out.pixels[i]);
    g= 255-green(out.pixels[i]);
    b= 255-blue(out.pixels[i]);

    out.pixels[i] = color(r, g, b);
  }

  out.updatePixels();
  return out;
}