
A 回答 (2件)
- 最新から表示
- 回答順に表示
No.2
- 回答日時:
# コードは詳しく読んでません。
ずばりのコードを書く気もありません。あくまで考え方のみです。あしからず。Nフレーム後の雪の座標をあらかじめテーブルに持っておくのも一つの手ですね。
この場合全部が同じ動きになってしまうとつまらないので、適度に乱数で揺らぎを与えてみることになるかと思います。
この回答への補足
「乱数で揺らぎ」を考えてました。
Y軸方向もステップ量を変化させることで、考えて
リサージュー曲線を思い出しました
まぁ~これで充分かな~と・・・。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<title>TEST</title>
<style type="text/css">
body{ background-color:black; overflow:hidden; }
</style>
<body>
<script type="text/javascript">
//@cc_on
var i,snow =30;
var sin =[];
for( i=0; i<361; i++) sin[i]=Math.sin(i*3.14159/180);
for( i=0; i<snow; i++) new bringSnow();
function bringSnow(){
this.go = function(){
this.y += this.z/2 +2;
this.p+=2;
if( this.y > document.documentElement.clientHeight-60) this.init();
this.e.style.top = this.y + (sin[this.p%360]*6*this.z|0) +'px';
this.e.style.left = this.x + (sin[this.p*2%360]*6*this.z|0) +'px';
}
this.init = function(n){
this.p =0;
this.y = Math.random() * document.documentElement.clientHeight * ( n != undefined ) |0;
this.x = (Math.random() * document.documentElement.clientWidth |0)-60;
this.z = (Math.random() * 5 |0) + 1;
var op = (Math.random() * 80 |0) + 21;
this.e.style.fontSize = this.z * 7 + 'px';
this.e.style./*@if(1) filter = 'alpha(opacity='+ op+ ')'; @else @*/
MozOpacity = this.e.style.opacity = op / 100;/*@end@*/
}
var ne = document.createElement('div');
ne.appendChild( document.createTextNode( '*' ) );
ne.style.color = 'white';
ne.style.position = 'absolute';
this.e = document.body.appendChild( ne );
this.init(1);
setInterval((function(f_){ return function(){ f_.go.call(f_);}})(this), (Math.random() * 30 |0) +16)
}
</script>
No.1
- 回答日時:
関数のオーバーヘッドのみが問題なら、あらかじめ配列に用意してしまうのも一つの手ですよ。
昔は速度を稼ぐために128倍整数化したサインテーブルをxsin[0..359]のような配列に確保するなどしたものです。
この回答への補足
こんな感じでしょうか?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<title>TEST</title>
<style type="text/css">
body { background-color:black; overflow:hidden; }
</style>
<script type="text/javascript">
//@cc_on
var i,snow =50;
var sin =[];
for( i=0; i<361; i++) sin[i]=Math.sin(i*3.14159/180);
for( i=0; i<snow; i++) new bringSnow();
function bringSnow(){
this.go = function(){
this.y += this.z ;
if( this.y > document.documentElement.clientHeight-60) this.init();
this.e.style.top = this.y +'px';
this.e.style.left = (this.x + sin[this.y%360|0]*this.z*10) +'px';
}
this.init = function(n){
this.p =0;
this.y = Math.random() * document.documentElement.clientHeight * ( n != undefined ) |0;
this.x = (Math.random() * document.documentElement.clientWidth |0)-60;
this.z = (Math.random() * 5 |0) + 1;
var op = (Math.random() * 80 |0) + 21;
this.e.style.fontSize = this.z * 7 + 'px';
this.e.style./*@if(1) filter = 'alpha(opacity='+ op+ ')'; @else @*/
MozOpacity = this.e.style.opacity = op / 100;/*@end@*/
}
var ne = document.createElement('div');
ne.appendChild( document.createTextNode( '*' ) );
ne.style.color = 'white';
ne.style.position = 'absolute';
this.e = document.body.appendChild( ne );
this.init(1);
setInterval((function(f_){ return function(){ f_.go.call(f_);}})(this), (Math.random() * 30 |0) +16)
}
</script>
ご回答ありがとうございます。
雪の描くラインをアルファベットの「J]のようにしてみたいのです。
落ちては左右どちらかにカーブして、せり上がるまではいかなくても
よいのですが、そこで落下速度が落ち、また下に落ちるような・・・
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
復数の配列をJson形式にまとめたい
-
配列の1要素を代入した変数を使...
-
イベントが初めの一回しか起き...
-
関数名をテキストから読み込む...
-
static constメンバ変数(配列)...
-
【JavaScript】数当てゲームを...
-
ASP+アクセスでのSQLコメントに...
-
1.gifをホームページ上でランダ...
-
シューティングゲームの作り方
-
構造体を引数で関数へ渡す
-
Latexに関する質問です。
-
JavaScriptの値を表示するには
-
Matlabで自作関数をオーバーロード
-
[初心者]javascriptのfor文でな...
-
JavaScriptで連続する空白を、h...
-
jqGridについて
-
Ajaxにおける非同期通信で、数...
-
htaccessのリダイレクトがルー...
-
APIを使って埋め込んだグーグル...
-
window.onloadを複数実行したい...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
同じIDで定義した要素の配列を...
-
jspからjavascriptの変数引継ぎ
-
C#テキストボックスの文字を配...
-
undefinedを表示させない方法は...
-
雪を降らせるみたいな、ゆらゆ...
-
JavaScriptで簡単なクイズを作...
-
1から20までの整数から、重複な...
-
javascriptで行を抽出したいです。
-
Perlの配列をJavaScriptに渡せ...
-
javascript 変数名の連結をしたい
-
jQueryで文字数カウンタ(複数...
-
配列データの利用方法
-
時計を複数表示する場合
-
("Scripting.Dictionary")につ...
-
順列生成アルゴリズムについて...
-
配列の数ではなく、文字列の長...
-
JSONデータを50音順でソートしたい
-
総当りの配列を返す関数の作成
-
javascriptで2つのArrayの...
-
JavaScriptにおける[] とか :...
おすすめ情報