Stereo Effect: half of window replicates the other

Hello!

I am trying to get the right half of my processing window to replicate whatever is happening (in this case showing 3d shapes) on the left half of the window - in other words, a stereo effect. I have tried torturing the code found here which mirrors one side, in order to get it to replicate and not mirror, but without any success at all. Playing with the numbers via trial and error just gives me distorted results.

Does anyone have a clue what I could do? Thank you very much!

void setup(){
 size(800,400, P2D);
}

void draw(){
  background(250);
  fill(0);
  rect(0,0,200,400);
  fill(255);
  rect(0,200,200,400);

  fill(255,0,0);
  ellipse(mouseX, mouseY,20,20);

  flipHalf();
}

void flipHalf() {
  beginShape();
  texture(get());
  vertex(width/2, 0, width/2, 0);
  vertex(width, 0, 0, 0);
  vertex(width, height, 0, height);
  vertex(width/2, height, width/2, height);
  endShape();
}

Answers

  • edited January 2017 Answer ✓

    @jetjaguar -- don't overthink it. If you want to copy the left half of your sketch to the right half, just use copy() at the end of your draw loop.

    Here is a simple example based on your code above:

    void setup(){
     size(800,400, P2D);
    }
    
    void draw(){
      // draw on the left half
      background(250);
      fill(0);
      rect(0,0,200,400);
      fill(255);
      rect(0,200,200,400);
      fill(255,0,0);
      ellipse(mouseX, mouseY,20,20);
    
      // copy to the right
      copy(0, 0, width/2, height, width/2, 0, width/2, height);
    }
    

    P.S. "distorted results" may mean that you are using x1,y1,x2,y2 -- copy uses x,y,w,h. The w,h values in the first four arguments and in second four should be the same numbers or there will be distortion.

  • edited January 2017

    @jetjaguar -- you can also create a PGraphics image and then draw it twice on the main canvas with image(). Both approaches work but PGraphics is more flexible than copy if you want different compositions with multiple images, partial overlapping, etc.

    Here is the same sketch as above, only using PGraphics instead of copy:

    PGraphics pg;
    void setup(){
      size(800,400, P2D);
      pg = createGraphics(400, 400, P2D);
    }
    void draw(){
      // draw on PGraphics
      pg.beginDraw();
      pg.background(250);
      pg.fill(0);
      pg.rect(0,0,200,400);
      pg.fill(255);
      pg.rect(0,200,200,400);
      pg.fill(255,0,0);
      pg.ellipse(mouseX, mouseY,20,20);
      pg.endDraw();
    
      // render twice on sketch
      image(pg,0,0);
      image(pg,width/2,0);
    }
    
  • copy(0, 0, width/2, height, width/2, 0, width/2, height);

    This works perfectly for what I need, it copies everything. Thank you so much Jeremy!

Sign In or Register to comment.