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

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

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


forked from : borealkiss's 毛文字 [diff(207)]

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