Flip the image HORIZONTALLY

please format code with </> button * homework policy * asking questions

Hi, I’m new to processing, and I’m trying to flip the image horizontally. However, I am facing the problem of only flipping half of the image, could you guys help me with it?

Here is my code:

PImage img;

void setup()
{
img = loadImage( “coffee.JPG”);
size(img.width,img.height); // use size of the image
noLoop();
}

void draw()
{
// Use for loops to go through every pixel
for (int y = 0; y < img.height; y++ )
{
for (int x = 0; x < img.width/2; x++ )
{
// get the color values
float r = red (img.get(x, y));
float g = green(img.get(x, y));
float b = blue (img.get(x, y));

  /******** image processing goes here **********/


  // Set the new color to the pixel
  img.set(width-x, y, color(r,g,b));    
}

}
image(img, 0, 0); // display the image
}

Yes. Please check your for-loops

just add

scale(1, -1);

before

image(img, 0, 0);

Hello,

Please format your code:
https://discourse.processing.org/faq#format-your-code

I usually just skip over unformatted code because I have to fix it to test it!

Your code appears to do that.

This image:
tint1

becomes this with your code:
image

I had to manually set size() to image size.

There is a comment here about passing parameters to size() in settings() and loadImage():

:)