Due3.Screensaver Clock Modoki
http://www.apple.com/downloads/macosx/icons_screensavers/due3screensaverclock.html
* これを作ってみようとしているところ
// forked from ahchang's forked from: clock01
// forked from ll_koba_ll's clock01
/*
* http://www.apple.com/downloads/macosx/icons_screensavers/due3screensaverclock.html
* これを作ってみようとしているところ
*/
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.filters.*;
import flash.utils.*;
import caurina.transitions.Tweener;
import flash.text.*;
[SWF(width="465",height="465",frameRate="60",backgroundColor="0x222222")]
public class Clock01 extends Sprite
{
private var secondHand:Sprite;
private var minuteHand:Sprite;
private var hourHand:Sprite;
private var center:Point;
public function Clock01()
{
//init();
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// mac firefoxでstageWidthが取得できないので1フレ遅らせる
addEventListener(Event.ENTER_FRAME, function(e:Event):void {
removeEventListener(Event.ENTER_FRAME, arguments.callee);
center = new Point();
center.x = 200;
center.y = 320;
createSecondHand();
createMinuteHand();
createHourHand();
initAnime();
})
}
private function initAnime():void
{
var d:Date = new Date();
var s:int = d.getSeconds();
var m:int = d.getMinutes();
var h:int = d.getHours();
Tweener.addTween(secondHand,{rotation:getRotation(s, 60), time:1, transition:"easeOutBounce"});
Tweener.addTween(minuteHand,{rotation:getRotation(m, 60), time:1, transition:"easeOutBounce"});
Tweener.addTween(hourHand, {rotation:getRotation(h, 12)+360/12/60*m, time:1, transition:"easeOutBounce"});
var year:int = d.getFullYear();
var month:int = d.getMonth();
var date:int = d.getDate();
var week:int = d.getDay();
createTextField();
start();
}
private function start():void
{
var t:Timer = new Timer(1000, 0);
t.addEventListener(TimerEvent.TIMER, timer);
t.start();
}
private function createTextField():void
{
var format:TextFormat = new TextFormat();
var tf:TextField = new TextField();
format.size = 20;
format.font = "Helvetica";
format.color = 0xf0ffff;
tf.defaultTextFormat = format;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = "Due3.Screensaver\nClock\nModoki";
//tf.text = date;
tf.x = 20;
tf.y = 385;
addChild(tf);
}
private function createSecondHand():void
{
secondHand = new Sprite;
var g:Graphics = secondHand.graphics;
g.beginFill(0xafeeee);
g.drawRect(0, -460, 1, 450);
g.endFill();
addChild(secondHand);
secondHand.x = center.x;
secondHand.y = center.y;
}
private function createMinuteHand():void
{
minuteHand= new Sprite;
var g:Graphics = minuteHand.graphics;
g.beginFill(0x444444);
g.drawRect(0, -460, 1, 450);
g.endFill();
addChild(minuteHand);
minuteHand.x = center.x;
minuteHand.y = center.y;
}
private function createHourHand():void
{
hourHand = new Sprite;
var g:Graphics = hourHand.graphics;
g.beginFill(0x444444);
g.drawRect(0, -430, 1, 450);
g.endFill();
addChild(hourHand);
hourHand.x = center.x;
hourHand.y = center.y;
}
private function timer(e:TimerEvent = null):void
{
var d:Date = new Date();
//年月日
var year:int = d.getFullYear();
var month:int = d.getMonth();
var date:int = d.getDate();
var week:int = d.getDay();
//時間
var s:int = d.getSeconds();
var m:int = d.getMinutes();
var h:int = d.getHours();
var sr:Number = getRotation(s, 60);
Tweener.addTween(secondHand, { rotation:sr, time:1, transition:"easeOutBounce"});
if (s == 0)
{
var mr:Number = getRotation(m,60);
Tweener.addTween(minuteHand, { rotation:mr+360, time:2});
var hr:Number = 360/12*h + (360/12/60*m);
hourHand.rotation = hr;
}
}
private function getRotation(val:int, bunkatsu:int = 60):Number
{
return (360/bunkatsu*val <= 186)? 360/bunkatsu*val : -(360 - 360/bunkatsu*val);
}
}
}