Sample(ランダムカラーとストップ&スタート追加)
練習
Flash Math & Physics Design:ActionScript 3.0による数学・物理学表現[入門編]
http://www.amazon.co.jp/Flash-Math-Physics-Design-3-0%E3%81%AB%E3%82%88%E3%82%8B%E6%95%B0%E5%AD%A6%E3%83%BB%E7%89%A9%E7%90%86%E5%AD%A6%E8%A1%A8%E7%8F%BE/dp/4797351411
/**
* Copyright mattodesign ( http://wonderfl.net/user/mattodesign )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/989l
*/
//練習
//Flash Math & Physics Design:ActionScript 3.0による数学・物理学表現[入門編]
//http://www.amazon.co.jp/Flash-Math-Physics-Design-3-0%E3%81%AB%E3%82%88%E3%82%8B%E6%95%B0%E5%AD%A6%E3%83%BB%E7%89%A9%E7%90%86%E5%AD%A6%E8%A1%A8%E7%8F%BE/dp/4797351411
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.ColorTransform;
import flash.events.MouseEvent;
public class Sample extends Sprite {
var circle:Sprite;
var ookisa:Number = 0;
var timer:Timer;
var randomColor:int = Math.random() * 0xFFFFFF;
var r_multiplier:Number;
var g_multiplier:Number;
var b_multiplier:Number;
var timerFlg:Boolean;
//コンストラクタ
public function Sample():void {
//stage初期化
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
//circle作成
circle = new Sprite();
circle.graphics.beginFill(randomColor);
circle.graphics.drawCircle(0, 0, 20);
circle.graphics.endFill();
addChild(circle);
circle.addEventListener(MouseEvent.CLICK, stop);
circle.buttonMode = true;
//1秒間に30回loopを実行
timer = new Timer(33);
timer.addEventListener(TimerEvent.TIMER, loop);
timer.start();
}
function stop(event:MouseEvent):void {
timerFlg = timer.running;
if(timerFlg){
timer.stop();
}else {
timer.start();
}
}
function loop(event:TimerEvent):void {
ookisa += 0.05;
r_multiplier = Math.random() * 1;
g_multiplier = Math.random() * 1;
b_multiplier = Math.random() * 1;
if (ookisa > 10) {
ookisa = 0;
}
circle.transform.colorTransform = new ColorTransform(r_multiplier, g_multiplier, b_multiplier);
circle.x = this.mouseX;
circle.y = this.mouseY;
circle.scaleX = circle.scaleY = ookisa;
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
}
}
}