日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java图形旋转动画_Java动画:旋转图像

發布時間:2023/12/2 java 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java图形旋转动画_Java动画:旋转图像 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我將假設您了解如何旋轉圖像一次.如果你不這樣做,你可以通過快速谷歌搜索找到它.

您需要的是一個為您旋轉它的后臺進程.它的工作原理如下:

/**

* Warning - this class is UNSYNCHRONIZED!

*/

public class RotatableImage {

Image image;

float currentDegrees;

public RotateableImage(Image image) {

this.image = image;

this.currentDegrees = 0.0f;

this.remainingDegrees = 0.0f;

}

public void paintOn(Graphics g) {

//put your code to rotate the image once in here, using current degrees as your rotation

}

public void spin(float additionalDegrees) {

setSpin(currentDegrees + additionalDegrees);

}

public void setSpin(float newDegrees) {

currentDegrees += additionalDegrees;

while(currentDegrees < 0f) currentDegrees += 360f;

while(currentDegrees >= 360f) currentDegrees -= 360f;

}

}

public class ImageSpinner implements Runnable {

RotateableImage image;

final float totalDegrees;

float degrees;

float speed; // in degrees per second

public ImageSpinner(RotatableImage image, float degrees, float speed) {

this.image = image;

this.degrees = degrees;

this.totalDegrees = degrees;

this.speed = speed;

}

public void run() {

// assume about 40 frames per second, and that the it doesn't matter if it isn't exact

int fps = 40;

while(Math.abs(degrees) > Math.abs(speed / fps)) { // how close is the degrees to 0?

float degreesToRotate = speed / fps;

image.spin(degreesToRotate);

degrees -= degreesToRotate;

/* sleep will always wait at least 1000 / fps before recalcing

but you have no guarantee that it won't take forever! If you absolutely

require better timing, this isn't the solution for you */

try { Thread.sleep(1000 / fps); } catch(InterruptedException e) { /* swallow */ }

}

image.setSpin(totalDegrees); // this might need to be 360 - totalDegrees, not sure

}

}

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的java图形旋转动画_Java动画:旋转图像的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。