clock4

by Scmiz
♥0 | Line 66 | Modified 2011-05-28 18:16:51 | MIT License
play

ActionScript3 source code

/**
 * Copyright Scmiz ( http://wonderfl.net/user/Scmiz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1G6t
 */

package {
	import flash.display.Graphics;
    import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
    public class FlashTest extends Sprite {
		private const DIR_R:uint = 0;
		private const DIR_D:uint = 1;
		private const DIR_L:uint = 2;
		private const DIR_U:uint = 3;
		private const DIR_NUM:uint = 4;
		private const DIR_BEGIN:uint = DIR_R;
		
		private const NUM:uint = 400;
		
        public function FlashTest() {
			this.addEventListener(Event.ENTER_FRAME, proc);
        }
		
		private function proc(e:Event):void {
			draw();
		}
		
		private function draw():void {
			var value:uint = calc(NUM) * currentRatio();
			
			var g:Graphics = this.graphics;
			g.clear();
			g.lineStyle(1, 0x000000);
			var dir:uint = DIR_BEGIN;
			var posX:uint = 32;
			var posY:uint = 32;
			var reftLength:uint = value;
			for (var index:uint = 0; index < NUM; ++index) {
				g.moveTo(posX, posY);
				
				var length:uint = NUM - index;
				if (length > reftLength) {
					length = reftLength;
				}
				
				switch (dir) {
					case DIR_R: posX += length; break;
					case DIR_D: posY += length; break;
					case DIR_L: posX -= length; break;
					case DIR_U: posY -= length; break;
				}
				g.lineTo(posX, posY);

				++dir;
				if (dir == DIR_NUM) {
					dir = DIR_BEGIN;
				}
				reftLength -= length;
				if (reftLength == 0) {
					break;
				}
			}
		}
		
		private function currentRatio():Number {
			var now:Date = new Date();
			
			var sec:uint = (now.hours * 60 * 60) + (now.minutes * 60) + (now.seconds);
			var max:uint = (23 * 60 * 60) + (59 * 60) + (59);
			
			return Number(sec) / max;
		}

		private function calc(value:uint):uint {
			var total:uint = 0;
			for (var index:uint = 1; index <= value; ++index) {
				total += index;
			}
			return total;
		}
    }	
}