forked from: RollingBalls from: nengafl
/**
* Copyright hacker_yk666qry ( http://wonderfl.net/user/hacker_yk666qry )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7iXo
*/
// forked from cybernet's RollingBalls from: nengafl
package {
import flash.accessibility.Accessibility;
import flash.display.Sprite;
import flash.events.*;
import flash.text.*;
[SWF(backgroundColor="#666666", frameRate=10)]
public class RollingBalls extends Sprite {
public function RollingBalls() {
var tf:TextField = new TextField();
tf.x = 50;
tf.y = 20;
tf.width = 230;
tf.height = 50;
tf.textColor = 0x000000;
tf.text = "四辺形をマウスでクリックする毎に、\n"+
"色つきの円が放出されて坂を転がり\n"+
"落ちていきます。\n";
addChild(tf);
var bounding:Bounding = new Bounding();
bounding.rotation =15;
addChild(bounding);
stage.addEventListener(MouseEvent.CLICK,onClick);
}
private function onClick(evt:MouseEvent): void {
var bounding:Bounding = new Bounding();
bounding.rotation = 15;
addChild(bounding);
}
}
}
import flash.display.*;
class Ball extends Sprite {
public var radius: Number = 7+17*Math.random();
public function Ball(){
var mytama:Sprite = new Sprite();
var mt :Graphics = mytama.graphics;
mt.lineStyle();
mt.beginFill(0xFFFFFF*Math.random(), 0.5+ 0.5*Math.random()); //色,アルファ
mt.drawCircle(0,0,radius);
mt.endFill();
addChild(mytama);
}
}
import flash.events.*;
import flash.text.*;
class Bounding extends Sprite {
private var t:Number;
private var k:Number;
private var a:Number;
private var b:Number = 10;
private var w:Number;
private var ramda:Number;
private var ball:Ball = new Ball();
private var rr:Number = ball.radius;
public function Bounding(): void {
var box:Sprite= new Sprite();
box.graphics.moveTo(50,111);
box.graphics.lineStyle(0x000000,1);
box.graphics.lineTo(600,111);
box.graphics.beginFill(0x00FF00,1);
box.graphics.drawRect(50,106,30,30);
addChild(box);
box.addEventListener(MouseEvent.CLICK, clickListener);
}
private function clickListener(e:MouseEvent): void {
a = 10 + 90*Math.random();
w = 0.5 + 2.0*Math.random();
ramda = 0.05 + 0.175*Math.random();
t = 0;
k = 0.075 + 0.125*Math.random();
ball.x = 0;
ball.y = 0;//0;
addChild(ball);
addEventListener(Event.ENTER_FRAME,onRun,false,0,true);
}
private function onRun(e:Event):void {
t += k;
ball.x = 50+30*t;
ball.y = 113-rr-a*Math.exp(-ramda*t)*Math.abs(Math.sin(w*t));
addChild(ball);
if(t > 18){
removeEventListener(Event.ENTER_FRAME,onRun);
parent.removeChild(this);
}
}
}