Skip to content

Instantly share code, notes, and snippets.

@eiszfuchs
Created July 14, 2010 10:46
Show Gist options
  • Save eiszfuchs/475287 to your computer and use it in GitHub Desktop.
Save eiszfuchs/475287 to your computer and use it in GitHub Desktop.
// image instance
PImage img;
// set up canvas
void setup() {
img = loadImage("IMG_0472.png");
size(img.width, img.height); // this is cool!
}
/**
* Brightness Negative
* This will create a negative of a picture,
* remaining all colours instead of negating
* them too.
*/
void draw() {
background(0);
image(img, 0, 0); // draw the picture
// get size & set colour mode
int sizeImage = width * height;
loadPixels(); // get the pixels!
for (int i = 0; i < sizeImage; i++) {
colorMode(RGB, 255);
// for every pixel: get RGB values
float r = red(pixels[i]);
float g = green(pixels[i]);
float b = blue(pixels[i]);
// set brightness negative
pixels[i] = color(255-r, 255-g, 255-b);
colorMode(HSB, 255);
// for every pixel: get HSB values
float h = hue(pixels[i]);
float s = saturation(pixels[i]);
float v = brightness(pixels[i]);
pixels[i] = color((255+h+127)%255, s, v);
}
updatePixels(); // show the pixels!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment