MaiaVictor
MaiaVictor

Reputation: 52957

How do you flip a image horizontally using Processing.js?

Not much to add to the question. How do you flip a image horizontally using Processing.js?

Upvotes: 3

Views: 12297

Answers (2)

unblevable
unblevable

Reputation: 1316

Assuming you've already loaded your img:

processing.draw = function () {
   // place image
    processing.image(img, 0, 0);

    // flip using a matrix
    processing.pushMatrix();
    processing.scale(-1.0, 1.0)
    processing.image(img, -img.width, 0);
    processing.popMatrix();
};

If needed, it shouldn't be too hard to adjust the arguments to flip the image vertically.

Upvotes: 8

user2578094
user2578094

Reputation:

public PImage getReversePImage( PImage image ) {
 PImage reverse = new PImage( image.width, image.height );
 for( int i=0; i < image.width; i++ ){
   for(int j=0; j < image.height; j++){
     reverse.set( image.width - 1 - i, j, image.get(i, j) );
   }   
 }
 return reverse;
}

From http://uihacker.blogspot.com/2012/04/processing-flip-pimage-horizontally.html

Upvotes: 0

Related Questions