flash on 2012-1-27
背景色かわらない…
/**
* Copyright buddylee101 ( http://wonderfl.net/user/buddylee101 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/iEE3
*/
package
{
import flash.display.*;
import flash.events.*;
import caurina.transitions.Tweener;
[SWF(backgroundColor = "#111111", frameRate = "60")]
public class Main extends Sprite
{
private var _pc:PointCircle;
public function Main():void
{
if (stage) _init();
else addEventListener(Event.ADDED_TO_STAGE, _init,false,0,true);
}
private function _init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, _init);
// entry point
//背景色用
var bmd:BitmapData = new BitmapData(465, 465, false, 0xFF111111);
var bg:Bitmap = new Bitmap(bmd);
addChild(bg);
_pc = new PointCircle();
_pc.x = 100;
_pc.y = 100;
addChild(_pc);
var b1_mc:Sprite = new Sprite();
b1_mc.graphics.beginFill(0x444444);
b1_mc.graphics.drawCircle(0,0,10);
b1_mc.graphics.endFill();
b1_mc.x = 40; b1_mc.y = 210; b1_mc.buttonMode = true;
addChild(b1_mc);
var b2_mc:Sprite = new Sprite();
b2_mc.graphics.beginFill(0x444444);
b2_mc.graphics.drawCircle(0,0,10);
b2_mc.graphics.endFill();
b2_mc.x = 80; b2_mc.y = 210; b2_mc.buttonMode = true;
addChild(b2_mc);
b1_mc.addEventListener(MouseEvent.CLICK, _click);
b2_mc.addEventListener(MouseEvent.CLICK, _click2);
}
private function _click(e:MouseEvent):void
{
var _a:int = Math.floor(Math.random() * 5) + 1;
var _b:int = Math.floor(Math.random() * 5) + 1;
var _c:int = Math.floor(Math.random() * 5) + 1;
var _d:int = Math.floor(Math.random() * 5) + 1;
var _e:int = Math.floor(Math.random() * 5) + 1;
_pc.showData(_a, _b, _c, _d, _e);
}
private function _click2(e:MouseEvent):void
{
_pc.hideData();
}
}
}
import flash.display.*;
import flash.events.*;
import flash.filters.*;
class PointCircle extends Sprite
{
private var _circlesArr:Array = new Array();//グラフの円
private var _linesArr:Array = new Array();//グラフの線
private var _dataArr:Array = new Array();//値
private var _nowArr:Array = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]];
private var _goalArr:Array = new Array();
private var _dataPenta:Shape;//値の五角形
private var _circleWrap:Sprite;
private var _lineWrap:Sprite;
private var _minR:uint = 15;
private var _rad:Number = Math.PI / 180;
private var _rate:Number = 0.2;
private var _filterAlpha:Number = 0;
private var _filterAlphaChange:Number = 0.025;
public function PointCircle()
{
if (stage) _init();
else addEventListener(Event.ADDED_TO_STAGE, _init, false, 0, true);
}
private function _init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, _init);
_makeCircle();
}
private function _makeCircle():void
{
_circleWrap = new Sprite();
addChild(_circleWrap);
_lineWrap = new Sprite();
addChild(_lineWrap);
_dataPenta = new Shape();
//_dataPenta.graphics.lineStyle(1, 0x333333);
//_dataPenta.graphics.beginFill(0x333333, 0.5);
addChild(_dataPenta);
for (var i:int = 0; i < 5; i++) {
var circle:Shape = new Shape();
var r:uint = _minR * (5 - i);
circle.graphics.lineStyle(1, 0x444444, 1, true, "none");
circle.graphics.beginFill(0x222222);
circle.graphics.drawCircle(0, 0, r);
_circleWrap.addChild(circle);
_circlesArr.push(circle);
var line:Shape = new Shape();
var a:Number = 360 / 5 * i;
line.graphics.lineStyle(1, 0x444444, 1, true, "none");
line.graphics.moveTo(0, 0);
line.graphics.lineTo(0, -_minR * 5);
line.rotation = a;
_lineWrap.addChild(line);
_linesArr.push(line);
}
}
public function showData(a:Number = 0, b:Number = 0, c:Number = 0, d:Number = 0, e:Number = 0):void
{
removeEventListener(Event.ENTER_FRAME, _showLoop);
removeEventListener(Event.ENTER_FRAME, _hideLoop);
_dataArr.length = 0;
_dataArr.push(a, b, c, d, e);
_goalArr.length = 0;
for (var i:int = 0; i < 5; i++) {
var __a:Number = 360 / 5 * i - 90;
var __x:Number = Math.cos(__a * _rad) * _dataArr[i] * _minR;
var __y:Number = Math.sin(__a * _rad) * _dataArr[i] * _minR;
_goalArr.push([__x, __y]);
}
addEventListener(Event.ENTER_FRAME, _showLoop, false, 0, true);
}
private function _showLoop(e:Event):void
{
_filterAlpha += _filterAlphaChange;
if ((_filterAlpha <= -0.5) || (_filterAlpha >= 1)) {
_filterAlphaChange *= -1;
}
_dataPenta.filters = [];
_dataPenta.filters = [new GlowFilter(0xe8f8ff, _filterAlpha, 6, 6, 2,4)];
_dataPenta.graphics.clear();
_dataPenta.graphics.lineStyle(1, 0x3ec6ff);
_dataPenta.graphics.beginFill(0x3ec6ff, 0.5);
for (var i:int = 0; i < 5; i++) {
var __x:Number = _nowArr[i][0] += (_goalArr[i][0] - _nowArr[i][0]) * _rate;
var __y:Number = _nowArr[i][1] += (_goalArr[i][1] - _nowArr[i][1]) * _rate;
if (i != 0) {
_dataPenta.graphics.lineTo(__x, __y);
}else {
_dataPenta.graphics.moveTo(__x, __y);
}
}
_dataPenta.graphics.endFill();
}
public function hideData():void
{
removeEventListener(Event.ENTER_FRAME, _showLoop);
removeEventListener(Event.ENTER_FRAME, _hideLoop);
addEventListener(Event.ENTER_FRAME, _hideLoop, false, 0, true);
}
private function _hideLoop(e:Event):void
{
_filterAlpha += _filterAlphaChange;
if ((_filterAlpha <= -0.5) || (_filterAlpha >= 1)) {
_filterAlphaChange *= -1;
}
_dataPenta.filters = [];
_dataPenta.filters = [new GlowFilter(0xe8f8ff, _filterAlpha, 6, 6, 2,4)];
_dataPenta.graphics.clear();
_dataPenta.graphics.lineStyle(1, 0x3ec6ff);
_dataPenta.graphics.beginFill(0x3ec6ff, 0.5);
for (var i:int = 0; i < 5; i++) {
var __x:Number = _nowArr[i][0] += (0 - _nowArr[i][0]) * _rate;
var __y:Number = _nowArr[i][1] += (0 - _nowArr[i][1]) * _rate;
if (i != 0) {
_dataPenta.graphics.lineTo(__x, __y);
}else {
_dataPenta.graphics.moveTo(__x, __y);
}
}
_dataPenta.graphics.endFill();
if ((Math.abs(0 - _nowArr[0][0]) <= 0.2) && (Math.abs(0 - _nowArr[0][1]) <= 0.2)) {
_filterAlpha = 0;
_filterAlphaChange = Math.abs(_filterAlphaChange);
removeEventListener(Event.ENTER_FRAME, _hideLoop);
_dataPenta.graphics.clear();
_dataPenta.filters = [];
trace("remove");
}
}
}