<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    筆頭。。
    實踐啟示
    posts - 14,comments - 3,trackbacks - 0
    動畫的實現(xiàn)上來說,是設置定時器進行刷新.
    對于Swing程序來說java.swing.Timer類保證了線程在swing調(diào)用上的安全性。通過時間參數(shù)的設置時間動態(tài)定時刷新,
    對于動態(tài)往復描繪來說,比如類似于動態(tài)的顏色變化,動態(tài)的進行透明變化之類的周期性刷新來說,一般需要幾個條件
    1.動畫的周期性
    2.動畫的當前狀態(tài)在起始狀態(tài)和目標狀態(tài)之間
    實現(xiàn)上需要這么幾個參數(shù)
    • 起始時間 animation startTime
    • 當前時間 currentime
    • 動畫周期 animation duration
    • 往返因數(shù) fraction

        往返因數(shù)fraction

        比如動態(tài)調(diào)整透明度、動態(tài)修改顏色在動畫的過程中可以設定起始與目標值,通過fraction在0-1范圍內(nèi)進行運算進行調(diào)整。
    以算法來描述則為
      起始值設為 init
      目標值為 dest
      實際值為 actual
        actual=init*(1-fraction)+dest*fraction;
      比較明顯的例子為,將顏色從初始顏色動態(tài)變化到目標顏色
     
      Color startColor = Color.red;    // where we start
        Color endColor = Color.BLACK;         // where we end
        Color currentColor = startColor;
       ....
       描繪currentColor的一個圓
       在Timer的actionPerform里調(diào)整currentColor
       
    // interpolate between start and end colors with current fraction
            int red = (int)(fraction * endColor.getRed() + 
                    (
    1 - fraction) * startColor.getRed());
            
    int green = (int)(fraction * endColor.getGreen() + 
                    (
    1 - fraction) * startColor.getGreen());
            
    int blue = (int)(fraction * endColor.getBlue() + 
                    (
    1 - fraction) * startColor.getBlue());
            
    // set our new color appropriately
            currentColor = new Color(red, green, blue);

    通過定時器的時間參數(shù)動態(tài)調(diào)整往返因數(shù)

        通過時間參數(shù)進行計算
        如下代碼所示,在Timer的actionPerform里實現(xiàn)
                long currentTime = System.nanoTime() / 1000000;
                
    long totalTime = currentTime - animationStartTime;
                //調(diào)整周期的起始時間
                if (totalTime > animationDuration) {
                    animationStartTime 
    = currentTime;
                }
                
    float fraction = (float)totalTime / animationDuration;
                fraction 
    = Math.min(1.0f, fraction);
         注意當前只是計算出了fraction,如何使因子在1-0和0-1之間往復變化呢
        以下代碼實現(xiàn)了該算法
       
        // This calculation will cause alpha to go from 1 to 0 and back to 1
                
    // as the fraction goes from 0 to 1
                alpha = Math.abs(1 - (2 * fraction));
          
        //repaint();//重新繪制


    posted on 2008-02-14 12:00 如果有一天de 閱讀(1320) 評論(1)  編輯  收藏 所屬分類: richclient

    FeedBack:
    # re: swing Timer 與 animation 之 技巧一讓往返因數(shù) fraction從1到0再從0到1
    2008-02-17 12:28 | 519virus
    非常不錯呀……   回復  更多評論
      
    主站蜘蛛池模板: 国产免费无码AV片在线观看不卡| 久久精品国产亚洲av天美18| 亚洲伊人久久精品| 亚洲AV人无码激艳猛片| 一级黄色免费大片| 最近中文字幕电影大全免费版 | 最近免费中文字幕中文高清| 日本高清高色视频免费| 亚洲精品V欧洲精品V日韩精品 | 亚洲卡一卡2卡三卡4卡无卡三| 亚洲精品免费在线视频| 中国xxxxx高清免费看视频| 国产精品视_精品国产免费| 亚洲AV日韩综合一区| www亚洲精品少妇裸乳一区二区 | 又黄又爽一线毛片免费观看| 美女被免费视频网站| 亚洲色图综合在线| 亚洲成av人片在www鸭子| 日韩伦理片电影在线免费观看| 亚洲中文久久精品无码ww16| 国产色爽免费无码视频| 亚洲综合综合在线| 成年女人免费视频播放77777| 亚洲综合久久综合激情久久 | 99精品视频在线观看免费播放| heyzo亚洲精品日韩| 成av免费大片黄在线观看| 久久亚洲精品国产精品黑人| 成人在线免费看片| 亚洲日本精品一区二区| 亚洲人成电影网站免费| 特级毛片免费观看视频| 久久精品国产亚洲av麻| 抽搐一进一出gif免费视频| 67pao强力打造67194在线午夜亚洲| 日本XXX黄区免费看| 亚洲性一级理论片在线观看| 一区二区在线免费观看| 一本天堂ⅴ无码亚洲道久久| 1区2区3区产品乱码免费|