giCentre Utilities library question: saving a zoomed and panned buffer

edited December 2014 in Library Questions

Hello,

Please execute the code below. The image of the circle can be zoomed by pressing the ALT key, pressing the left mouse button, and dragging. The image of the circle can be panned by pressing the ALT key, pressing the right mouse button, and dragging. I have a display window of 300 x 300 pixels, and a PGraphics buffer of 400 x 400 pixels. When the sketch starts, the circle is located in lower right 2/3 of the display window. Press the 'r' key to start over in terms of zooming and panning.

Press 'r'. Next, pressing the 's' key saves the buffer to a file (test.jpg) located in the sketch's directory (next to the .PDE file). Upon examination of the file, you can see that the circle (200 pixels in diameter) is located in the middle of the image (since the buffer is 400 x 400 pixels).

Now, no matter what I do in terms of panning and zooming, I want to see the circle located in the middle of the image when I save the buiffer. However, the circle in the saved image is dependent upon how I zoom and pan the display window. Pan and zoom the display window and save the image to the file to confirm this.

I do get the effect that I want when I first press 'r' and then press 's'. Ideally, however, I want to not have to reset my panning and zooming every time I want to save. Can you help me with this? See http://www.gicentre.net/utils/zoom for a description of the library involved.

Thanks, Craig

import processing.core.*;
import geomerative.*;
import org.gicentre.utils.move.*;

RShape rcircle, rline;
ZoomPan zoomer;
PVector mousePos;
PGraphics board;

void setup() {  
     size(300,300);
     board = createGraphics(400,400);
     board.background(255);

        zoomer = new ZoomPan(this,board);
        zoomer.setMouseMask(ALT);
        zoomer.setZoomScale(1);

        RG.init(this);
        rcircle = new RShape();
        rline = new RShape();
    }

 void draw() {
        board.background(255);
        pushMatrix();
        board.beginDraw();
        zoomer.transform(board);

        rcircle = RShape.createCircle(200, 200, 200);
        rcircle.draw(board);

        ellipseMode(RADIUS);
        noFill();

        for (int i = 0; i < 8; i++)
        {
          float index = (float) (i / 8.0);
          RPoint pt = rcircle.getPoint(index);
          board.ellipse(pt.x,pt.y,5,5);
        }

        board.endDraw(); 
        image(board,0,0); 
        popMatrix();
}

void keyPressed()
{
        if (key=='r')
        {
           zoomer.reset(); 
        }

        if (key=='s')
        {        
           board.save("test.jpg");
        } 
}
Sign In or Register to comment.