Created
July 24, 2012 09:40
-
-
Save crazymaster/3169132 to your computer and use it in GitHub Desktop.
Typography
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Copyright nitoyon ( http://wonderfl.net/user/nitoyon ) | |
| * Remix by master ( https://github.com/crazymaster ) | |
| * MIT License ( http://www.opensource.org/licenses/mit-license.php ) | |
| */ | |
| package | |
| { | |
| import flash.display.*; | |
| import flash.events.*; | |
| import flash.geom.*; | |
| import flash.text.*; | |
| import flash.utils.*; | |
| import flash.net.*; | |
| [SWF(backgroundColor="0x000000",width="475",height="475",frameRate="30")] | |
| public class Main extends MovieClip | |
| { | |
| private static var SIZE:Number = 475; | |
| private static var R:Number = SIZE-150; | |
| private static var HR:Number = R / 2; | |
| private var particles:Vector.<Number>; | |
| private var letterPoints:Vector.<Number>; | |
| private var colors:Vector.<uint>; | |
| private static var backColor:uint = 0x000000; | |
| private static var lettersColor:uint = 0x80FFFF; | |
| private static var lettersFont:String="_sans"; | |
| //[Embed(fontName='fontSouei',source='c:\\windows\\fonts\\HGRPRE.TTC', fontFamily='HGP創英プレゼンスEB', mimeType='application/x-font', embedAsCFF='false')] | |
| //private static var embedFont1:Class; | |
| // 光らせるための BitmapData | |
| private var canvasGlow:BitmapData; | |
| // 1/4 で描画するための Matrix | |
| private var mtx:Matrix = new Matrix(0.25, 0, 0, 0.25); | |
| private var bmd:BitmapData; | |
| private var canvas:BitmapData; | |
| private var uvts:Vector.<Number>; | |
| private var particles2:Vector.<Number>; | |
| private var mtx3d:Matrix3D; | |
| // 透視投影用の変換行列作成 | |
| private var proj:PerspectiveProjection; | |
| private var projMat:Matrix3D; | |
| private var bmp:Bitmap; | |
| private var canvasp:Bitmap; | |
| // ループ用の変数を用意 | |
| private var counter:int; | |
| private var moveCounter:int; | |
| private var xysRandom:Vector.<Number>; | |
| private var xys:Vector.<Number>; | |
| private var f:Boolean; | |
| private var timer1:int; | |
| public function Main():void | |
| { | |
| initialize(); | |
| stage.addEventListener(Event.RESIZE,Resize); | |
| // ループ処理 | |
| addEventListener("enterFrame",onEnterFrame); | |
| // 定期的に f を反転させる | |
| setInterval(function():void | |
| { | |
| f = true; | |
| }, 6000); | |
| } | |
| private function initialize():void | |
| { | |
| stage.scaleMode = StageScaleMode.NO_SCALE; | |
| stage.align = "TL"; | |
| SIZE = stage.stageHeight; | |
| this.x = (stage.stageWidth -SIZE)/2; | |
| R = SIZE-150; | |
| HR = R / 2; | |
| particles = new Vector.<Number>(); | |
| letterPoints = new Vector.<Number>(); | |
| colors = new Vector.<uint>(); | |
| // BitmapData にテキストを描画して座標を points に格納する | |
| bmd = createBitmapData("InternetClub"); | |
| initParticles(bmd); | |
| // キャンバスを準備 | |
| canvas = new BitmapData(SIZE, SIZE, false, backColor); | |
| canvasp = new Bitmap(canvas) | |
| addChild(canvasp); | |
| // FP10 用 座標変換の準備 | |
| uvts = new Vector.<Number>(); | |
| particles2 = new Vector.<Number>(); | |
| mtx3d = new Matrix3D(); | |
| // 透視投影用の変換行列作成 | |
| proj = new PerspectiveProjection(); | |
| proj.fieldOfView = 90; | |
| projMat = proj.toMatrix3D(); | |
| // 光らせるための BitmapData を初期化する | |
| canvasGlow = new BitmapData(SIZE / 4, SIZE / 4, false, backColor); | |
| bmp = new Bitmap(canvasGlow, PixelSnapping.NEVER, true); | |
| bmp.scaleX = bmp.scaleY = 4; | |
| bmp.smoothing = true; | |
| bmp.blendMode = BlendMode.ADD; | |
| //bmp.blendMode = BlendMode.MULTIPLY; | |
| addChild(bmp); | |
| // ループ用の変数を用意 | |
| timer1 = 0; | |
| counter = 0; | |
| moveCounter = 0; | |
| xysRandom = new Vector.<Number>(); | |
| xys = new Vector.<Number>(letterPoints.length); | |
| f = false; | |
| } | |
| private function onEnterFrame(event:Event):void | |
| { | |
| // 角度を設定して座標変換する (particles → particles2) | |
| mtx3d.identity(); | |
| mtx3d.appendRotation(counter, Vector3D.Y_AXIS); | |
| mtx3d.appendRotation(15, Vector3D.X_AXIS); | |
| mtx3d.appendTranslation(0, 0, SIZE / 2); | |
| mtx3d.transformVectors(particles, particles2); | |
| // 透視投影して回転後の座標を計算する | |
| Utils3D.projectVectors(projMat, particles2, xysRandom, uvts); | |
| // moveCounter 以下ならパーティクルを文字列の配置に近づける | |
| // そうでない場合はあらかじめ定義したランダム位置の配置に近づける | |
| for (var i:int = 0; i < xysRandom.length; i++) | |
| { | |
| if (i < moveCounter * 2) | |
| { | |
| xys[i] += (letterPoints[i] - xys[i]) * .13; | |
| } | |
| else | |
| { | |
| xys[i] += (xysRandom[i] - xys[i]) * .12; | |
| } | |
| } | |
| // 文字列表示中はmoveCounter を加算する | |
| moveCounter = (f ? moveCounter + 100 : 0); | |
| // BitmapData に描画する | |
| canvas.lock(); | |
| canvas.fillRect(canvas.rect, backColor); | |
| for (i = 0; i < xys.length / 2; i++) | |
| { | |
| canvas.setPixel(xys[i * 2] + SIZE / 2, xys[i * 2 + 1] + SIZE / 2, colors[i]); | |
| } | |
| canvas.unlock(); | |
| // 光らせるためのキャンバスにコピーする | |
| canvasGlow.fillRect(canvasGlow.rect, backColor); | |
| canvasGlow.draw(canvas, mtx); | |
| counter++; | |
| timer1++; | |
| if (f && timer1 == 400) { | |
| pagechange(); | |
| } | |
| } | |
| private function Resize(event:Event):void | |
| { | |
| removeChild(bmp); | |
| removeChild(canvasp); | |
| initialize(); | |
| } | |
| private static function createBitmapData(letters:String):BitmapData | |
| { | |
| var fmt:TextFormat = new TextFormat(); | |
| fmt.size = SIZE * 0.1; | |
| fmt.font = lettersFont; | |
| var tf:TextField = new TextField(); | |
| //tf.embedFonts = true; | |
| tf.defaultTextFormat = fmt; | |
| tf.autoSize = "left"; | |
| tf.textColor = lettersColor; | |
| tf.text = letters; | |
| var bmd:BitmapData = new BitmapData(tf.textWidth, tf.textHeight, false, backColor); | |
| var mtx:Matrix = new Matrix(); | |
| bmd.draw(tf, mtx); | |
| return bmd; | |
| } | |
| private function initParticles(bmd:BitmapData):void | |
| { | |
| for (var yy:int = 0; yy < bmd.height; yy++) | |
| { | |
| for (var xx:int = 0; xx < bmd.width; xx++) | |
| { | |
| var c:uint = bmd.getPixel(xx, yy); | |
| if (c != backColor) | |
| { | |
| letterPoints.push(xx - SIZE*0.28, yy - SIZE*0.04); | |
| //letterPoints.push(xx - 220, yy - 20); | |
| particles.push(R * Math.random() - HR, R * Math.random() - HR, R * Math.random() - HR); | |
| colors.push(c); | |
| } | |
| } | |
| } | |
| } | |
| private function pagechange():void | |
| { | |
| // URLRequestを設定 | |
| var url:URLRequest = new URLRequest( "top.html"); | |
| // 実際にページに飛ぶ | |
| navigateToURL( url,"_self"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment