0

画像を 90 度回転する方法は既にありますが、180 度回転する方法と 270 度回転する方法を別々に作成する必要があります。90度を繰り返すことでこれができると思ったのですが、これは初めてでよくわかりません。

私の90度コード:

    public Picture rotateRight90()
  {
   Picture rotated = new Picture (getHeight(), getWidth());

   for (int x = 0, roty = 0; x < getWidth(); x++, roty++)
   {
    for ( int y = 0, rotx = getHeight() - 1; y < getHeight(); y++, rotx--)
    {
       Pixel orig = getPixel(x,y);
       Pixel rotPix = rotated.getPixel (rotx, roty);
       rotPix.setColor(orig.getColor());
    }
   }
   return rotated;
  }

私の試みた回転180コード:

     public Picture rotate180()
 {
   Picture rotated = new Picture (getHeight(), getWidth());

   for (int z = 0; z < 2; z++)
   {
     for (int x = 0, roty = 0; x < getWidth(); x++, roty++)
   {
    for ( int y = 0, rotx = getHeight() - 1; y < getHeight(); y++, rotx--)
    {
       Pixel orig = getPixel(x,y);
       Pixel rotPix = rotated.getPixel (rotx, roty);
       rotPix.setColor(orig.getColor());
    }
   }
   }
   return rotated;
  }
4

1 に答える 1