In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Due3.Screensaver Clock Modoki by paq

http://www.apple.com/downloads/macosx/icons_screensavers/due3screensaverclock.html
* http://www.due3.com/share/screensaver/index.html
* これを作ってみようとしているところ
* 
* 強敵はフォント。
* 
* 短針の動作がおかしいような。
* 
* 本家の動きはもっと鋭い。
* 
* 破線描画は
* http://blog.nipx.jp/2008/04/post-11.html
* を使わせていただきました。
// forked from ahchang's forked from: Due3.Screensaver Clock Modoki
// forked from ahchang's Due3.Screensaver Clock Modoki
// forked from ahchang's forked from: clock01
// forked from ll_koba_ll's clock01
/*
* http://www.apple.com/downloads/macosx/icons_screensavers/due3screensaverclock.html
* http://www.due3.com/share/screensaver/index.html
* これを作ってみようとしているところ
* 
* 強敵はフォント。
* 
* 短針の動作がおかしいような。
* 
* 本家の動きはもっと鋭い。
* 
* 破線描画は
* http://blog.nipx.jp/2008/04/post-11.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="0x0A0A0A")]
	
	public class Clock01 extends Sprite
	{
		private var secondHand:Sprite;
		private var minuteHand:Sprite;
		private var hourHand:Sprite;
		private var center:Point;
		private var weekText:TextField;
		private var monthText:TextField;
		private var timeText:TextField;
		public static const WEEK:Array = ["SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURSDAY"];
		public static const MONTH:Array = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"]
		
		public function Clock01()
		{
			addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);

			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.addEventListener(MouseEvent.CLICK, onClick);
			
			//時計の中心を設定
			center = new Point();
			center.x = 200;
			center.y = stage.stageWidth - 140;
			
			//針を作成
			
			//短針
			createMinuteHand();
			//長針
			createHourHand();
			//秒針
			createSecondHand();
			
			//針をトゥイーン
			initAnime();
			//テキストフィールドを作成
			createTextField();
			//タイマースタート
			start();
		}
		
		private function onClick(e:MouseEvent):void 
		{
			stage.displayState = stage.displayState == StageDisplayState.NORMAL ? StageDisplayState.FULL_SCREEN : StageDisplayState.NORMAL;
		}
		
		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を使って針をトゥイーンする
			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"});
		}

		private function start():void
		{
			//タイマー1秒をセット
			var t:Timer = new Timer(1000, 0);
			t.addEventListener(TimerEvent.TIMER, timer);
			
			//タイマーを開始
			t.start();
		}
		
		private function createTextField():void
		{
			//テキストのフォーマットを作成
			var format:TextFormat = new TextFormat();
			format.size = 20;
			format.font = "Helvetica";
			
			//曜日を表示するテキストフィールドを作成
			weekText= new TextField();
			weekText.textColor = 0xFFFFFF;
			weekText.defaultTextFormat = format;
			weekText.autoSize = TextFieldAutoSize.LEFT;
			weekText.x = 30;
			weekText.y = 365;
			weekText.mouseEnabled = false;
			
			//月を表示するテキストフィールドを作成
			monthText = new TextField();
			monthText.textColor = 0xA5FFFE;
			monthText.defaultTextFormat = format;
			monthText.autoSize = TextFieldAutoSize.LEFT;
			monthText.x = 30;
			monthText.y = 385;
			monthText.mouseEnabled = false;
			
			//現在時刻を表示するテキストフィールドを作成
			timeText = new TextField();
			timeText.textColor = 0xFFFFFF;
			timeText.defaultTextFormat = format;
			timeText.autoSize = TextFieldAutoSize.LEFT;
			timeText.x = 30;
			timeText.y = 405;
			timeText.mouseEnabled = false;
						
			//現在時刻を更新
			updateText()
			
			//テキストフィールドをstageに追加
			addChild(weekText);
			addChild(monthText);
			addChild(timeText);
		}

		private function timer(e:TimerEvent = null):void
		{
			//現在時刻の取得
			var d:Date = new Date();
			var s:int = d.getSeconds();
			var m:int = d.getMinutes();
			var h:int = d.getHours();
			var year:int = d.getFullYear();
			var monthIndex:int = d.getMonth();
			var day:int = d.getDate();
			var weekIndex:int = d.getDay();
			
			//秒針をトゥイーン
			var sr:Number = getRotation(s, 60);
			//secondHand.rotation = sr-10;
			Tweener.addTween(secondHand, { rotation:sr, time:0.5, transition:"easeOutElastic"} );

			//秒が0だった場合
			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;
			}
			
			//現在時刻を更新
			updateText()
		}

		private function updateText():void
		{
			//現在時刻の取得
			var d:Date = new Date();
			var year:int = d.getFullYear();
			var monthIndex:int = d.getMonth();
			var day:int = d.getDate();
			var weekIndex:int = d.getDay();
			var s:int = d.getSeconds();
			var m:int = d.getMinutes();
			var h:int = d.getHours();
			var ss:String;
			var mm:String;
			var hh:String;
			
			ss = s < 10 ? "0" + s : String(s);
			mm = m < 10 ? "0" + m : String(m);
			hh = h < 10 ? "0" + h : String(h);
			
			//現在時刻をテキストフィールドに表示
			weekText.text = WEEK[weekIndex] 
			monthText.text = MONTH[monthIndex] + " " + day + ", " + year;
			timeText.text = hh + ":" + mm + " / " + ss;
		}
		private function getRotation(val:int, bunkatsu:int = 60):Number
		{
			//角度を返す
			return (360/bunkatsu*val <= 186)? 360/bunkatsu*val : -(360 - 360/bunkatsu*val);
		}
		
		private function createSecondHand():void
		{
			//秒針を描く
			secondHand = new Sprite;
			var g:Graphics = secondHand.graphics;
			g.beginFill(0xA5FFFE);
			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.lineStyle(1, 0x252525, 1);
			dotLineTo(g, 4, 0, -10, 0, -460);
			
			addChild(minuteHand);
			minuteHand.x = center.x;
			minuteHand.y = center.y;
		}

		private function createHourHand():void
		{
			//長針を描く
			hourHand = new Sprite;
			var g:Graphics = hourHand.graphics;
			g.lineStyle(1, 0x252525, 1);
			dotLineTo(g, 4, 0, 50, 0, -430);
			
			addChild(hourHand);
			hourHand.x = center.x;
			hourHand.y = center.y;
		}	   
		
		/*===============================================================
		 * Ni_DotLine
		 * 
		 * @see		http://blog.nipx.jp/2008/04/post-11.html
		 * @author	kosuke
		 * 
		*///===========================================================*/
		public function dotLineTo( targetGraphics:Graphics, segment:Number=20, xx:Number=0, yy:Number=0, gx:Number=0, gy:Number=0 ):void
		{
			var target:Graphics = targetGraphics;
			var seg:Number = segment;
			var now:Point = new Point( xx, yy );
			var rest:Number = 0;
			var flag:Boolean = false;
			
			var s:Point = new Point( now.x, now.y );
			var e:Point = new Point( gx, gy );
			var d:Number = Point.distance( s, e );
			
			now.x = e.x;
			now.y = e.y;
			rest = (seg * 1 < rest) ? rest - seg * Math.floor( rest / seg ) : rest;
			if(d <= rest){
				rest -= d;
				if(flag){
					target.lineTo( e.x, e.y );
					flag = (rest == 0) ? false : true;
				}
				else{
					target.moveTo( e.x, e.y );
					flag = (rest == 0) ? true : false;
				}
				return void;
			}

			var m:Number = 1 / ( d / seg  );
			var n:Number = 1 / ( d / rest );

			for( var i:Number=1-n; 0 < i; i-=m ){
				var a:Point = Point.interpolate( s, e, i );
				if(flag){
					target.lineTo( a.x, a.y );
					flag = false;
				}
				else{
					target.moveTo( a.x, a.y );
					flag = true;
				}
				if( i - m < 0 ){
					var b:Point = Point.interpolate( s, e, i - m );
					var c:Point = Point.interpolate( s, e, 0 );
					rest = Point.distance( e, b );
					if(flag){
						target.lineTo( c.x, c.y );
					}
					else{
						target.moveTo( c.x, c.y );
					}
				}
			}
		}
	}
}