PImage bufSlice;
PGraphics buf;
int destinationX;
int destinationY;
int positionX = 20;
int positionY = 20;
int positionX2 = 750;
int positionY2 = 750;
CameraPosition campos;
void setup() {
size(400, 400, P3D);
// Load our image.
// Create an off-screen buffer that will contain the entire image.
destinationX = width;
destinationY = height;
campos = new CameraPosition();
buf = createGraphics(1000, 1000, P3D);
}
void draw() {
background(255);
buf.beginDraw();
buf.ellipse(200, 200, 200, 200);
buf.endDraw();
destinationX = mouseX;
destinationY = mouseY;
campos.move(destinationX, destinationY);
}
/**
* Updates the copied version of the off-screen buffer.
*/
class CameraPosition {
float x, y; //position
float currentX = 0;
float currentY = 0;
float easing;
void move(float destX, float destY) {
x = destX;
y = destY;
easing = .2;
currentX += (y - currentX) * easing;
currentY += (x - currentY) * easing;
image(getBufSlice(currentX, currentY), 0, 0); // plot current position
}
}
PImage getBufSlice(float currentX, float currentY) {
int x = int(currentX);
int y = int(currentY);
return buf.get(x, y, width, height);
}