forked from: Human Clock
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aW0r
*/
// forked from Event's Human Clock
package {
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Graphics;
import flash.display.Shape;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var _sec:int;
private var _shpSec:Shape;
private var _shpMin:Shape;
private var _shpHour:Shape;
private var _pathCommands:Vector.<int> = Vector.<int>([1,2,2,2,2]);
public function FlashTest() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
initView();
addEventListener(Event.ENTER_FRAME, enterFrame);
}
private function initView():void {
var spContainer:Sprite = new Sprite;
var shp:Shape;
var t:Number;
var layer:int;
for (var i:int = 0; i < 2; ++i)
spContainer.addChild(new Sprite);
for (i = 0; i < 360; ++i) {
shp = new Shape;
shp.graphics.beginFill(0);
if (i % 60 == 0) {
layer = 1;
drawTrapezium(shp.graphics, 2, 35, 8, 0);
} else if (i % 30 == 0) {
layer = 1;
drawTrapezium(shp.graphics, 1, 20, 4, 0);
} else {
layer = 0;
shp.graphics.beginFill(0x999999);
drawTrapezium(shp.graphics, 0.1, 20, 1, 0);
}
shp.rotation = i;
t = Math.PI / 180 * i - Math.PI / 2;
shp.x = 100 * Math.cos(t); shp.y = 100 * Math.sin(t);
Sprite(spContainer.getChildAt(layer)).addChild(shp);
}
shp = new Shape;
shp.graphics.lineStyle(10);
shp.graphics.moveTo(-300, 0);
shp.graphics.curveTo(0, -230, 300, 0);
spContainer.addChild(shp);
spContainer.graphics.beginFill(0);
spContainer.graphics.drawCircle(0, 0, 50);
_shpHour = new Shape;
_shpHour.graphics.beginFill(0xdc143c);
drawTrapezium(_shpHour.graphics, 6, 95, 8, 55);
_shpHour.graphics.endFill();
_shpMin = new Shape;
_shpMin.graphics.beginFill(0x228b22);
drawTrapezium(_shpMin.graphics, 6, 95, 8, 55);
_shpMin.graphics.endFill();
_shpSec = new Shape;
_shpSec.graphics.beginFill(0xeb6101);
drawTrapezium(_shpSec.graphics, 3, 95, 5, 55);
_shpSec.graphics.endFill();
spContainer.x = spContainer.y = 465 >> 1;
addChild(spContainer);
spContainer = Sprite(spContainer.addChild(new Sprite));
spContainer.addChild(_shpHour);
spContainer.addChild(_shpMin);
spContainer.addChild(_shpSec);
spContainer.rotation = 180;
}
private function drawTrapezium($graphics:Graphics, $right:Number, $top:Number, $left:Number, $bottom:Number):void {
$graphics.drawPath(_pathCommands, Vector.<Number>([
$left, $bottom, -$left, $bottom, -$right, $top, $right, $top, $left, $bottom
]));
}
private function enterFrame(e:Event):void {
var time:Date = new Date;
var sec:int = time.getSeconds();
if (_sec == sec) return;
_sec = sec;
updateView(time.getHours(), time.getMinutes(), sec);
}
private function updateView($hour:int, $min:int, $sec:int):void {
_shpHour.rotation = ($hour % 12) * 30 + $min / 2;
_shpMin.rotation = $min * 6;
_shpSec.rotation = _sec * 6;
}
}
}