• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why isn't this code flipping the image as it should?  RSS feed

 
Joshua Harris
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm trying to create a method which flips a picture horizontally from left to right but for some reason this code is only making half of the image flip.



I've tried things like changing the condition in the 2nd loop to "j < gray[i].length" instead of length/2 but it produces the same result. I coded a program which does the same thing a few weeks ago but somehow I can't get it to work this time.

edit: literally got it working about 2 minutes after posting this lol. Hard to believe that I couldn't spot the mistake despite staring at the code for half an hour last night.

 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume your issue was caused by the fact that you were overwriting the image as you go?

The first loop command will be:
gray[0][0] = gray[0][length] // but you are going to lose the value from gray[0][0] which you haven't copied yet!

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!