import ColorSet; var MODE_DRAW_VERY_FIRST:Number = 0; var MODE_DRAW_INIT:Number = 1; var MODE_DRAW_ONE:Number = 2; var MODE_DRAW_CLEAR:Number = 3; var prev_s:Number = -1; var cur_s:Number = -1; var cur_m:Number = -1; var my_mode:Number = MODE_DRAW_VERY_FIRST; var first_sec = -1; /* for layouting */ var wh:Number = 20; var margin:Number = 2; var edge_margin:Number = 2 ; var cols:Array = initCols(0xffcccc); var cols2:Array = initCols(0xddaaaa); _root.onEnterFrame = function(){ var d:Date = new Date(); h = d.getHours(); m = d.getMinutes(); s = d.getSeconds(); ms = d.getMilliseconds(); // update min_arm if(cur_m != m){ this.clear(); end_clear(); cur_m = m; } if(cur_s != s){ cur_s = s; writeTime(this, h, m, cols2[s]); } //function blink(my_mc, flag, rgb){ blink(this, ms, cols2[s]); // update mode switch(my_mode){ case MODE_DRAW_VERY_FIRST: first_sec = s; my_mode = MODE_DRAW_INIT; return; case MODE_DRAW_INIT: if(s == first_sec) return; if(s != first_sec + 1) my_mode = MODE_DRAW_ONE; break; case MODE_DRAW_ONE: if(s == 59) my_mode = MODE_DRAW_CLEAR; break; case MODE_DRAW_CLEAR: if(s != 59) my_mode = MODE_DRAW_ONE; break; } switch(my_mode){ case MODE_DRAW_INIT: do_first_flip(s, ms); break; case MODE_DRAW_ONE: do_draw_one(prev_s, s, ms); prev_s = s-1; break; case MODE_DRAW_CLEAR: do_clear(ms); prev_s = -1; break; } }; function permute(cnt){ return (cnt * 11) % 60; } function do_first_flip(s, ms){ for(i = 0; i <= s; i++){ cnt = permute(i); drawSecFlipping(this, cnt, cols[cnt], ms * 0.001); } } function do_draw_one(prev_s, s, ms){ for(i = prev_s+1; i < s; i++){ cnt = permute(i); drawSec(this, cnt, cols[cnt]); } cnt = permute(i); drawSecFlipping(this, cnt, cols[cnt], ms * 0.001);} function do_clear(ms){ for(i = 0; i < 60; i++) drawSecFlipping(this, i, cols[i], 1-ms*0.001);} function end_clear(){ for(i = 0; i < 60; i++) drawSec(this, i, [0xee,0xee,0xee]);} /* util functions */ function blend(r0, g0, b0, r1, g1, b1, alpha){ r = int(r0 * alpha + r1 * (1.00 - alpha)); g = int(g0 * alpha + g1 * (1.00 - alpha)); b = int(b0 * alpha + b1 * (1.00 - alpha)); col = r * 0x10000 + g * 0x100 + b; return col; } function writeTime(my_mc, h, m, rgb){ col = rgb[0] * 0x10000 + rgb[1] * 0x100 + rgb[2]; drawNum(my_mc, int(h/10), 0, col); drawNum(my_mc, h%10, 1, col); drawNum(my_mc, int(m/10), 2, col); drawNum(my_mc, m%10, 3, col); } function drawNum(my_mc, n, pos_id, col){ x0 = 35; y0 = 80; shift_x = pos_id * 32; if(pos_id >= 2) shift_x += 12; var segs:Array; switch(n){ case 0: segs = [0,1,2,4,5,6]; break; case 1: segs = [5,6]; break; case 2: segs = [1,2,3,4,5]; break; case 3: segs = [2,3,4,5,6]; break; case 4: segs = [0,3,5,6]; break; case 5: segs = [0,2,3,4,6]; break; case 6: segs = [0,1,2,3,4,6]; break; case 7: segs = [2,5,6]; break; case 8: segs = [0,1,2,3,4,5,6]; break; case 9: segs = [0,2,3,4,5,6]; break; } for(i = 0; i < segs.length; i++) draw7Seg(my_mc, x0 + shift_x, y0, segs[i], col); } function draw7Seg(my_mc, x0, y0, type, col){ bar = 20; barMargin = 3; barDiff = 2; my_mc.lineStyle(1,col); my_mc.beginFill(0xffffff); switch(type){ case 0: case 1: case 5: case 6: if(type == 1 || type == 6) y0 += bar + barMargin; if(type == 5 || type == 6) x0 += bar + barMargin; my_mc.moveTo(x0, y0); my_mc.lineTo(x0 - barDiff, y0 + barDiff); my_mc.lineTo(x0 - barDiff, y0 - barDiff + bar); my_mc.lineTo(x0, y0 + bar); my_mc.lineTo(x0 + barDiff, y0 - barDiff + bar); my_mc.lineTo(x0 + barDiff, y0 + barDiff); break; case 2: case 3: case 4: x0 += barMargin/2; y0 -= barMargin / 2; if(type == 3) y0 += bar + barMargin; if(type == 4) y0 += (bar + barMargin)*2; my_mc.moveTo(x0, y0); my_mc.lineTo(x0 + barDiff, y0 - barDiff); my_mc.lineTo(x0 - barDiff + bar, y0 - barDiff); my_mc.lineTo(x0 + bar, y0); my_mc.lineTo(x0 - barDiff + bar, y0 + barDiff); my_mc.lineTo(x0 + barDiff, y0 + barDiff); break; } my_mc.endFill(); my_mc.lineStyle(); } function blink(my_mc, ms, rgb){ rad = ms / 500 * Math.PI ; col = blend(rgb[0], rgb[1], rgb[2], 255, 255, 255, Math.sin(rad)/2 + 0.5); blinkOne(my_mc, col, 100, 88); blinkOne(my_mc, col, 100, 112); } function blinkOne(my_mc, col, x0, y0){ rag = 3; my_mc.lineStyle(1,col); my_mc.beginFill(0xffffff); my_mc.moveTo(x0, y0-rag); my_mc.lineTo(x0+rag, y0); my_mc.lineTo(x0, y0+rag); my_mc.lineTo(x0-rag, y0); my_mc.endFill(); my_mc.lineStyle(); } function initCols(col){ var cols:Array = new Array(); var cs:ColorSet = new ColorSet(col); for(i = 0; i < 60; i++){ cs.h = i * 6; cols[i] = [int(cs.r), int(cs.g), int(cs.b)- int((cs.r + cs.g) * 0.05)]; } return cols; } function getIxy(cnt){ /* Return position */ if(cnt > 27) cnt += 7; if(cnt > 36) cnt += 7; if(cnt > 45) cnt += 7; return [cnt%9, int(cnt/9)]; } function drawSec(my_mc, cnt, rgb){ /* 0 <= cnt < 4*N */ xy = getIxy(cnt); col = rgb[0] * 0x10000 + rgb[1] * 0x100 + rgb[2]; x0 = edge_margin + xy[0] * (wh+margin) + margin; y0 = edge_margin + xy[1] * (wh+margin) + margin; drawSq(my_mc, x0, y0, wh, col); } function drawSecFlipping(my_mc, cnt, rgb, ratio){ /* 0 <= cnt < 4*N */ xy = getIxy(cnt); x0 = edge_margin + xy[0] * (wh+margin) + margin; y0 = edge_margin + xy[1] * (wh+margin) + margin; drawSq(my_mc, x0, y0, wh, 0xffffff); col = blend(rgb[0], rgb[1], rgb[2], 0xee, 0xee, 0xee, ratio); drawFlip(my_mc, x0, y0, wh, col, ratio); } function drawSq(my_mc, x0, y0, wh, col){ my_mc.beginFill(col, 100); my_mc.moveTo(x0, y0); my_mc.lineTo(x0 + wh, y0); my_mc.lineTo(x0 + wh, y0 + wh); my_mc.lineTo(x0, y0 + wh); my_mc.endFill(); } function drawFlip(my_mc, x0, y0, wh, col, ratio){ rad = ratio * Math.PI / 2; wx = wh * Math.sin(rad); wy = wh * Math.cos(rad); my_mc.beginFill(col, 100); my_mc.moveTo(x0 + wx, y0 + wh - wy); my_mc.lineTo(x0 + wh, y0); my_mc.lineTo(x0 + wh - wx, y0 + wy); my_mc.lineTo(x0, y0 + wh); my_mc.endFill(); }