Hi,
I made a Slit-Scan effect in Processing, now I’m trying to export the pdf of the scan effect with only render the new image, and I thought about PGraphics.
The problem is that PGraphics looks empty, I don’t know why copy() function doesn’t work.
import processing.pdf.*;
// Image Array
int num = 4;
int index = 0;
PImage[] img = new PImage[num];
// PGraphics
PGraphics pg;
// Declare variable
int spacing = 20;
int velocity = 1;
int w, h, pos, speed, mouse;
int portion = 3;
// Scale image
float scala = 0.35;
void setup() {
size(760, 565);
smooth();
stroke(236, 38, 140);
noFill();
strokeCap(CORNER);
strokeWeight(portion);
// Load and scale the image (1500px x 1000px)
for (int i = 0; i < img.length; i++) {
img[i] = loadImage("0" + i + ".jpg");
}
w = round(img[index].width * scala);
h = round(img[index].height* scala);
pg = createGraphics(w, h);
// Speed and Position
speed = 0;
pos = (spacing*2) + w;
}
void draw() {
// Change image
index = constrain(index, 0, img.length);
if (index == num) index = 0;
image(img[index], spacing, spacing, w, h);
// Render
pg.beginDraw();
render(pg);
pg.endDraw();
image(pg, pos, spacing);
}
void render(PGraphics gfx) {
// Constrain mouse inside the load image
mouse = constrain(mouseY, spacing, h+spacing);
// Condition
boolean cond1 = mouseX > spacing;
boolean cond2 = mouseX < spacing + w;
boolean cond3 = mouseY > spacing;
boolean cond4 = mouseY < spacing + h;
if (cond1 && cond2 && cond3 && cond4) {
copy(spacing, mouse, w, portion, pos, spacing+speed, w, 1);
line(spacing, mouse, spacing+w-1, mouse);
speed+=velocity;
if (speed > h) speed = h+100;
}
}
void keyPressed() {
if (key == 'q') speed = 0;
if (keyCode == UP) index++;
if (keyCode == DOWN) index--;
if (key == 's') {
String filename = "out/" + System.currentTimeMillis() + ".pdf";
PGraphicsPDF pdf = (PGraphicsPDF) createGraphics(pg.width, pg.height, PDF, filename);
pdf.beginDraw();
render(pdf);
pdf.dispose();
pdf.endDraw();
println("PDF " + filename + " Saved!");
}
}