We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I've been trying to have a pan effect in my project. Came across a simple & great blog by "daniel shiffman" to have a pan effect. [Link: shiffman.net/2011/12/20/night-1-zoom-and-pan-in-2d/] It works great if you are trying to just pan a static scene in the processsing window.
But, how about a scene which is constantly updating my window? How can i have pan effect for the same?
One of the ways i could think of is by remembering all the points in the previous frame and rendering them again and again!
Works fine! except that: 1. I'm redrawing the points every time draw is called. 2. The program needs to remember all the points which have been drawn so far.
So, It consumes lot of memory and it slows down the frame rate of the sketch.
Any easier way around this? - Thanks in advance! :)
Below is the code for the same - Please try it out!:
ArrayList<PVector> draw_points;
int x_pos = 0;
PVector offset, poffset,mouse;
void setup(){
draw_points = new ArrayList<PVector>();
size(512,512);
background(255);
offset = new PVector(0, 0);
poffset = new PVector(0, 0);
for(int i=0;i<100;i++){
draw_points.add(new PVector(i,i));
}
}
void draw(){
background(255);
translate(width/2, height/2);
float zoom = 1.0; // 150%
scale(zoom);
translate(-width/2, -height/2);
translate(0,200);
translate(offset.x,offset.y);
x_pos += 3;
//translate(x_pos,0);
for(int i=0;i<100;i++){
draw_points.add(new PVector(i+x_pos,i));
}
println(draw_points.size());
for(int i=0;i<draw_points.size();i++){
point(draw_points.get(i).x,draw_points.get(i).y);
}
}
void mousePressed() {
mouse = new PVector(mouseX, mouseY);
poffset.set(offset);
}
void mouseDragged() {
offset.x = mouseX - mouse.x + poffset.x;
offset.y = mouseY - mouse.y + poffset.y;
}
Comments
Two options:
that's one of the basic approaches in processing I think
Map
when you use a map you just display the part of the map that's inside the screen and thus pan
http://www.openprocessing.org/sketch/149191
;-)