Rolling Clock
/**
* Copyright Mingchoi ( http://wonderfl.net/user/Mingchoi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/3kn2S
*/
// forked from Yui.Ohsaki's clock
package {
import flash.text.TextField;
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class FlashTest extends Sprite {
public var g:Sprite = new Sprite(); // 針(三本)
public var first:Boolean; //呼び出しフラグ(初回)
public var clockPanel:Sprite;
public var clockPanel_g:Sprite;
public function FlashTest() {
// write as3 code here..
clockPanel = new Sprite;
clockPanel_g = new Sprite;
var s:Sprite = new Sprite; //時計盤
//時計盤設定
s.graphics.beginFill( 0x000000, 1.0);
s.graphics.lineStyle( 1, 0x000000, 1.0);
s.graphics.drawCircle( 200, 250, 180);
s.graphics.beginFill( 0x999999, 1.0);
s.graphics.lineStyle( 1, 0x999999, 1.0);
s.graphics.drawCircle( 200, 250, 10);
//目盛設定
var i:int;
for( i = 0; i < 60; i++){
var theta:Number = 2 * Math.PI * i/60;
s.graphics.moveTo( 200 + 180 * Math.cos(theta), 250 + 180 * Math.sin(theta));
if(i % 5 == 0 ){
s.graphics.lineStyle( 1, 0xffffff , 1.0);
s.graphics.lineTo( 200 + 170 * Math.cos(theta), 250 + 170 * Math.sin(theta));
}else{
s.graphics.lineStyle( 1, 0xffffff , 1.0);
s.graphics.lineTo( 200 + 175 * Math.cos(theta), 250 + 175 * Math.sin(theta));
}
}
first = true;
//タイマー設定
var timer:Timer = new Timer( 1000 );
timer.addEventListener( TimerEvent.TIMER, moveSecond );
timer.start();
//Fork
addChild( clockPanel );
clockPanel.x=200;
clockPanel.y=250;
clockPanel.addChild( s );
s.x=-200;
s.y=-250;
addChild( clockPanel_g );
clockPanel_g.x=200;
clockPanel_g.y=250;
var TF12:TextField=new TextField();
TF12.htmlText="<font color='#BBBBBB' size='30' face='Arial'>XII</font>"
TF12.x=182-200;
TF12.y=101-250;
TF12.z=0;
clockPanel.addChild(TF12);
var TF6:TextField=new TextField();
TF6.htmlText="<font color='#BBBBBB' size='30' face='Arial'>VI</font>"
TF6.x=190-200;
TF6.y=365-250;
TF6.z=0;
clockPanel.addChild(TF6);
var TF3:TextField=new TextField();
TF3.htmlText="<font color='#BBBBBB' size='30' face='Arial'>III</font>"
TF3.x=330-200;
TF3.y=230-250;
TF3.z=0;
clockPanel.addChild(TF3);
var TF9:TextField=new TextField();
TF9.htmlText="<font color='#BBBBBB' size='30' face='Arial'>IX</font>"
TF9.x=63-200;
TF9.y=230-250;
TF9.z=0;
clockPanel.addChild(TF9);
}
public function moveSecond( event:TimerEvent):void{
var now:Date = new Date();
var h:int = now.getHours();
var m:int = now.getMinutes();
var s:int = now.getSeconds();
//初回呼び出し時はリムーブしない
if(first){
first = false;
}else{
clockPanel_g.removeChild( g );
}
g.graphics.clear();
var theta:Number;
g.graphics.lineStyle( 1 , 0x999999, 1.0);
theta = 2 * Math.PI * s / 60 - Math.PI / 2;
g.graphics.moveTo( 0, 0);
g.graphics.lineTo( 150 * Math.cos(theta) , 150 * Math.sin(theta));
g.graphics.lineStyle( 2 , 0x999999, 1.0);
theta = 2 * Math.PI *( s + m / 60) - Math.PI / 2;
g.graphics.moveTo( 0, 0);
g.graphics.lineTo( 130 * Math.cos(theta) , 130 * Math.sin(theta));
g.graphics.lineStyle( 5 , 0x999999, 1.0);
theta = 2 * Math.PI * ( h + m / 60 ) / 12 - Math.PI / 2;
g.graphics.moveTo( 0, 0);
g.graphics.lineTo( 80 * Math.cos(theta) , 80 * Math.sin(theta));
clockPanel_g.addChild( g ) ;
clockPanel.rotation-=6;
clockPanel_g.rotation-=6;
}
}
}