Februar 27, 2012
![](../../../../files/2012/02/points_2012-2-27_13-55-45-300x225.jpg)
![](../../../../files/2012/02/points_2012-2-27_14-1-13-300x225.jpg)
![](../../../../files/2012/02/points_2012-2-27_14-0-58-300x225.jpg)
PImage img; PImage img2; float alphaWert; void setup() { img = loadImage("landschaft.jpg"); img2 = loadImage("landschaft_black.jpg"); size(1024,768); } void draw() { image(img, 0,0,1024,768); image(img2,0,0,1024,768); loadPixels(); // We must also call loadPixels() on the PImage since we are going to read its pixels. img.loadPixels(); for (int x = 0; x <width; x++ ) { for (int y = 0; y <height; y++ ) { // Calculate the 1D pixel location int loc = x + y*width; // Get the R,G,B values from image float r = red (pixels[loc]); float g = green (pixels[loc]); float b = blue (pixels[loc]); float distance = dist(x,y,mouseX,mouseY); // The closer the pixel is to the mouse, the lower the value of "distance" // We want closer pixels to be brighter, however, so we invert the value with the formula: adjustBrightness = (50-distance)/50 // Pixels with a distance of 50 (or greater) have a brightness of 0.0 (or negative which is equivalent to 0 here) // Pixels with a distance of 0 have a brightness of 1.0. if(mousePressed) { save("screens/points_"+year()+"-"+month()+"-"+day()+"_"+hour()+"-"+minute()+"-"+second()); } switch(key) { case ' ': float yves = (300-distance)/300; r *= yves; g *= yves; b *= yves; tint(255,map(mouseX,0,width,0,255)); // macht das Bild transparent break; case'b': noTint(); // We calculate a multiplier ranging from 0.0 to 8.0 based on mouseX position. // That multiplier changes the RGB value of each pixel. float adjustBrightness = ((float) mouseX / width) * 4.0; r *= adjustBrightness; g *= adjustBrightness; b *= adjustBrightness; break; case'v': noTint(); yves = 1; r *= yves; g *= yves; b *= yves; break; } // The RGB values are constrained between 0 and 255 before being set as a new color. r = constrain(r,0,255); g = constrain(g,0,255); b = constrain(b,0,255); // Make a new color and set pixel in the window color c = color(r,g,b); pixels[loc] = c; } } updatePixels(); }