This site requires JavaScript, please enable it in your browser!
Greenfoot back
jbiser361
jbiser361 wrote ...

2019/3/8

flip verticle?

jbiser361 jbiser361

2019/3/8

#
Hello :) ok so my teacher doesn't want us to use the method for flip vertical or horizontal ... i have no idea how to do it and no matter what i do it will no work. And we are stuck with nested loops... almost everyone is going nuts trying to figure it out. please help please thanks!
Zestix Zestix

2019/3/8

#
Can't you just use the turn method?
jbiser361 jbiser361

2019/3/8

#
no we cannot i tried
Zestix Zestix

2019/3/8

#
Oh sorry misread everything, just look into the documentation for greenfootimage
Zestix Zestix

2019/3/8

#
Zestix wrote...
Oh sorry misread everything, just look into the documentation for greenfootimage
There is a method for mirroring pictures
danpost danpost

2019/3/8

#
jbiser361 wrote...
we are stuck with nested loops... almost everyone is going nuts trying to figure it out.
So ... , what have you tried using with nested loops? Show attempted code.
jbiser361 jbiser361

2019/3/9

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public void flipVerticle(){
            GreenfootImage noceMan = getBackground();
      ///  ng.mirrorVertically();
        for(int x = 0; x< getWidth(); x++){
            for(int y = 0; y < getHeight()/2;y++){
                 Color oldC = noceMan.getColorAt(x,y);
               Color flip = noceMan.getColorAt( getWidth()-x,y);
               noceMan.setColorAt(x,y ,flip);
               noceMan.setColorAt(x,getHeight()-y,oldC);
                 
 
            }
 
        }
 
    }
tried that
danpost danpost

2019/3/9

#
jbiser361 wrote...
<< Code Omitted >> tried that
If you are flipping vertically, then the x value should not change -- just the y's need swapped. Also, your bottom-up values are wrong. The coordinate of the maximum height is one less than the given height. Nonetheless, it would be easier to create a new image of the same size as that which you want to "flip" and do a standard nested loop:
1
2
3
4
5
6
7
8
9
GreenfootImage noceMan = getBackground();
int wide = noceMan.getWidth();
int high = noceMan.getHeight();
GreenfootImage vFlip = new GreenfootImage(wide, high);
for (int y=0; y<high; y++) for (int x=0; x<wide; x++)
{
    vFlip.setColorAt(x, high-1-y, noceMan.getColorAt(x, y);
}
setBackground(vFlip);
You need to login to post a reply.