細長時計
NHK教育「デザインあ」に出ていた細長時計。
http://www.nhk.or.jp/design-ah/vol08/
時計の作り方はこちらのコードをところどころ参考にしました。
http://wonderfl.net/c/fCRW
/**
* Copyright butchi ( http://wonderfl.net/user/butchi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lZd2
*/
package {
import flash.geom.Rectangle;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.LineScaleMode;
import flash.display.CapsStyle;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
public class HosonagaClock02 extends Sprite {
public function HosonagaClock02() {
this.graphics.lineStyle(5);
this.graphics.drawRect(10,10,440,80);
// 時刻の数字を表示するテキストフォーマット
var tf:TextFormat = new TextFormat();
tf.font = "Impact";
tf.size = 16;
//tf.align = TextFormatAlign.CENTER;
var time:int = 0;
for (var scale_counter:int = 0; scale_counter < 60; scale_counter++) {
if (scale_counter % 5 == 0) {
var scaleBold:Sprite = new Sprite();
scaleBold.graphics.beginFill(0x000000);
scaleBold.graphics.drawRect(0, 0, 3, 10);
scaleBold.graphics.endFill();
scaleBold.x = 25 + scale_counter * 7;
scaleBold.y = 75;
addChild(scaleBold);
var text_field:TextField = new TextField();
text_field.defaultTextFormat = tf;
text_field.autoSize = TextFieldAutoSize.CENTER;
if(time == 0) {
text_field.text = "12";
} else {
text_field.text = time.toString();
}
time++;
text_field.x = 25 + scale_counter * 7 - text_field.width/2;
text_field.y = 50;
addChild(text_field);
}
else {
var scaleThin:Sprite = new Sprite();
scaleThin.graphics.beginFill(0x000000);
scaleThin.graphics.drawRect(0, 0, 1, 6);
scaleThin.graphics.endFill();
scaleThin.x = 25 + scale_counter * 7;
scaleThin.y = 75;
addChild(scaleThin);
}
}
var second_hand:Shape = new Shape();
second_hand.graphics.lineStyle(2,0x000000,1.0,false,LineScaleMode.NORMAL,CapsStyle.NONE);
second_hand.graphics.lineTo(0,60);
second_hand.x = 25 + 3 * 7;
second_hand.y = 10;
addChild(second_hand);
var minute_hand:Shape = new Shape();
minute_hand.graphics.lineStyle(5,0x000000,1.0,false,LineScaleMode.NORMAL,CapsStyle.NONE);
minute_hand.graphics.lineTo(0,45);
minute_hand.x = 25;
minute_hand.y = 10;
addChild(minute_hand);
var hour_hand:Shape = new Shape();
hour_hand.graphics.lineStyle(5,0x000000,1.0,false,LineScaleMode.NORMAL,CapsStyle.NONE);
hour_hand.graphics.lineTo(0,25);
hour_hand.x = 25 + 15 * 7;
hour_hand.y = 10;
addChild(hour_hand);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(evt:Event) {
var date:Date = new Date();
hour_hand.x = 25 + date.getHours() * 7 * 5;
minute_hand.x = 25 + date.getMinutes() * 7;
second_hand.x = 25 + date.getSeconds() * 7;
}
}
}
}