package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.TextField;
public class ClockSample extends Sprite {
// 表示用スプライト
private var child:Sprite;
/**
* コンストラクタ */
public function ClockSample() {
// 文字盤を作る
makeBoard();
// 時計の針をつくる
makeNeedles();
}
/**
* 文字盤を作る */
private function makeBoard():void {
child = new Sprite();
child.graphics.beginFill(0xFFFFFF);
child.graphics.drawRect(-200, -200, 400, 400);
child.graphics.endFill();
child.x = this.stage.stageWidth / 2;
child.y = this.stage.stageHeight / 2;
this.addChild(child);
var i:int;
for(i=1;i<=12;i++) {
var number:Shape = new Shape();
var angle:Number = Math.PI * i / 6.0;
number.graphics.beginFill(0xCCCCCC);
number.graphics.drawRect(-10,-10,20,20);
number.graphics.endFill();
number.x = (child.width * Math.sin(angle)*0.8) * 0.5;
number.y = (child.height * -Math.cos(angle)*0.8) * 0.5;
child.addChild(number);
}
}
/**
* 針を作る */
private function makeNeedles():void {
child.addChild(new NeedleSec());
child.addChild(new NeedleMin());
child.addChild(new NeedleHour());
}
}
}
import flash.display.Shape;
import flash.events.Event;
/**
* 針の基本クラス */
internal class Needle extends Shape
{
public function Needle(length:uint, width:uint, color:uint) {
this.graphics.beginFill(color);
this.graphics.drawRoundRect(-width, -length, width*2, length, width, width);
this.graphics.endFill();
this.x = 0;
this.y = 0;
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
move();
}
public function onEnterFrame(event:Event):void {
move();
}
public function move():void {}
}
/**
* 時間を指し示す針のクラス */
internal class NeedleHour extends Needle {
public function NeedleHour() {
super(60, 3, 0xFF0000);
}
override public function move():void {
var now:Date = new Date();
this.rotation = (now.hours + now.minutes/60) * 30;
}
}
/**
* 分を指し示す針のクラス */
internal class NeedleMin extends Needle {
public function NeedleMin() {
super(100, 2, 0xFF8000);
}
override public function move():void {
var now:Date = new Date();
this.rotation = now.minutes * 6;
}
}
/**
* 秒を指し示す針のクラス */
internal class NeedleSec extends Needle {
public function NeedleSec() {
super(105, 1, 0x000000);
}
override public function move():void {
var now:Date = new Date();
this.rotation = now.seconds * 6;
}
}
2007年12月21日金曜日
時計の表示
時計を表示します。
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿