📄 rotation2.java
字号:
package com.midp;
public class Rotation2 {
/**
* SIN TABLE 放大了255倍
*/
public final static int SIN_TABLE[] = {
0, 4, 8, 13, 17, 22, 26, 31, 35, 39,
44, 48, 53, 57, 61, 65, 70, 74, 78, 83,
87, 91, 95, 99, 103, 107, 111, 115, 119, 123,
127, 131, 135, 138, 142, 146, 149, 153, 156, 160,
163, 167, 170, 173, 177, 180, 183, 186, 189, 192,
195, 198, 200, 203, 206, 208, 211, 213, 216, 218,
220, 223, 225, 227, 229, 231, 232, 234, 236, 238,
239, 241, 242, 243, 245, 246, 247, 248, 249, 250,
251, 251, 252, 253, 253, 254, 254, 254, 254, 254,
255, 254, 254, 254, 254, 254, 253, 253, 252, 251,
251, 250, 249, 248, 247, 246, 245, 243, 242, 241,
239, 238, 236, 234, 232, 231, 229, 227, 225, 223,
220, 218, 216, 213, 211, 208, 206, 203, 200, 198,
195, 192, 189, 186, 183, 180, 177, 173, 170, 167,
163, 160, 156, 153, 149, 146, 142, 138, 135, 131,
127, 123, 119, 115, 111, 107, 103, 99, 95, 91,
87, 83, 78, 74, 70, 65, 61, 57, 53, 48,
44, 39, 35, 31, 26, 22, 17, 13, 8, 4,
0, -4, -8, -13, -17, -22, -26, -31, -35, -39,
-44, -48, -53, -57, -61, -65, -70, -74, -78, -83,
-87, -91, -95, -99, -103, -107, -111, -115, -119, -123,
-127, -131, -135, -138, -142, -146, -149, -153, -156, -160,
-163, -167, -170, -173, -177, -180, -183, -186, -189, -192,
-195, -198, -200, -203, -206, -208, -211, -213, -216, -218,
-220, -223, -225, -227, -229, -231, -232, -234, -236, -238,
-239, -241, -242, -243, -245, -246, -247, -248, -249, -250,
-251, -251, -252, -253, -253, -254, -254, -254, -254, -254,
-255, -254, -254, -254, -254, -254, -253, -253, -252, -251,
-251, -250, -249, -248, -247, -246, -245, -243, -242, -241,
-239, -238, -236, -234, -232, -231, -229, -227, -225, -223,
-220, -218, -216, -213, -211, -208, -206, -203, -200, -198,
-195, -192, -189, -186, -183, -180, -177, -173, -170, -167,
-163, -160, -156, -153, -149, -146, -142, -138, -135, -131,
-127, -123, -119, -115, -111, -107, -103, -99, -95, -91,
-87, -83, -78, -74, -70, -65, -61, -57, -53, -48,
-44, -39, -35, -31, -26, -22, -17, -13, -8, -4
};
public static int TRANSPARENT = 0;
public static int getRadius(int _width,int _height)
{
return (int)Math.sqrt(_width*_width + _height*_height);
}
public static int[] rotate(int[] _pixels,int _width,int _height,int _angle)
{
int i,j;
int r = getRadius(_width,_height);
int[] newPixels = new int[r*r];
for(i = 0; i < newPixels.length;i++)
{
newPixels[i] = (TRANSPARENT)<<24;
}
int w = _width<<16;
int h = _height<<16;
int x,y;
int tmp_sin = SIN_TABLE[_angle%360]<<8;
int tmp_cos = SIN_TABLE[(_angle + 90) % 360]<<8;
for(i = 0;i < r;i++)
{
x = (-r/2)*tmp_cos + (i - r/2)*tmp_sin;
y = (r/2)*tmp_sin + (i - r/2)*tmp_cos;
for(j = 0;j < r;j++)
{
if(x >= -w/2&&x< w/2&&y >= -h/2&&y< h/2)
{
int k = ((y>>16)+_height/2)*_width+(x>>16)+_width/2;
newPixels[i*r + j] = _pixels[k];
}
x += tmp_cos;
y -= tmp_sin;
}
}
return newPixels;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -