2009-08-27 2 views
2

私はランダムに画面の周りに浮かんでいるいくつかの形を持つことに取り組んでいます。最終的に彼らは相互に作用し、onclick機能を持ちます。私は画面上でレンダリングするサークルを得ることができますが、動きを持たせることはできません。 .animate()関数はここで必要なものではないようです。Raphael JSを使用して画面の周りに浮動小数点を浮動させる

誰も私がこれについてどうやって行くのか知っていますか?

jQuery(function ($) { 

    // Global Vars 
    var items = 30, 
    width = window.innerWidth, 
    height = window.innerHeight, 
    paper = Raphael("galaxy", width, height), 
    frameRate = 100, 
    i, 
    galaxy = [], 
    star = [], 
    stars = []; 

    // Do some variants for each item 
    for (i = 0; i<items; i++) { 
     stars[i] = { 
      x : Math.random() * width, 
      y : Math.random() * height, 
      r : Math.random()*255, 
      g : Math.random()*255, 
      b : Math.random()*255, 
      size : Math.random() * 20 
     } 
    } 

    // Creates canvas 320 × 200 at 10, 50 
    // Creates circle at x = 50, y = 40, with radius 10 
    for (i = 0; i<items; i++) { 
     star[i] = paper.circle(stars[i].x, stars[i].y, stars[i].size); 
     star[i].attr("fill", "rgb("+stars[i].r+", "+stars[i].g+", "+stars[i].b+")"); 
     star[i].attr("stroke", "none"); 

    }//end for 

}); 

答えて

3

それがアニメーションで仕事ができる():ここで

は私が持っているものです。例:これを上記の関数に追加します。

(function anim() { 
    for (i = 0; i<items; i++) { 
     newX = Math.random() * width; 
     newY = Math.random() * height; 
     star[i].animate({cx: newX, cy: newY}, 1000); 
    } 
    setTimeout(anim, 1000); 
})(); 

あなたのサークルが飛びます。もちろん、それは本当に浮かんだり、相互作用したりするのにはまだまだ長い道のりですが、それはおそらく出発点です。

+0

うわー、これは完璧です。私はsetTimeoutを使用してさまざまな組み合わせを試みたが、私はそれを正しく得ることはできませんでした。ありがとう! –

関連する問題