※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


FORKED
  1. // forked from borealkiss's 毛文字
  2. package {
  3.     
  4.     /**
  5.      * どんな仕組みになっているか気になったので勉強をかねて、使いやすくリファクタリング
  6.      */
  7.     
  8.     import flash.display.BitmapData;
  9.     import flash.display.DisplayObject;
  10.     import flash.display.Sprite;
  11.     import flash.text.TextFormat;
  12.     
  13.     [SWF(width = "465", height = "465", frameRate = "60", backgroundColor = "#ffffff")]
  14.     public class Main extends Sprite {
  15.         
  16.         private const TEXT:String = "毛文字";
  17.         
  18.         public function Main() {
  19.             
  20.             var hairyText:DisplayObject = createHairyText( TEXT, new TextFormat( null100 ), 0.5 );
  21.             hairyText.x = ( stage.stageWidth - hairyText.width ) / 2;
  22.             hairyText.y = ( stage.stageHeight - hairyText.height ) / 2;
  23.             addChild( hairyText );
  24.         }
  25.     }
  26.  }
  27. import flash.display.Bitmap;
  28. import flash.display.DisplayObject;
  29. import flash.display.Sprite;
  30. import flash.display.Graphics;
  31. import flash.display.BitmapData;
  32. import flash.geom.Matrix;
  33. import flash.geom.Rectangle;
  34. import flash.text.TextFormat;
  35.  
  36. function createHairyText( text:String, textFormat:TextFormat = null, limit:Number = 1, longHairLength:Number = 0, alpha:Number = 0.5 ):DisplayObject {
  37.     
  38.     if ( !textFormat )
  39.         textFormat = new TextFormat();
  40.     
  41.     if ( !longHairLength )
  42.         longHairLength = ( ( textFormat.size ) ? Number( textFormat.size ) : 12 ) / 10;    // 12 は Flash Player 固有のフォーマットのフォントサイズ
  43.     
  44.     var bitmapData:BitmapData = textToBitmapData( text, textFormat );
  45.     
  46.     var sprite:Sprite = new Sprite();
  47.     var graphics:Graphics = sprite.graphics;
  48.     
  49.     graphics.clear();
  50.     graphics.lineStyle( 0uint( textFormat.color ), alpha );
  51.     
  52.     for ( var i:uint = 0; i < ( bitmapData.width * bitmapData.height ) * limit; i++ ) {
  53.         
  54.         var x:uint = ( limit != 1 ) ? Math.random() * bitmapData.width : i % bitmapData.width;
  55.         var y:uint = ( limit != 1 ) ? Math.random() * bitmapData.height : uint( i / bitmapData.width );
  56.         var color32:uint = bitmapData.getPixel32( x, y );
  57.         
  58.         if ( color32 != 0 ) {
  59.             
  60.             //Anchor point so that the hair goes outer.
  61.             var hairLength:Number = longHairLength * Math.random();
  62.             var hairRadian:Number = Math.random() * 2 * Math.PI;
  63.             var anchorX:Number = x + hairLength * Math.cos( hairRadian );
  64.             var anchorY:Number = y + hairLength * Math.sin( hairRadian );
  65.             
  66.             //Control point for the Bezier curve.
  67.             var controlDistance:Number = longHairLength * Math.random();
  68.             var controlRadian:Number = Math.random() * 2 * Math.PI;
  69.             var controlX:Number = x + controlDistance * Math.cos( controlRadian );
  70.             var controlY:Number = y + controlDistance * Math.sin( controlRadian );
  71.             
  72.             graphics.moveTo( x, y );
  73.             graphics.curveTo( controlX, controlY, anchorX, anchorY );
  74.         }
  75.     }
  76.     
  77.     return sprite;
  78.  }
  79. import flash.display.BitmapData;
  80. import flash.geom.Matrix;
  81. import flash.text.TextField;
  82. import flash.text.TextFormat;
  83. /**
  84.  * テキストをビットマップデータに変換する関数
  85.  */
  86. function textToBitmapData( text:String, textFormat:TextFormat = null ):BitmapData {
  87.     
  88.     // テキストフィールドの作成
  89.     var textField:TextField = new TextField();
  90.     textField.text = text;
  91.     
  92.     // テキストフォーマットの適用
  93.     if( textFormat )
  94.         textField.setTextFormat( textFormat );
  95.     
  96.     // テキストフィールドの幅、高さを調節。2 * 2 の意味は参考リンク参照。
  97.     textField.width = textField.textWidth + 2 * 2;
  98.     textField.height = textField.textHeight + 2 * 2;
  99.     
  100.     // ビットマップデータの作成
  101.     var bitmapData:BitmapData = new BitmapData( textField.width - 2 * 2, textField.height - 2 * 2true0 );
  102.     
  103.     // テキストフィールドをビットマップデータ上に描画。
  104.     bitmapData.draw( textField, new Matrix(1001, -2, -2) );
  105.     
  106.     return bitmapData;
  107. }
noswf
Get Adobe Flash Player