长时间以来工作一直想用j2me实现表盘显示的功能,但一直没有空下来去想过,网上查来查去也没有个好的答案。
因为没有double的值的显示,所以在实现上面不能都很平滑的显示。但是最主要的还是通过三角函数来实现设定
坐标值显示。以内切四边形的方式来求坐标。
其中提供该方法给大家参考,如果谁有更好的实现方式,请留言交流。
public int[] setPosition(int time) {
if (time == 0) {
position[0] = 0;
position[1] = -LENGTH_SECONDHAND;
}
if (time > 0 && time <= 15) {
position[0] = (int) (Math
.floor((Math.sin(Math.toRadians(time * 6)) * LENGTH_SECONDHAND)));
position[1] = -(int) (Math
.floor((Math.cos(Math.toRadians(time * 6)) * LENGTH_SECONDHAND)));
}
if (time > 15 && time < 30) {
position[1] = (int) (Math
.floor((Math.sin(Math.toRadians((time - 15) * 6)) * LENGTH_SECONDHAND)));
position[0] = (int) (Math
.floor((Math.cos(Math.toRadians((time - 15) * 6)) * LENGTH_SECONDHAND)));
}
if (time == 30) {
position[0] = 0;
position[1] = LENGTH_SECONDHAND;
}
if (time > 30 && time < 45) {
position[0] = -((int) (Math
.floor((Math.sin(Math.toRadians((time - 30) * 6)) * LENGTH_SECONDHAND))));
position[1] = (int) (Math
.floor((Math.cos(Math.toRadians((time - 30) * 6)) * LENGTH_SECONDHAND)));
}
if (time == 45) {
position[0] = -LENGTH_SECONDHAND;
position[1] = 0;
}
if (time > 45 && time < 60) {
position[1] = -((int) (Math
.floor((Math.sin(Math.toRadians((time - 45) * 6)) * LENGTH_SECONDHAND))));
position[0] = -((int) (Math
.floor((Math.cos(Math.toRadians((time - 45) * 6)) * LENGTH_SECONDHAND))));
}
return position;
}
因为没有double的值的显示,所以在实现上面不能都很平滑的显示。但是最主要的还是通过三角函数来实现设定
坐标值显示。以内切四边形的方式来求坐标。
其中提供该方法给大家参考,如果谁有更好的实现方式,请留言交流。
public int[] setPosition(int time) {
if (time == 0) {
position[0] = 0;
position[1] = -LENGTH_SECONDHAND;
}
if (time > 0 && time <= 15) {
position[0] = (int) (Math
.floor((Math.sin(Math.toRadians(time * 6)) * LENGTH_SECONDHAND)));
position[1] = -(int) (Math
.floor((Math.cos(Math.toRadians(time * 6)) * LENGTH_SECONDHAND)));
}
if (time > 15 && time < 30) {
position[1] = (int) (Math
.floor((Math.sin(Math.toRadians((time - 15) * 6)) * LENGTH_SECONDHAND)));
position[0] = (int) (Math
.floor((Math.cos(Math.toRadians((time - 15) * 6)) * LENGTH_SECONDHAND)));
}
if (time == 30) {
position[0] = 0;
position[1] = LENGTH_SECONDHAND;
}
if (time > 30 && time < 45) {
position[0] = -((int) (Math
.floor((Math.sin(Math.toRadians((time - 30) * 6)) * LENGTH_SECONDHAND))));
position[1] = (int) (Math
.floor((Math.cos(Math.toRadians((time - 30) * 6)) * LENGTH_SECONDHAND)));
}
if (time == 45) {
position[0] = -LENGTH_SECONDHAND;
position[1] = 0;
}
if (time > 45 && time < 60) {
position[1] = -((int) (Math
.floor((Math.sin(Math.toRadians((time - 45) * 6)) * LENGTH_SECONDHAND))));
position[0] = -((int) (Math
.floor((Math.cos(Math.toRadians((time - 45) * 6)) * LENGTH_SECONDHAND))));
}
return position;
}