Flip along the x-axis

Here’s some code I’m using to generate a color wheel (you can copy-paste this into your PDE and it should run just fine):

void setup()  {
  size(500, 500);
  noStroke();
  background(255);
  colorMode(HSB, 360, 100, 100);
}

void draw()  {
  cw(width/2, height/2, 200, 5);
}


void cw(float x, float y, float r, float spacer)  {
  pushMatrix(); translate(x, y); rotate(radians(-90));
  
  for(int i = 0; i < 360; i+= spacer)  {
    float x1 = pcx(r, i); float x2 = pcx(r, i+1.5 + spacer);
    float y1 = pcy(r, i); float y2 = pcy(r, i+1.5 + spacer);
    
    noStroke();
    fill(i, 80, 90);
    triangle(0, 0, x1, y1, x2, y2);
  }
  fill(0, 0, 100); ellipse(0, 0, r*1.05, r*1.05);
  
  popMatrix();
}

float pcx(float r, float theta)  {  return r * cos(radians(theta));  }
float pcy(float r, float theta)  {  return r * sin(radians(theta));  }

I want to flip this output horizontally, so that it would look like this:

I’ve tried scale(-1, 1) followed by translate but to no avail.

Would be very grateful if you help me out with this. Thank you.

1 Like

You have the right idea with scale(). Put it here:

void cw(float x, float y, float r, float spacer)  {
  pushMatrix(); translate(x, y); rotate(radians(-90)); scale(1,-1); // <---
2 Likes

Well, that was easier than I thought it would be.
Thank you!

Yep! Also notice that this is actually a “vertical” flip because you’ve already rotated the image somewhat.

Oh, and you get pineapples for asking your question well. :pineapple::pineapple::pineapple:

1 Like

Yep! Also notice that this is actually a “vertical” flip because you’ve already rotated the image somewhat.

Yes, I did, and this is what I missed out on earlier. I was trying to use scale(-1, 1) while forgetting that I’d already rotated it before and wasn’t getting the order right.

Oh, and you get pineapples for asking your question well. :pineapple::pineapple::pineapple:

cheers :slight_smile:
It’s the least one should do when asking for help

1 Like