Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

03 Eigener Filter erstellen

Februar 27, 2012

Ich erstellte einen einfachen Verlauf mit Hilfe der Mausposition X. Ziehe ich die Maus von Links nach Rechts, so verliert das Bild an Sättigung. Drücke ich die Taste "b" so wechselt der Filter zur Helligkeit. Ebenfalls wieder von Links nach Rechts. Code:

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();
}