wonderFl_KeyVisual_v1
@author Takashi Murai(KAYAC)
// write as3 code here..
package
{
/**
*
* @author Takashi Murai(KAYAC)
*/
import flash.display.*
import flash.events.*
import flash.text.*
import flash.filters.*;
import flash.geom.*;
import flash.utils.*
[SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="30")]
public class WonderFL extends MovieClip
{
//
var Layer:Sprite=new Sprite()
var drawPos:Sprite=new Sprite()
var textPos:Sprite=new Sprite()
var txtFmt:TextFormat = new TextFormat();
var textFields:TextField=new TextField()
//message
var messages=[
"hello world.",
"<-- write code"+"\n\n"+"drawPos.graphics.drawCircle(232.5, 232.5 , 200);",
"and watch it move here.",
"it's a wonderfl world"
]
//lleasures
var posX:Number = stage.stageWidth / 2;
var posY:Number = stage.stageHeight /2;
var disX:Number =Math.random()*30+5
var disY:Number =Math.random()*20+5
var deg:Number = Math.random()*360
var count:Number = 0;
var step:Number =64
var cx:Number = stage.stageWidth /2;
var cy:Number = stage.stageHeight /2;
var xPos:Number = posX * Math.sin(disX * count + deg) + cx;
var yPos:Number = posY * Math.sin(disY * count) + cy;
//gladationLine
var mtx:Matrix = new Matrix();
var gradCount=1
var gradDir=1
var life=0
var lifeLmt=150
//fader
var blurVall=4
var faderAlpha=0.9
var interval=3000
var _bd:BitmapData
var _bmp:Bitmap
var _blurF:BlurFilter
public function WonderFL() {
//messages.push(Math.floor(disX)+" : "+Math.floor(disY)+" : "+Math.floor(deg))
initFader()
initLissajous()
setMessage("","normal",0xFFFFFF)
var timerLmt=(messages.length-1)*2
var phaseCnt=0
var phase1:Timer = new Timer(interval, timerLmt);
phase1.addEventListener(TimerEvent.TIMER, function(e:Event){
if(!(phaseCnt%2)){
faderAlpha=0.8
typewriter(messages[phaseCnt/2])
}else{
faderAlpha=0.999
setMessage("","normal",0xFFFFFF)
}
switch(phaseCnt/2){
case 1:
txtFmt.size =20
break;
case 2:
txtFmt.size =30
drawPos.graphics.drawCircle(232.5, 232.5 , 200)
break
default:
txtFmt.size =30
break
}
phaseCnt++
});
phase1.start();
var phase2:Timer = new Timer((timerLmt)*interval+1500, 1);
phase2.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:Event){
drawPos.graphics.clear();
setMessage(messages[messages.length-1],"screen",0xFFFFFF)
startLissajous()
faderAlpha=0.992
});
phase2.start();
this.addChild(_bmp)
Layer.addChild(drawPos)
Layer.addChild(textPos)
textPos.addChild(textFields)
}
function setMessage(mes:String,blend:String,hex:Number){
txtFmt.font="Arial"
txtFmt.align = TextFormatAlign.CENTER;
txtFmt.color=hex
textFields.defaultTextFormat = txtFmt;
textFields.multiline=true
textFields.autoSize=TextFieldAutoSize.LEFT
textFields.x =0
textFields.y = 0
textFields.text=mes
textPos.alpha=0.5
textPos.blendMode=blend
textPos.x=stage.stageWidth/2-textFields.width/2
textPos.y=stage.stageHeight/2-textFields.height/2
}
function typewriter(str:String){
var n:uint=0
var tmp=""
stage.addEventListener(Event.ENTER_FRAME, function(e:Event){
tmp=""
for (var i:uint=0;i<str.length-n;i++) {
tmp+=""
}
setMessage(str.substr(0,++n)+tmp,"normal",0xFF0000)
if(n==str.length){
stage.removeEventListener(Event.ENTER_FRAME,arguments.callee)
}
});
}
function initFader(){
_bd=new BitmapData(stage.stageWidth,stage.stageHeight,true,0x000000);
_bmp=new Bitmap(_bd);
_blurF=new BlurFilter(blurVall,blurVall,3);
stage.addEventListener(Event.ENTER_FRAME, function(e:Event){
render()
});
}
function render():void {
_bd.colorTransform(_bd.rect, new ColorTransform(1, 1, 1,faderAlpha, 0, 0, 0, 0));
_bd.applyFilter(_bd,_bd.rect,new Point(0,0),_blurF);
_bd.draw(Layer);
}
function initLissajous(){
mtx.createGradientBox(400, 400, 0, 0, 0);
drawPos.graphics.lineStyle(1);
drawPos.graphics.lineGradientStyle(GradientType.LINEAR, [0xFF0000, 0x0000FF], [0.5,0.5],[gradCount,255-gradCount], mtx, SpreadMethod.REFLECT);
drawPos.graphics.moveTo(xPos,yPos);
}
function startLissajous(){
stage.addEventListener(Event.ENTER_FRAME, function(e:Event){
drawLissajous()
});
}
function drawLissajous():void {
count+= step;
xPos = posX * Math.sin(disX * count + deg) + cx;
yPos = posY * Math.sin(disY * count) + cy;
if(gradCount>=255 || 0>=gradCount){
gradDir*=-1
}
gradCount+=gradDir
life=life>lifeLmt?0:life+1
if (life>lifeLmt) {
drawPos.graphics.clear()
drawPos.graphics.lineStyle(0.5);
drawPos.graphics.moveTo(xPos,yPos)
}
drawPos.graphics.lineGradientStyle(GradientType.LINEAR, [0xFF0000, 0xFF0000], [(gradCount/255),((255-gradCount)/255)],[0,255], mtx, SpreadMethod.REFLECT);
drawPos.graphics.lineTo(xPos,yPos);
}
}
}