forked from: WorldClock_WIF2010
日本(+9)とフランス(+2)の時間を表示させてください。
*
*
* 自由に使える素材は以下にあります。
*
* イラスト
*
* illust_barimi.png
* http://assets.wonderfl.net/images/related_images/0/0e/0e85/0e859cec4da398db9762ae1c9683f99f94b395a9
*
* illust_iizukayac.png
* http://assets.wonderfl.net/images/related_images/d/d6/d6c5/d6c5e2c6ac5d052f0ffbdae5634ffbc25a2afa46
*
* illust_kousho.png
* http://assets.wonderfl.net/images/related_images/c/c1/c1f5/c1f55ca807c76574b85876caa84cb5371aca857b
*
*
/**
* Copyright Murai ( http://wonderfl.net/user/Murai )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2lLF
*/
// forked from kousho's WorldClock_WIF2010
/**
*
* 日本(+9)とフランス(+2)の時間を表示させてください。
*
*
* 自由に使える素材は以下にあります。
*
* イラスト
*
* illust_barimi.png
* http://assets.wonderfl.net/images/related_images/0/0e/0e85/0e859cec4da398db9762ae1c9683f99f94b395a9
*
* illust_iizukayac.png
* http://assets.wonderfl.net/images/related_images/d/d6/d6c5/d6c5e2c6ac5d052f0ffbdae5634ffbc25a2afa46
*
* illust_kousho.png
* http://assets.wonderfl.net/images/related_images/c/c1/c1f5/c1f55ca807c76574b85876caa84cb5371aca857b
*
*
*/
package {
import flash.display.BlendMode;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.filters.BitmapFilter;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
[SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="30")]
public class WorldClock extends Sprite
{
private const LAG_JAPAN:Number = 9;
private const LAG_FRANCE:Number = 2;
private var jp:CircleChainClock;
private var fr:CircleChainClock;
private var _bmd:BitmapData;
private static const P:Point = new Point();
private static const BLUR:BitmapFilter = new BlurFilter(16, 16, 1);
private static const ALPHA:ColorTransform = new ColorTransform(1, 1, 1, 0.85, 0, 0, 0, 0);
public function WorldClock()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
init();
}
private function init():void {
addChild(jp = new CircleChainClock("JP", LAG_JAPAN, 0xFF0000,new Point(465*0.75,465*0.5)));
addChild(fr = new CircleChainClock("FR", LAG_FRANCE, 0x0000FF,new Point(465*0.25,465*0.5)));
_bmd = new BitmapData(465, 465, true, 0x00000000);
addChild(new Bitmap(_bmd));
addEventListener(Event.ENTER_FRAME, glower);
}
private function glower(e:Event):void {
_bmd.applyFilter(_bmd, _bmd.rect, P, BLUR);
_bmd.colorTransform(_bmd.rect, ALPHA);
_bmd.draw(jp.canvas);
_bmd.draw(fr.canvas);
}
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFormat;
internal class CircleChainClock extends Sprite {
private var font:Class;
public var textField:TextField = new TextField();
public var date:Date;
public var str:String = new String();
private var _scale:Number = 75;
private var _cx:Number;
private var _cy:Number;
private var Hs:Sprite = new Sprite();
private var Ms:Sprite = new Sprite();
private var Ss:Sprite = new Sprite();
private var MSs:Sprite = new Sprite();
private var country:String;
private var gmt:int;
private var color:uint;
private var center:Point;
public var canvas:Sprite = new Sprite();
public function CircleChainClock(country:String,gmt:int,color:uint,center:Point) {
this.center = center;
this.color = color;
this.gmt = gmt;
this.country = country;
var format:TextFormat = new TextFormat();
format.font = "_sans";
format.align = "center";
format.size = 20;
format.color = color;
//
textField.defaultTextFormat = format;
textField.text = " ";
textField.width = 150;
textField.x = center.x - textField.width/ 2;
textField.y = center.y - textField.textHeight / 2;
Hs.alpha = 0.25;
Ms.alpha = 0.25;
Ss.alpha = 0.75;
MSs.alpha = 0.25;
canvas.addChild(Hs);
canvas.addChild(Ms);
canvas.addChild(Ss);
canvas.addChild(MSs);
canvas.addChild(textField);
addChild(canvas);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function drawSteiner(n:int,sp:Sprite,nR:Number):void {
sp.graphics.clear();
if(n < 3)return;
var r:Number = nR;
; var X:Number = 0;//((new Date().seconds - 1) * 1000 + new Date().milliseconds) / 60000;
var Y:Number = 0;//((new Date().seconds - 1) * 1000 + new Date().milliseconds) / 60000;
var t:Number = Math.PI / n;
var rho:Number = r * Math.sin(t) / (1 - Math.sin(t));
t = 2 * t;
var s:Number;
_cx = center.x;
_cy = center.y;
for (var i:int = 0;i < n;++i) {
s = i * t + Math.PI / 2;
sp.graphics.beginFill(color);
draw(X + (r + rho) * Math.cos(s), Y + (r + rho) * Math.sin(s), rho, sp);
sp.graphics.endFill();
}
}
public function draw(cx:Number, cy:Number, cr:Number, sp:Sprite):void {
var c:Number = cx * cx + cy * cy - cr * cr;
var rx:Number, ry:Number, rr:Number;
rx = cx / c * _scale + _cx;
ry = -cy / c * _scale + _cy;
rr = cr / c * _scale;
sp.graphics.drawCircle(rx, ry, rr);
}
private function onEnterFrame(e:Event):void {
date = new Date();
str = country+" "+str2((hour + gmt + 24) % 24) + ":" + str2(min) + ":" + str2(sec);
textField.text = str;
drawSteiner((hour + gmt + 24) % 24, Hs, 1);
drawSteiner(min, Ms, 0.8);
drawSteiner(sec, Ss, 0.7);
drawSteiner(date.milliseconds / 3, MSs, 0.5);
}
private function str2(val:*):String
{
var str:String = String(val);
while(str.length < 2) { str = "0" + str; }
return str;
}
private function get hour():int { return int(date.getUTCHours());}
private function get min():int { return int(date.getUTCMinutes());}
private function get sec():int { return int(date.getUTCSeconds());}
}