import processing.pdf.*;
PImage img;
PImage img1;
int numFrames = 50;

int unit = 2;//How close lines are from each other
boolean record = true;
void setup() {
size(900, 600, P3D);
img = loadImage("IMG13.JPG");
img1 = loadImage("IMG1.JPG");
imageMode(CENTER);
stroke(255);
frameRate(20);
//noStroke();
}

void draw() {
if (record == true) {
PGraphicsPDF pdf = (PGraphicsPDF)beginRaw(PDF, "Portrait-###.pdf");
pdf.strokeCap(SQUARE);
pdf.fill(0);
pdf.noStroke();
pdf.rect(0, 0, width, height);
}
//rotateX(map(mouseX, 0, width, 0, HALF_PI));
//rotateY(map(mouseY, 0, height, 0, HALF_PI));

for (int y = unit/2; y < height; y += unit) {
for (int x = unit/2; x < width; x += unit) {
color c = img.get(x, y);
color c1 = img1.get(x, y);
float b = brightness(c/2);//If statement
float b1 = brightness(c1);
float fade = map(frameCount, 0, numFrames, 0, 1);
//float fade1 = map(frameCount, 0, numFrames, 1, 0);
float b2 = lerp(b, b1, fade);
stroke(c);
line(x, y, b2, x, y, b2-10);
}
}

endRaw();
if (frameCount>numFrames) {
exit();
}

}