試作品:アナログ時計
今自分でできる範囲の簡単なアナログ時計。
ソースが酷すぎる。
後日見やすくする。
あとやりたいのは後ろの円をカラフルにするのと、特定時間で時間のデジタル表示を変えること。寝よ。
/**
* Copyright Nowloading_ ( http://wonderfl.net/user/Nowloading_ )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lGz6
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.events.TimerEvent;
import flash.utils.Timer;
import caurina.transitions.Tweener;
[SWF (width=465,height=465,frameRate=30,backgroundCOlor=0xffffff)]
public class FlashTest extends Sprite {
private const cx:int = 120;
private const cy:int = 120;
private var data:Date; //日時データ
private var h:Number; //時間
private var m:Number; //分
private var s:Number; //秒
private var text:TextField; //テキスト表示域
private var ttex:TextField;
private var ttf:TextFormat;
private var array:Array = new Array(); //テキスト用配列
private var tim:Timer; //1秒タイマー
private var lsin:Sprite; //長針
private var ssin:Sprite; //短針
private var bsin:Sprite; //秒針
private var _body:Sprite;
private var tball:Sprite;
//メインファンクション
public function FlashTest() {
text = new TextField();
_set();
stim();
_ttf();
ttex = new TextField();
ttex.width=200;
stage.addChild(ttex);
}
//針と時計bodyの描画設定
private function _set():void{
_sbody();
_shari();
tball = new Sprite();
tball.x=cx;
tball.y=cy;
stage.addChild(tball);
tball.graphics.beginFill(0x000000,0.11);
tball.graphics.lineStyle(0,0x000000,0);
tball.graphics.drawCircle(0,0,70);
tball.graphics.endFill();
}
//時計bodyの描画設定
private function _sbody():void{
_body = new Sprite();
_body.x=cx;
_body.y=cy;
stage.addChild(_body);
_body.graphics.beginFill(0x000000);
_body.graphics.lineStyle(1,0x000000);
_body.graphics.drawCircle(0,0,5);
_body.graphics.endFill();
//_body.graphics.beginFill(0x00ff00,0.2);
//_body.graphics.lineStyle(4,0x00ff00,0.5);
//_body.graphics.drawCircle(0,0,85);
//_body.graphics.drawCircle(0,0,105);
//_body.graphics.endFill();
_body.graphics.lineStyle(6,0xff0000,0.5);
_body.graphics.moveTo(0,-92);
_body.graphics.lineTo(0,-98);
_body.graphics.lineStyle(6,0x0000ff,0.5);
_body.graphics.moveTo(0,92);
_body.graphics.lineTo(0,98);
_body.graphics.lineStyle(5,0x000000,0.3);
_body.graphics.moveTo(-92,0);
_body.graphics.lineTo(-98,0);
_body.graphics.moveTo(92,0);
_body.graphics.lineTo(98,0);
_body.graphics.drawRoundRect(-110,-110,220,220,65,65);
}
//針の描画設定(lsin:長針ssin:短針bsin:秒針)
private function _shari():void{
//長針の設定
lsin = new Sprite();
stage.addChild(lsin);
lsin.x = cx;
lsin.y = cy;
//短針の設定
ssin = new Sprite();
stage.addChild(ssin);
ssin.x = cx;
ssin.y = cy;
//秒針の設定
bsin = new Sprite();
stage.addChild(bsin);
bsin.x = cx;
bsin.y = cy;
}
//タイマー(1000ms)の設定と開始
private function stim():void{
tim = new Timer(1000);
tim.reset();
tim.addEventListener(TimerEvent.TIMER,clock);
tim.start();
}
private function _ttf():void{
ttf = new TextFormat();
ttf.size = 32;
ttf.font="_sans";
ttf.color= 0x555555;
//ttf.align=TextFormatAlign.CENTER;
}
//1秒毎の処理
public function clock(e:TimerEvent):void{
_ctex();
_chari();
ttex.x=cx-60;
ttex.y=cy+25;
ttex.defaultTextFormat=ttf;
var ss:String="0";
if (s < 10){
ss = "0"+String(s);
}else {
ss = String(s);
}
var mm:String="0";
if (m < 10){
mm = "0"+String(m);
}else {
mm = String(m);
}
var hh:String="0";
if (h < 10){
hh = "0"+String(h);
}else {
hh = String(h);
}
ttex.text = hh+":"+mm+":"+ss;
Tweener.addTween(tball, {
scaleX: 0.87,
scaleY: 0.87,
time: 0.3,
transition: "easeoutclick",
onComplete: next,
onCompleteParams: [tball]
});
}
private function next(tball:Sprite):void{
Tweener.addTween(tball, {
scaleX: 1.0,
scaleY: 1.0,
time: 0.4,
transition: "easeoutback"
});
}
public function _ctex():void{
data = new Date();
h = data.getHours();
m = data.getMinutes();
s = data.getSeconds();
array.unshift("," + h + ":" + m + ":" + s + "\n");
text.text = String(array);
}
private function _chari():void{
bsin.graphics.clear();
bsin.graphics.moveTo(0,0);
bsin.graphics.lineStyle(1,0x000000);
bsin.graphics.lineTo(85*Math.sin(6*s*Math.PI/180),
-85*Math.cos(6*s*Math.PI/180));
bsin.graphics.lineTo(-12*Math.sin(6*s*Math.PI/180),
12*Math.cos(6*s*Math.PI/180));
ssin.graphics.clear();
ssin.graphics.moveTo(0,0);
ssin.graphics.lineStyle(4,0x000000);
ssin.graphics.lineTo(80*Math.sin(((6*m)+(s/10))*Math.PI/180),
-80*Math.cos(((6*m)+(s/10))*Math.PI/180));
lsin.graphics.clear();
lsin.graphics.moveTo(0,0);
lsin.graphics.lineStyle(6,0x000000);
lsin.graphics.lineTo(55*Math.sin(((15*h)+(m/10))*Math.PI/180),
-55*Math.cos(((15*h)+(m/10))*Math.PI/180));
}
}
}
import flash.display.Sprite;
class BodyDraw extends Sprite{
private const cx:int = 120;
private const cy:int = 120;
//private var text:TextField; //テキスト表示域
//private var ttex:TextField;
//private var ttf:TextFormat;
private var lsin:Sprite; //長針
private var ssin:Sprite; //短針
private var bsin:Sprite; //秒針
private var _body:Sprite;
private var tball:Sprite;
public function BodyDraw(){
_sbody();
tball = new Sprite();
tball.x=cx;
tball.y=cy;
stage.addChild(tball);
tball.graphics.beginFill(0x000000,0.11);
tball.graphics.lineStyle(0,0x000000,0);
tball.graphics.drawCircle(0,0,70);
tball.graphics.endFill();
}
private function _sbody():void{
_body = new Sprite();
_body.x=cx;
_body.y=cy;
stage.addChild(_body);
_body.graphics.beginFill(0x000000);
_body.graphics.lineStyle(1,0x000000);
_body.graphics.drawCircle(0,0,5);
_body.graphics.endFill();
//_body.graphics.beginFill(0x00ff00,0.2);
//_body.graphics.lineStyle(4,0x00ff00,0.5);
//_body.graphics.drawCircle(0,0,85);
//_body.graphics.drawCircle(0,0,105);
//_body.graphics.endFill();
_body.graphics.lineStyle(6,0xff0000,0.5);
_body.graphics.moveTo(0,-92);
_body.graphics.lineTo(0,-98);
_body.graphics.lineStyle(6,0x0000ff,0.5);
_body.graphics.moveTo(0,92);
_body.graphics.lineTo(0,98);
_body.graphics.lineStyle(5,0x000000,0.3);
_body.graphics.moveTo(-92,0);
_body.graphics.lineTo(-98,0);
_body.graphics.moveTo(92,0);
_body.graphics.lineTo(98,0);
_body.graphics.drawRoundRect(-110,-110,220,220,65,65);
}
}