バネ運動基礎1(+摩擦)
題名のまんま
♥0 |
Line 47 |
Modified 2011-05-13 00:44:05 |
MIT License
archived:2017-03-20 13:49:54
ActionScript3 source code
/**
* Copyright Nowloading_ ( http://wonderfl.net/user/Nowloading_ )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fLdV
*/
package {
import flash.display.Sprite;
import flash.events.Event;
public class FlashTest extends Sprite {
private var ball:Ball;
private var vx:Number = 0;
private var tx:Number = stage.stageWidth/2;
private var spring:Number = 0.02;
//摩擦ありの場合
private var friction:Number = 0.98;
public function FlashTest() {
init();
}
public function init():void{
graphics.lineStyle(1,0x000000);
graphics.drawCircle(stage.stageWidth/2,stage.stageHeight/2,3);
ball = new Ball(20,0x00ff00);
ball.x=40;
ball.y=stage.stageHeight/2;
addChild(ball);
addEventListener(Event.ENTER_FRAME,oEF);
}
private function oEF(e:Event):void{
var ax:Number=(tx - ball.x)*spring;
vx += ax;
vx *= friction;
ball.x += vx;
}
}
}
import flash.display.Sprite;
class Ball extends Sprite{
public var radius:Number;
public var color:uint;
public var vx:Number =0;
public var vy:Number =0;
public function Ball(radius:Number = 40,color:uint = 0xff0000){
this.radius = radius;
this.color = color;
init();
}
public function init():void{
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}
}