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

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

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

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

        往返因數(shù)fraction

        比如動(dòng)態(tài)調(diào)整透明度、動(dòng)態(tài)修改顏色在動(dòng)畫的過程中可以設(shè)定起始與目標(biāo)值,通過fraction在0-1范圍內(nèi)進(jìn)行運(yùn)算進(jìn)行調(diào)整。
    以算法來描述則為
      起始值設(shè)為 init
      目標(biāo)值為 dest
      實(shí)際值為 actual
        actual=init*(1-fraction)+dest*fraction;
      比較明顯的例子為,將顏色從初始顏色動(dòng)態(tài)變化到目標(biāo)顏色
     
      Color startColor = Color.red;    // where we start
        Color endColor = Color.BLACK;         // where we end
        Color currentColor = startColor;
       ....
       描繪currentColor的一個(gè)圓
       在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í)器的時(shí)間參數(shù)動(dòng)態(tài)調(diào)整往返因數(shù)

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

    FeedBack:
    # re: swing Timer 與 animation 之 技巧一讓往返因數(shù) fraction從1到0再?gòu)?到1
    2008-02-17 12:28 | 519virus
    非常不錯(cuò)呀……   回復(fù)  更多評(píng)論
      
    主站蜘蛛池模板: 久久精品无码免费不卡| 97人妻无码一区二区精品免费| 精品久久久久久亚洲中文字幕 | 国产日韩AV免费无码一区二区| 精精国产www视频在线观看免费| www一区二区www免费| 中文在线免费不卡视频| 免费观看无遮挡www的视频| 欧美日韩国产免费一区二区三区 | 无码精品人妻一区二区三区免费看| 久草免费福利视频| 成年免费大片黄在线观看岛国| 日本午夜免费福利视频| 亚洲无线码在线一区观看| 亚洲一卡2卡3卡4卡乱码 在线| 亚洲国产aⅴ成人精品无吗| 国内精品99亚洲免费高清| 99久久精品日本一区二区免费| 亚洲国产91精品无码专区| 18gay台湾男同亚洲男同| 朝桐光亚洲专区在线中文字幕| 久热免费在线视频| 亚洲国产精品成人一区| 国产亚洲福利在线视频| 国产午夜不卡AV免费| 中文字幕亚洲专区| 美女视频黄a视频全免费网站一区| 91禁漫免费进入| 久久综合日韩亚洲精品色| 日韩毛片在线免费观看| 成年女人午夜毛片免费视频| 亚洲级αV无码毛片久久精品| 美女羞羞视频免费网站| 免费黄色大片网站| 亚洲videos| 67194成是人免费无码| 亚洲av无码一区二区三区观看| 免费精品无码AV片在线观看| 亚洲国产天堂在线观看| 免费观看91视频| 久久av无码专区亚洲av桃花岛|