...
| Code Block | ||||
|---|---|---|---|---|
| ||||
PImage myImage; int pixelSize = 10; void setup() { size(200600, 200400); myImage = loadImage("EinBild.png"); myImage.loadPixels(); } void draw() { myImage.loadPixels()int size = mouseX/10+1; for(int x=0; x<width; x+=pixelSizesize) { for(int y=0; y<height; y+=pixelSizesize) { int loc = x+y*width; color c = myImage.pixels[loc]; fill(c); noStroke(); rect(x, y, pixelSizesize, pixelSizesize); } } } |
Flashlight
Im folgenden Beispiel verändern wir die Helligkeit der Pixel durch die Position der Maus:
| Code Block | ||||
|---|---|---|---|---|
| ||||
PImage myImage;
void setup() {
size(200600, 200400);
myImage = loadImage("EinBild.png");
}
void draw() {
loadPixels();
myImage.loadPixels();
PVector mousePos = new PVector(mouseX, mouseY);
PVector currPixel = new PVector(0, 0);
for for(int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
int loc = x+y*width;
currPixel.x = x;
currPixel.y = y;
float r = red(myImage.pixels[loc]);
float g = redgreen(myImage.pixels[loc]);
float b = redblue(myImage.pixels[loc]);
float distance = mousePos.dist(currPixel);
float brightness = (50100-distance)/50;
100;
r*=brightness;
g*=brightness;
b*=brightness;
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
color c = color(r, g, b);
pixels[loc] = c;
}
}
updatePixels();
}
|
Threshold
Im folgenden Beispiel zeichnen wir ein Schatz-Weiss Bild welches auf bestimmte Grenzwerte abgestimmt ist. Ausserdem zeichnen wir in diesem Beispiel nicht auf die Zeichenfläche direkt, sondern initialisieren ein neues “leeres” Bild auf dem wir dann zeichen:
...

