Hi, I am trying to convert this to animation filter and webcam filter, the idea seems it is so interesting itself. But it seems the frame rate is very low.
the animate version:
PImage img;
PImage sorted;
float zoff = 0;
void setup()
{
// width and height should be similar to the picture's dimensions
size(1324, 900, P3D);
img = loadImage("Rembrandt_Girl_in_a_Picture_Frame.jpg");
sorted = createImage(img.width, img.height, RGB);
}
void draw()
{
sorted = img.get();
sorted.loadPixels();
println(frameRate);
//for(int f = 0; f < 100; f++)
//{
//int selectedPixel = index;
for(int i = 0; i < sorted.width; i++)
{
for(int j = 0; j < sorted.height; j++)
{
int order = i + j * sorted.width;
float n = warp3D(i, j, zoff, 0.02, 1024);
//int offset = (index-int(n));
int offset = abs(order-int(n));
//println(offset);
//if(offset < 0)
//{
// offset = 0;
//}
color temp = sorted.pixels[offset];
sorted.pixels[order] = temp;
}
}
zoff += 2;
sorted.updatePixels();
background(0);
image(img, 0, 0);
image(sorted, 664, 0);
//image(sorted, 200, 0);
//if(sorted != null)
//{
// //save("RembrandtGirlinaPictureFrame_sortedNoise.jpg");
// noLoop();
//}
}
float warp(int x, int y, float factor, float n_range)
{
float n1 = noise((x + 0.0) * factor, (y + 0.0) * factor) * n_range;
float n2 = noise((x + 5.2) * factor, (y + 1.3) * factor) * n_range;
PVector q = new PVector(n1, n2);
float n3 = noise(((x + q.x * 4.0) + 1.7) * factor, ((y + q.y * 4.0) + 9.2) * factor);
float n4 = noise(((x + q.x * 4.0) + 8.3) * factor, ((y + q.y * 4.0) + 2.8) * factor);
PVector r = new PVector(n3, n4);
return noise((x + r.x * 4.0) * factor, (y + r.y * 4.0) * factor) * n_range;
}
float warp3D(int x, int y, float z, float factor, float n_range)
{
float n1 = noise((x + 0.0) * factor, (y + 0.0) * factor, (z + 0.0)* factor) * n_range;
float n2 = noise((x + 5.2) * factor, (y + 1.3) * factor, (z + 0.6)* factor) * n_range;
float n3 = noise((x + 9.4) * factor, (y + 2.8) * factor, (z + 1.7)* factor) * n_range;
PVector q = new PVector(n1, n2, n3);
float n4 = noise(((x + q.x * 4.0) + 1.7) * factor, ((y + q.y * 4.0) + 9.2) * factor, ((z + q.z * 4.0) + 13.1) * factor);
float n5 = noise(((x + q.x * 4.0) + 8.3) * factor, ((y + q.y * 4.0) + 2.8) * factor, ((z + q.z * 4.0) + 1.3)* factor);
float n6 = noise(((x + q.x * 4.0) + 12.6) * factor, ((y + q.y * 4.0) + 1.3) * factor, ((z + q.z * 4.0) + 0.6) * factor);
PVector r = new PVector(n4, n5, n6);
return noise((x + r.x * 4.0) * factor, (y + r.y * 4.0) * factor, (z + r.z * 4.0) * factor) * n_range;
}
the webcam version
import processing.video.*;
Capture cam;
PImage img;
PImage sorted;
void captureEvent(Capture c)
{
c.read();
}
void setup()
{
// width and height should be similar to the picture's dimensions
size(1280, 480, P2D);
String[] cameras = Capture.list();
printArray(cameras);
cam = new Capture(this, cameras[0]);
cam.start();
img = createImage(640, 480, RGB);
img = cam;
}
void draw()
{
sorted = createImage(img.width, img.height, RGB);
sorted = img.get();
sorted.loadPixels();
for(int i = 0; i < sorted.width; i++)
{
for(int j = 0; j < sorted.height; j++)
{
int index = i + j * sorted.width;
float n = warp(i, j, 0.02, 1024);
//float n = warp(i, j, 0.003, 615);
//float n = warp(i, j, 0.003, 1);
//int offset = (index-int(n));
int offset = abs(index-int(n));
//println(offset);
//if(offset < 0)
//{
// offset = 0;
//}
color temp = sorted.pixels[offset];
sorted.pixels[index] = temp;
}
}
sorted.updatePixels();
//background(0);
image(img, 0, 0);
image(sorted, 640, 0);
println(frameRate);
}
float warp(int x, int y, float factor, float n_range)
{
float n1 = noise((x + 0.0) * factor, (y + 0.0) * factor) * n_range;
float n2 = noise((x + 5.2) * factor, (y + 1.3) * factor) * n_range;
PVector q = new PVector(n1, n2);
float n3 = noise(((x + q.x * 4.0) + 1.7) * factor, ((y + q.y * 4.0) + 9.2) * factor);
float n4 = noise(((x + q.x * 4.0) + 8.3) * factor, ((y + q.y * 4.0) + 2.8) * factor);
PVector r = new PVector(n3, n4);
return noise((x + r.x * 4.0) * factor, (y + r.y * 4.0) * factor) * n_range;
}