Created
July 14, 2010 10:46
-
-
Save eiszfuchs/475287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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