<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
    動畫的實現上來說,是設置定時器進行刷新.
    對于Swing程序來說java.swing.Timer類保證了線程在swing調用上的安全性。通過時間參數的設置時間動態定時刷新,
    對于動態往復描繪來說,比如類似于動態的顏色變化,動態的進行透明變化之類的周期性刷新來說,一般需要幾個條件
    1.動畫的周期性
    2.動畫的當前狀態在起始狀態和目標狀態之間
    實現上需要這么幾個參數
    • 起始時間 animation startTime
    • 當前時間 currentime
    • 動畫周期 animation duration
    • 往返因數 fraction

        往返因數fraction

        比如動態調整透明度、動態修改顏色在動畫的過程中可以設定起始與目標值,通過fraction在0-1范圍內進行運算進行調整。
    以算法來描述則為
      起始值設為 init
      目標值為 dest
      實際值為 actual
        actual=init*(1-fraction)+dest*fraction;
      比較明顯的例子為,將顏色從初始顏色動態變化到目標顏色
     
      Color startColor = Color.red;    // where we start
        Color endColor = Color.BLACK;         // where we end
        Color currentColor = startColor;
       ....
       描繪currentColor的一個圓
       在Timer的actionPerform里調整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);

    通過定時器的時間參數動態調整往返因數

        通過時間參數進行計算
        如下代碼所示,在Timer的actionPerform里實現
                long currentTime = System.nanoTime() / 1000000;
                
    long totalTime = currentTime - animationStartTime;
                //調整周期的起始時間
                if (totalTime > animationDuration) {
                    animationStartTime 
    = currentTime;
                }
                
    float fraction = (float)totalTime / animationDuration;
                fraction 
    = Math.min(1.0f, fraction);
         注意當前只是計算出了fraction,如何使因子在1-0和0-1之間往復變化呢
        以下代碼實現了該算法
       
        // 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 閱讀(1311) 評論(1)  編輯  收藏 所屬分類: richclient

    FeedBack:
    # re: swing Timer 與 animation 之 技巧一讓往返因數 fraction從1到0再從0到1
    2008-02-17 12:28 | 519virus
    非常不錯呀……   回復  更多評論
      
    主站蜘蛛池模板: 午夜成年女人毛片免费观看 | 亚洲人成人伊人成综合网无码| 亚洲综合一区二区三区四区五区| 一级毛片在线免费视频| 亚洲毛片免费观看| 国产91精品一区二区麻豆亚洲| 亚洲最大免费视频网| 一级毛片免费不卡| 亚洲欧洲自拍拍偷精品 美利坚| 亚洲AV无码成人专区| 99久久免费国产精品热| 免费毛片在线视频| 亚洲AV无码AV男人的天堂不卡| 最近2019中文字幕免费大全5| 亚洲国产精品不卡毛片a在线| 99999久久久久久亚洲| 日本免费一区二区三区四区五六区| 一区二区三区亚洲视频| 亚洲综合中文字幕无线码| 成人性生免费视频| 色偷偷女男人的天堂亚洲网| 四虎成人免费影院网址| 免费夜色污私人影院网站电影| 日本高清免费不卡视频| 国产AV旡码专区亚洲AV苍井空| 国产91色综合久久免费| 久久精品a亚洲国产v高清不卡| 黄网站色视频免费在线观看的a站最新 | 国产精品极品美女免费观看| 亚洲精品午夜视频| 日韩免费人妻AV无码专区蜜桃| 亚洲成a人片7777| 国产午夜影视大全免费观看| 亚洲色一区二区三区四区 | 成人毛片18女人毛片免费96| 国产AV日韩A∨亚洲AV电影 | 亚洲中文字幕在线观看| 永久免费无码日韩视频| 亚洲成a人片在线观看久| 香蕉免费一区二区三区| 久久久无码精品亚洲日韩京东传媒|