単振動あそび3
パラメータいじるだけで色んなそれっぽい図がかけます。
単振動って何なのよ。というテスト
// forked from ledmosquito's 単振動あそび2
// forked from ledmosquito's 単振動あそび1
// パラメータいじるだけで色んなそれっぽい図がかけます。
//単振動って何なのよ。というテスト
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
[SWF(backgroundColor=0x000000,framerate=100)]
public class Tanshindo extends Sprite{
private var sprite:Sprite;
private var sprite2:Sprite;
private var spring:Springs;
private var spring2:Springs;
private var bitmap:Bitmap;
private var colorTr:ColorTransform;
public function Tanshindo() {
stage.width
sprite = new Sprite();
sprite.graphics.beginFill(0xffffff,1);
sprite.graphics.drawCircle(0, 0, 1);
sprite.x = 300;
sprite.y = 300;
sprite2 = new Sprite();
sprite2.addChild(sprite);
spring = new Springs();
spring.fc = 0.99995;
spring.k = 0.00000007;
spring2 = new Springs();
spring2.fc = 0.99995;
spring2.k = 0.05;
bitmap = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight,true,0x000000));
addChild(bitmap);
addEventListener('enterFrame', loop);
}
private function loop(e:Event):void {
for (var i:Number = 0; i < 400; i++ ) {
sprite.x = spring.run() * stage.stageWidth/2 + stage.stageWidth/2;
sprite.y = spring2.run() * stage.stageHeight/2 + stage.stageHeight/2;
bitmap.bitmapData.draw(sprite2);
}
//bitmap.bitmapData.applyFilter(bitmap.bitmapData, bitmap.getRect(bitmap) , new Point(), new BlurFilter(1.05,1.05));
}
}
}
/**
* ばね運動
*/
class Springs {
//ふり幅
private var _f:Number = 1;
//バネの長さ
private var _v:Number = 0;
//バネ定数
private var _k:Number = 1;
//摩擦力
private var _fc:Number = 1;
public function Springs() {
}
public function run():Number {
_v -= _k * _f;
_f += _v;
_f *= _fc;
return _f;
}
/**
* バネ定数
*/
public function set k(value:Number):void {
_k = value;
}
/**
* 摩擦
*/
public function set fc(value:Number):void {
_fc = value;
}
}