Many tiny sketches in one sketch / Passepartout

edited November 2015 in How To...

Hi coders!

I guess, this is a bold and a little bit naive question, but i just wonder if it is possible to stick a part of my sketch into a rectangle, to have different layers with cropped animations.

Imagine InDesign: There you can easily create a rectangle an load an image inside. The frame is like a passepartout for the image and it can be placed anywhere in an document, even on top of other images. That is what i am looking for.

Does anyone know how this can be done?

Have a nice coding-weekend!

Answers

  • Answer ✓

    Hi,

    do you want to have two seperate sketches or just two drawing surfaces?
    For the latter, you could use different PGraphics-objects, use them for your drawing/animation and then show them like two images. Have a look at createGraphics() or this example:

    PGraphics pg1, pg2;
    
    void setup(){
      size(500, 300);
      // create two PGraphics objects
      pg1 = createGraphics(300, 300);
      pg2 = createGraphics(200, 300);
    }
    
    void draw(){
    
      // draw on first PGraphics
      pg1.beginDraw();
      pg1.background(255);;
      pg1.noFill();
      for(int i =0; i< 50; i++){
        int d = (frameCount+i*20)%800;
        pg1.ellipse(50, 50, d, d);
      }
      pg1.endDraw();
    
    
      // draw on second PGraphics
      pg2.beginDraw();
      pg2.background(255);
      pg2.noFill();
      for(int i =0; i< 50; i++){
        int d = (frameCount+i*20)%800;
        pg2.ellipse(100, 150, d, d);
      }
      pg2.endDraw();
    
    
      // show both PGraphics on different locations
      image(pg1, 0, 0);
      image(pg2, 300, 0);
    }
    
Sign In or Register to comment.