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.

pixel blending animation

März 5, 2012

a blending effect takes place square by square between two pictures. The square diminishes in size to create a mor hi-res image. With the space bar the next picture can be activated.

PImage[] img = new PImage[6];
float pause = 0.000001;
long timeStamp;
float rectSize = 30;
int getPic = 0;
int getPicNext = 1;

void setup() {
 size(800, 600);
 img[0] = loadImage("ducks.jpg");
 img[1] = loadImage("arcade.jpg");
 img[2] = loadImage("forbidenplanet.jpg");
 img[3] = loadImage("green.jpg");
 img[4] = loadImage("planets.jpg");
 img[5] = loadImage("vector.jpg");
 noStroke();
 image(img[getPic], 0, 0);
}

void draw() {

 img[getPic].loadPixels();
 img[getPicNext].loadPixels();
 // We must also call loadPixels() on the PImage since we are going to read its pixels.
 for (int y = 0; y < height; y++ ) {
 for (int x = 0; x < width; x++ ) {
 if (millis()-timeStamp>pause) {
 if (rectSize>=10)
 rectSize = rectSize-(pause*5000);

int getRandomLocX = int(random(width));
 int getRandomLocY = int(random(height));

int loc = getRandomLocX + getRandomLocY*width;

float r = red(img[getPicNext].pixels [loc]);
 float g = green(img[getPicNext].pixels[loc]);
 float b = blue(img[getPicNext].pixels[loc]);

fill(r, g, b, 80);
 rect(getRandomLocX, getRandomLocY, rectSize, rectSize);
 timeStamp= millis();
 }
 }
 }
}

void keyPressed() {
 if (key==32) {
 rectSize = 80;
 getPic++;
 getPicNext = getPic+1;

if (getPic==img.length-1) {
 getPicNext=0;
 }
 if (getPic==img.length) {
 getPic=0;
 getPicNext = getPic+1;
 }
 }
 println(getPic +" | " +getPicNext);
}