import processing.video.*; // // PARAMETERS // int REFRESH_INTERVAL = 14000; // in millisecs float START_DISPLACEMENT = 0.0; float SPEED = 1.0; boolean INVERT_COLORS = false; Capture video; PVector[] vectorMap; PImage display; PImage source_img; int source_x, source_y; int index; float amp; int last_update; void setup() { size(1024, 768); video = new Capture(this, width, height); video.start(); while (!video.available()) { delay(100); } video.read(); vectorMap = new PVector[video.pixels.length]; updateDisplacementMap(vectorMap, video); display = createImage(width, height, RGB); source_img = video.copy(); amp = START_DISPLACEMENT; last_update = millis(); } void updateDisplacementMap(PVector[] vector_map, PImage map_img) { map_img.loadPixels(); float x_off, y_off; for (int j=0; j> 16 & 0xFF) / 255.0; y_off = -0.5 + (displacementPix >> 8 & 0xFF) / 255.0; vector_map[index] = new PVector(x_off, y_off); } } } void draw() { if (video.available()) { video.read(); updateDisplacementMap(vectorMap, video); if (millis() - last_update > REFRESH_INTERVAL) { source_img = video.copy(); source_img.loadPixels(); last_update = millis(); amp = START_DISPLACEMENT; } } index = 0; for (int j=0; j= display.width) source_x -= display.width; while (source_y < 0) source_y += display.height; while (source_y >= display.height) source_y -= display.height; display.pixels[index] = source_img.pixels[display.width*source_y + source_x]; index++; } } display.updatePixels(); if (INVERT_COLORS) display.filter(INVERT); image(display, 0, 0); amp += SPEED; } void mouseClicked() { saveFrame("pic-###.png"); }