時報
forked from Human Clock (diff: 223)
Copyright Event ( http://wonderfl.net/user/Event ) * MIT License ( http://www.opensource.org/licenses/mit-license.php ) * Downloaded from: http://wonderfl.net/c/r0sP
ActionScript3 source code
/**
* Copyright s26 ( http://wonderfl.net/user/s26 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uEou
*/
/**
* Copyright Event ( http://wonderfl.net/user/Event )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/r0sP
*/
package {
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
import flash.display.*;
import flash.geom.*;
public class HumanClock extends Sprite {
private var _sec:int;
private var _shpSec:Shape;
private var _shpMin:Shape;
private var _shpHour:Shape;
private var _pathCommands:Vector.<int> = Vector.<int>([1,2,2,2,2]);
private var canvas:BitmapData;
private var textCanvas:BitmapData;
private var particles:Array;
private var _num:int;
private var maxDis:int = 400;
public function HumanClock() {
initView();
canvas = new BitmapData(stage.stageWidth,stage.stageHeight,false,0x000000);
addChild( new Bitmap(canvas) );
ParticleText(" ",12)
ParticleText2(" ",12)
var timer:Timer = new Timer(50);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
var _timer:Timer = new Timer(10);
_timer.addEventListener(TimerEvent.TIMER, _onEnterFrame);
_timer.start();
var _timer2:Timer = new Timer(10);
_timer2.addEventListener(TimerEvent.TIMER, _onEnterFrame2);
_timer2.start();
}
private function initView():void {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
onTimer(null);
}
private function onTimer(e:TimerEvent):void {
var time:Date = new Date;
var sec:int = time.getSeconds();
if (_sec == sec) return;
_sec = sec;
updateView(time.getHours(), time.getMinutes(), sec);
}
private function updateView($hour:int, $min:int, $sec:int):void {
if (_sec % 10 == 2) {
ParticleText2("いま",36)
}
if (_sec % 10 == 3) {
if(_sec==3){
ParticleText($hour + "時 " + $min + "分 ちょうどを",36)
}else{
ParticleText($hour + "時 " + $min + "分 " + int($sec - 3) + "秒を",36)
}
}
if (_sec % 10 == 5) {
ParticleText("おしらせいたします",36)
}
if (_sec % 10 == 7) {
ParticleText2("ぴ",24)
}
if (_sec % 10 == 8) {
ParticleText2("ぴ",48)
}
if (_sec % 10 == 9) {
ParticleText2("ぴ",64)
}
if (_sec % 10 == 0) {
ParticleText("ぽ--ん",36)
}
}
public function ParticleText(str:String,size:uint) {
var tf:TextField = new TextField;
tf.defaultTextFormat = new TextFormat("Times New Roman",size,0xFFFFFF);
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = str
textCanvas = new BitmapData(tf.textWidth,tf.textHeight,false,0x000000);
textCanvas.draw(tf);
particles = new Array();
createText();
}
public function createText():void{
var ofx:Number = stage.stageWidth/2 - textCanvas.width/2;
var ofy:Number = stage.stageHeight/2 - textCanvas.height/2;
for ( var ex:Number = 0;ex < textCanvas.width;ex++){
for (var ey:Number = 0;ey < textCanvas.height;ey++){
var c:uint = textCanvas.getPixel(ex,ey);
//if(c != 0x000000){
createParticle(ex + ofx,ey + ofy,c);
//}
}
}
}
public function createParticle(ex:Number,ey:Number,c:int):void{
var p:Particle = new Particle();
p.ex = ex;
p.ey = ey;
p.c = c;
initParticle(p);
particles.push(p)
_num = 0;
}
public function initParticle(p:Particle):void{
p.x = p.ex+300-600*Math.random();
p.y = p.ey+300-600*Math.random();
}
private function _onEnterFrame( evt:Event ):void{
canvas.lock();
canvas.fillRect( canvas.rect,0x000000 );
for (var i:int = 0;i<_num;i++){
var p:Particle = particles[i];
if(Math.abs(p.ex - p.x)<0.5 &&Math.abs(p.ey-p.y)<0.5){
p.x = p.ex;
p.y = p.ey;
}else{
p.x += (p.ex - p.x)/15;
p.y += (p.ey - p.y)/15;
}
canvas.setPixel(p.x,p.y,p.c);
}
var n:int = particles.length;
_num = (_num +400<n)?_num + 400:n;
canvas.unlock();
}
public function ParticleText2(str:String,size:uint) {
var tf:TextField = new TextField;
tf.defaultTextFormat = new TextFormat("Times New Roman",size,0xFFFFFF);
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = str
textCanvas = new BitmapData(tf.textWidth,tf.textHeight,false,0x000000);
textCanvas.draw(tf);
particles = new Array();
createText2();
}
public function createText2():void{
var ofx:Number = stage.stageWidth/2 - textCanvas.width/2;
var ofy:Number = stage.stageHeight/2 - textCanvas.height/2;
for ( var ex:Number = 0;ex < textCanvas.width;ex++){
for (var ey:Number = 0;ey < textCanvas.height;ey++){
var c:uint = textCanvas.getPixel(ex,ey);
//if(c != 0x000000){
createParticle2(ex + ofx,ey + ofy,c);
//}
}
}
}
public function createParticle2(ex:Number,ey:Number,c:int):void{
var p:Particle = new Particle();
p.ex = ex;
p.ey = ey;
p.c = c;
initParticle2(p);
particles.push(p)
_num = 0;
}
public function initParticle2(p:Particle):void{
p.x = p.ex+300-600*Math.random();
p.y = p.ey+300-600*Math.random();
}
private function _onEnterFrame2( evt:Event ):void{
canvas.lock();
canvas.fillRect( canvas.rect,0x000000 );
for (var i:int = 0;i<_num;i++){
var p:Particle = particles[i];
if(Math.abs(p.ex - p.x)<0.5 &&Math.abs(p.ey-p.y)<0.5){
p.x = p.ex;
p.y = p.ey;
}else{
p.x += (p.ex - p.x)/15;
p.y += (p.ey - p.y)/15;
}
canvas.setPixel(p.x,p.y,p.c);
}
var n:int = particles.length;
_num = (_num +20 < n)?_num + 20:n;
canvas.unlock();
}
}
}
class Particle{
public var x:Number;
public var y:Number;
public var ex:Number;
public var ey:Number;
public var c:int;
public function Particle(){
x = 0;
y = 0;
ex = 0;
ey = 0;
c = 0;
}
}