How to get 4 mirrored quadrants

edited April 2017 in Questions about Code

Hi,

I'm working on a final project for a class and I want to create an interactive piece with 4 mirrored quadrants. I found code to get the left half to reflect on the right half of the composition. Any suggestions on how I can get the bottom half to mirror the top half as well?

float r, w;
PImage leftHalf;


import processing.pdf.*;

void setup(){
  size(720,720);
  background(255);
  frameRate(1);

  beginRecord(PDF, "P4Reflect-1.pdf");
}

void draw(){
  r = random(0,360);
  w = random(5,50);
  fill(75,0,130);
  stroke(w);
  line(0, r, mouseX, mouseY);
    leftHalf = get(0, 0, width/2, height);
  translate(width, 0);
  scale(-1, 1);
  image(leftHalf, 0, 0);
}

void mousePressed(){
  endRecord();
  exit();
}
Tagged:

Answers

  • Use height/2 and also scale(1,-1) and scale(-1,-1).

    Kf

  • edited April 2017

    When scale() is called with -1 in the x or y argument, it flips or mirrors all future drawing commands along that axis.

    Starting with an image in the lower right corner, you could flip it backwards to the lower left... then upside down to the upper left.... then forward to the upper right:

    // forum.processing.org/two/discussion/21978/how-to-get-4-mirrored-quadrants
    // 2017-04-14
    
    PImage pi;
    void setup() {
      size(400, 400);
      pi = loadImage("https://" + "processing.org/img/processing3-logo.png");
      pi.resize(200, 200);
      noLoop();
    }
    
    void draw() {
      background(0, 0, 255);
    
      pushMatrix();
      translate(width/2, height/2);
      image(pi, 0, 0); // lower right
      scale(-1, 1); // mirror left-right
      image(pi, 0, 0); // lower left
      scale(1, -1); // flip up-down
      image(pi, 0, 0); // upper left
      scale(-1, 1); // mirror left-right
      image(pi, 0, 0); // upper right
      popMatrix();
    }
    
Sign In or Register to comment.