Adobe System

drawTriangleの応募作品はいずれもオリジナリティがありとても参考になりました。 Text Layout Frameworkはこれからより多くの作品が出てくると思いますが、Text Layout Frameworkは、ゲーム開発や画像の取り込んだクリエイティブな挑戦ができるポテンシャルを持っています。是非、チャレンジしてみてください。 wonderfl build flash onlineのユーザーのみなさんが、今後もwonderflをつかって、クリエイティブ・チャレンジをしていただけることを期待しています。

Many drawTriangle works were full of originality and were good foods for thought.
There should be more Text Layout Framework works coming up in near future. Text Layout Framework has potential to take part in game development or creative work with images. Please give it a try.
For the user of wonderfl build flash online, by using wonderfl, we are looking forward to your creative challenges.

Present

1位
CHECKMATE覆面
iPod shuffle
(Adobe Flash Player Teamからのメッセージ入り!)
2位
CHECKMATE覆面
Adobe&CHECKMATEせんべい
3位
CHECKMATE覆面

Queenmtok

  1. // forked from checkmate's adobe challenge 1
  2. /**
  3.  * 
  4.  * "Use Flash Player 10 drawing API,
  5.  *  specifically drawTriangles.
  6.  *  My favorite part of the new capabilities
  7.  *  is the ability to specify
  8.  *  UVT texture mapping data."
  9.  *                     by Justin Everett-Church
  10.  *  
  11.  * This code is a example of drawTriangle.
  12.  */
  13. package {
  14.     import flash.display.Bitmap;
  15.     import flash.display.BitmapData;
  16.     import flash.display.Graphics;
  17.     import flash.display.Loader;
  18.     import flash.display.LoaderInfo;
  19.     import flash.display.Sprite;
  20.     import flash.events.Event;
  21.     import flash.geom.Point;
  22.     import flash.net.URLLoader;
  23.     import flash.net.URLRequest;
  24.     import flash.system.LoaderContext;
  25.     import flash.system.Security;
  26.     import fl.motion.easing.*;
  27.     import flash.utils.setInterval;
  28.     import flash.utils.clearInterval;
  29.     
  30.     import com.flashdynamix.motion.Tweensy;
  31.     import com.flashdynamix.motion.TweensyTimeline;
  32.     
  33.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="24")]
  34.     public class DrawTriangleTest extends Sprite{
  35.     
  36.         private var bushUrl:String = "http://www.matzmtok.com/wonderfl/checkmate/bush.xml";
  37.         private var obamaUrl:String = "http://www.matzmtok.com/wonderfl/checkmate/obama.xml";
  38.         private var bushImgUrl:String = "http://www.matzmtok.com/wonderfl/checkmate/image/bush.png";
  39.         private var obamaImgUrl:String = "http://www.matzmtok.com/wonderfl/checkmate/image/obama.png";
  40.         private var bushBmpData:BitmapData;
  41.         private var obamaBmpData:BitmapData;
  42.         
  43.         private var interval:int;
  44.         private var chkFlag:uint;
  45.         
  46.         private var oScreen:Sprite;
  47.         private var bScreen:Sprite;
  48.         
  49.         private var bVerD:Vector.<Number>;
  50.         private var oVerD:Vector.<Number>;
  51.         private var verD:Vector.<Number>;
  52.         
  53.         private var oIndD:Vector.<int>;
  54.         private var bIndD:Vector.<int>;
  55.         
  56.         private var bUvtD:Vector.<Number>;
  57.         private var oUvtD:Vector.<Number>;
  58.         
  59.         private var sw:Number = 465;
  60.         private var sh:Number = 465;
  61.         
  62.         public function DrawTriangleTest() {
  63.             
  64.             addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
  65.         } 
  66.         
  67.         private function addedToStageHandler(e:Event):void 
  68.         {
  69.             
  70.             trace('initialize');
  71.                         Wonderfl.disable_capture();
  72.                         Wonderfl.capture_delay( 3 );
  73.             removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
  74.             
  75.             Security.loadPolicyFile("http://www.matzmtok.com/wonderfl/crossdomain.xml");
  76.             
  77.             addChild(oScreen = new Sprite());
  78.             addChild(bScreen = new Sprite());
  79.             
  80.             interval = setInterval(waitInitialze, 500);
  81.             
  82.             var l1:URLLoader = new URLLoader();
  83.             l1.load(new URLRequest(bushUrl));
  84.             l1.addEventListener(Event.COMPLETE, bushLoadCompleteHandler);
  85.             
  86.             var l2:URLLoader = new URLLoader();
  87.             l2.load(new URLRequest(obamaUrl));
  88.             l2.addEventListener(Event.COMPLETE, obamaLoadCompleteHandler);
  89.             
  90.             var lc:LoaderContext = new LoaderContext(true);
  91.             var l3:Loader = new Loader();
  92.             l3.load(new URLRequest(bushImgUrl), lc);
  93.             l3.contentLoaderInfo.addEventListener(Event.COMPLETE, bushImagLoadCompleteHandler);
  94.             var l4:Loader = new Loader();
  95.             l4.load(new URLRequest(obamaImgUrl), lc);
  96.             l4.contentLoaderInfo.addEventListener(Event.COMPLETE, obamaImgLoadCompleteHandler);
  97.         }
  98.         
  99.         private function obamaImgLoadCompleteHandler(e:Event):void 
  100.         {
  101.             trace('complete obama img');
  102.             var l:LoaderInfo = e.target as LoaderInfo;
  103.             var bmp:Bitmap;
  104.             
  105.             bmp = l.content as Bitmap;
  106.             obamaBmpData = new BitmapData(bmp.width, bmp.height, true);
  107.             obamaBmpData.draw(bmp);
  108.             
  109.             chkFlag |= 0x01;
  110.         }
  111.         
  112.         private function bushImagLoadCompleteHandler(e:Event):void 
  113.         {
  114.             trace('complete bush img');
  115.             var l:LoaderInfo = e.target as  LoaderInfo;
  116.             var bmp:Bitmap;
  117.             
  118.             bmp = l.content as Bitmap;
  119.             bushBmpData = new BitmapData(bmp.width, bmp.height, true);
  120.             bushBmpData.draw(bmp);
  121.             chkFlag |= 0x02;
  122.         }
  123.         
  124.         private function obamaLoadCompleteHandler(e:Event):void 
  125.         {
  126.             trace('complete obma xml');
  127.             var l:URLLoader = e.target as URLLoader;
  128.             var xml:XML = new XML(l.data);
  129.             var pts:Array = [];
  130.             var _x:Number, _y:Number;
  131.             var xl:XMLList = xml.points.point;
  132.             oVerD = new Vector.<Number>();
  133.             oUvtD = new Vector.<Number>();
  134.             for each(var p:XML in xl) {
  135.                 _x = Number(p.@x);
  136.                 _y = Number(p.@y);
  137.                 oVerD.push(_x, _y);
  138.                 oUvtD.push(_x / sw, _y / sh);
  139.             }
  140.             
  141.             oIndD = new Vector.<int>();
  142.             xl = xml.triangles.triangle;
  143.             var i:int;
  144.             for each(var t:XML in xl) {
  145.                 i = int(t.@pid0);
  146.                 oIndD.push(i);
  147.                 i = int(t.@pid1);
  148.                 oIndD.push(i);
  149.                 i = int(t.@pid2);
  150.                 oIndD.push(i);
  151.             }
  152.             chkFlag |= 0x04;
  153.         }
  154.         
  155.         private function bushLoadCompleteHandler(e:Event):void 
  156.         {
  157.             trace('complete bush xml');
  158.             var l:URLLoader = e.target as URLLoader;
  159.             var xml:XML = new XML(l.data);
  160.             var pts:Array = [];
  161.             var _x:Number, _y:Number;
  162.             var xl:XMLList = xml.points.point;
  163.             bVerD = new Vector.<Number>();
  164.             bUvtD = new Vector.<Number>();
  165.             for each(var p:XML in xl) {
  166.                 _x = Number(p.@x);
  167.                 _y = Number(p.@y);
  168.                 bVerD.push(_x, _y);
  169.                 bUvtD.push(_x / sw, _y / sh);
  170.             }
  171.             
  172.             bIndD = new Vector.<int>();
  173.             xl = xml.triangles.triangle;
  174.             var i:int;
  175.             for each(var t:XML in xl) {
  176.                 i = int(t.@pid0);
  177.                 bIndD.push(i);
  178.                 i = int(t.@pid1);
  179.                 bIndD.push(i);
  180.                 i = int(t.@pid2);
  181.                 bIndD.push(i);
  182.             }
  183.             chkFlag |= 0x08;            
  184.         }
  185.         
  186.         private function waitInitialze():void {
  187.             if (chkFlag == 0x0F) {
  188.                 clearInterval(interval);
  189.                 
  190.                 verD = new Vector.<Number>(oVerD.length,false);
  191.                                 
  192.                 oScreen.alpha = 0.0;
  193.                 bScreen.alpha = 1;
  194.                 var tl:TweensyTimeline = Tweensy.to(bScreen, { alpha:0.0 }, 2, Linear.easeNone);
  195.                 tl.onUpdateParams = [tl];
  196.                 tl.onUpdate = update;
  197.                 tl.repeatType = TweensyTimeline.LOOP;
  198.             }
  199.         }
  200.         private function update(timeline:TweensyTimeline):void {
  201.             oScreen.alpha = 1 - bScreen.alpha;
  202.             var g:Graphics;
  203.             g = bScreen.graphics;
  204.             
  205.             for (var i:int = 0; i < oVerD.length; i++) {
  206.                 verD[i] = bVerD[i] + (oVerD[i] - bVerD[i]) * oScreen.alpha;
  207.             }
  208.             
  209.             //bush
  210.             g.clear();
  211.             g.beginBitmapFill(bushBmpData);
  212.             g.drawTriangles(verD, oIndD, bUvtD);
  213.             g.endFill();
  214.             //obama
  215.             g = oScreen.graphics;
  216.             g.clear();
  217.             g.beginBitmapFill(obamaBmpData);
  218.             g.drawTriangles(verD, oIndD, oUvtD);
  219.             g.endFill();
  220.         }
  221.     }
  222. }
flash swf thumbnail play
出題者からのコメント
非常に感動的な作品でした。モーフィングがスムーズで、表現がとても優れています。
Adobe Flash Player シニアプロダクトマネージャー Justin Everett-Church
Comments from Sponsor
It is impressive. Peformance is also good and very smooth morphing.
by Adobe, Flash Player sr-product manager Justin Everett-Church

Bishopnutsu

  1. // forked from checkmate's adobe challenge 1
  2. /**
  3.  * 
  4.  * "Use Flash Player 10 drawing API,
  5.  *  specifically drawTriangles.
  6.  *  My favorite part of the new capabilities
  7.  *  is the ability to specify
  8.  *  UVT texture mapping data."
  9.  *                     by Justin Everett-Church
  10.  *  
  11.  * This code is a example of drawTriangle.
  12.  */
  13. package {
  14.     
  15.     //Kaleidoscope:
  16.     //Web camera is required.
  17.     
  18.     import flash.display.*;
  19.     import flash.events.*;
  20.     import flash.geom.Matrix;
  21.     import flash.media.Camera;
  22.     import flash.media.Video;
  23.     import flash.text.TextField;
  24.     import flash.net.FileReference;
  25.     import flash.net.FileFilter;
  26.     
  27.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")]
  28.     public class drawTriangleTest extends Sprite{
  29.     
  30.         private var bmpd     :BitmapData;
  31.         
  32.         private var verD     :Vector.<Number>;
  33.         private var indD     :Vector.<int>;
  34.         private var uvtD     :Vector.<Number>;
  35.         private var uvID     :Vector.<int>;
  36.         private var uvVal    :Vector.<Number>;
  37.         private var _display :DisplayObject;
  38.         private var ptnShape :Shape;
  39.         private var ptn      :BitmapData;
  40.         
  41.         private var camera   :Camera;
  42.         private var video    :Video;
  43.         
  44.         private var mtx:Matrix;
  45.         private var mtxt:Matrix;
  46.         private var mtx0:Matrix;
  47.         
  48.         private var psize    :Number = 100;
  49.         private var hx       :Number = 465 / 2;
  50.         private var hy       :Number = 465 / 2;
  51.         private var tx       :Number = hx;
  52.         private var ty       :Number = hy;
  53.         private var a        :Number = 0;
  54.         
  55.         private var fileReference:FileReference;
  56.         private var loader:Loader;
  57.         
  58.         public function drawTriangleTest() {
  59.             
  60.             initTriangles();
  61.             
  62.             //texture src triangle
  63.             bmpd = new BitmapData( 320240 );
  64.             ptn  = new BitmapData( 3 * psize, 2 * psize * Math.sin(Math.PI / 3 ) );
  65.             ptnShape = new Shape();
  66.             mtx  = new Matrix();
  67.             mtx0 = new Matrix();
  68.             mtxt = new Matrix( 1001, psize / 2 );
  69.             
  70.             camera = Camera.getCamera();
  71.             if ( camera == null ) {
  72.                 setAltImage();
  73.             }else {
  74.                 camera.setMode(32024015);
  75.                 video = new Video(320240);
  76.                 video.attachCamera(camera);
  77.                 _display = video;
  78.                 camera.addEventListener(ActivityEvent.ACTIVITY, cameraStart);
  79.             }
  80.         }
  81.         
  82.         private function cameraStart(e:ActivityEvent):void {
  83.             camera.removeEventListener( ActivityEvent.ACTIVITY, cameraStart );
  84.             addEventListener( Event.ENTER_FRAME, handleEnterFrame );
  85.         }
  86.         
  87.         private function handleEnterFrame(e:Event):void {            
  88.             bmpd.draw( _display, mtx0 );
  89.             
  90.             tx += ( mouseX - tx ) * 0.2;
  91.             ty += ( mouseY - ty ) * 0.2;
  92.             
  93.             var ra:Number = 2 * Math.PI * (hx - tx) / 465;
  94.             var nv:Number = 0.5 - 0.4 * Math.min( 1, Math.abs(ty/465) );
  95.             
  96.             var i:int;
  97.             for ( i = 0; i < 3; i++ ) {
  98.                 var aa:Number = ra + i * 2 * Math.PI / 3;
  99.                 uvVal[i*2]   = ( 0.5 + nv * Math.cos( aa ) );
  100.                 uvVal[i*2+1] = ( 0.5 + nv * Math.sin( aa ) );
  101.             }
  102.             var len:int = uvID.length;
  103.             for ( i = 0; i < len; i++ ) {
  104.                 uvtD[i] = uvVal[ uvID[i] ];
  105.             }
  106.             
  107.             ptnShape.graphics.clear();
  108.             ptnShape.graphics.beginBitmapFill( bmpd );
  109.             ptnShape.graphics.drawTriangles( verD, indD, uvtD );
  110.             ptnShape.graphics.endFill();
  111.             ptn.draw( ptnShape, mtxt );
  112.             
  113.             mtx.identity();
  114.             mtx.scale( nv / 0.5, nv / 0.5 );
  115.             mtx.rotate( a );
  116.             mtx.translate( hx, hy );
  117.             graphics.clear();
  118.             graphics.beginBitmapFill( ptn, mtx, true );
  119.             graphics.drawRect( 00465465 );
  120.             graphics.endFill();
  121.             a += 0.005;
  122.         }
  123.         
  124.         private function initTriangles():void {
  125.             var xx:Number = psize;
  126.             var yy:Number = psize * Math.sin(Math.PI / 3 );;
  127.             
  128.             uvVal = Vector.<Number>( [0,0,1,0,1,1] );
  129.             verD  = new Vector.<Number>();
  130.             uvID  = new Vector.<int>();
  131.             
  132.             verD.push( xx, yy );
  133.             uvID.push( 01 );//0
  134.             var uf:Boolean = true;
  135.             for ( var i:int = 0; i < 6; i++ ) {
  136.                 var vx:Number = psize * Math.cos( i * Math.PI / 3 );
  137.                 var vy:Number = psize * Math.sin( i * Math.PI / 3 );
  138.                 verD.push( xx + vx, yy + vy );
  139.                 if( uf=!uf )
  140.                     uvID.push( 23 ); //1
  141.                 else
  142.                     uvID.push( 45 ); //2
  143.             }
  144.             
  145.             var ex:Number = psize * Math.cos( Math.PI / 3 );
  146.             verD.push( 3 * xx,  yy );
  147.             uvID.push( 23 );//1
  148.             verD.push( 2 * xx + ex,  2 * yy );
  149.             uvID.push( 01 );//0
  150.             verD.push( - ex,  2 * yy );
  151.             uvID.push( 01 );//0
  152.             verD.push( - xx,  yy );
  153.             uvID.push( 45 );//2
  154.             verD.push( - ex,  0 );
  155.             uvID.push( 01 );//0
  156.             verD.push( 2 * xx + ex,  0 );
  157.             uvID.push( 01 );//0
  158.             
  159.             uvtD = new Vector.<Number>( uvID.length );
  160.             
  161.             indD = Vector.<int>([
  162.                     012,
  163.                     023,
  164.                     034,
  165.                     045,
  166.                     056,
  167.                     061,
  168.                     178,
  169.                     182,
  170.                     394,
  171.                     4910,
  172.                     41011,
  173.                     4115,
  174.                     6121,
  175.                     1127 ]);
  176.         }
  177.         
  178.         private function setAltImage():void {
  179.             var tf:TextField = new TextField();
  180.             tf.autoSize = "left";
  181.             tf.x = 20;
  182.             tf.y = 20;
  183.             tf.text = "WebCamera is required.\nClick stage to select alternative image.";
  184.             tf.selectable = false;
  185.             tf.textColor = 0xffffff;
  186.             addChild( tf );
  187.             //
  188.             fileReference = new FileReference();
  189.             fileReference.addEventListener( Event.SELECT, select );
  190.             fileReference.addEventListener( Event.COMPLETE, complete );
  191.             loader = new Loader();
  192.             loader.contentLoaderInfo.addEventListener( Event.INIT, imageInit );
  193.             //
  194.             stage.addEventListener( MouseEvent.CLICK, ffstart );
  195.         }
  196.         
  197.         private function ffstart( e:MouseEvent ):void {
  198.             var fileFilter:FileFilter = new FileFilter("Images""*.jpg;*.gif;*.png");
  199.             fileReference.browse([fileFilter]);
  200.         }
  201.         
  202.         private function select( e:Event ):void {
  203.             fileReference.load();
  204.         }
  205.         
  206.         private function complete(e:Event):void {
  207.             loader.loadBytes( fileReference.data );
  208.         }
  209.         
  210.         private function imageInit(e:Event):void {
  211.             removeChildAt( 0 );
  212.             _display = Bitmap( loader.content );
  213.             mtx0 = new Matrix( 320 / _display.width, 00240 / _display.height );
  214.             loader.removeEventListener( Event.INIT, imageInit );
  215.             stage.removeEventListener( MouseEvent.CLICK, ffstart );
  216.             fileReference.removeEventListener( Event.SELECT, select );
  217.             fileReference.removeEventListener( Event.COMPLETE, complete );
  218.             addEventListener( Event.ENTER_FRAME, handleEnterFrame );
  219.         }
  220.     }
  221. }
flash swf thumbnail play
出題者からのコメント
ウェブカムを使った表現として優れています。このアプローチは、とても良かったです。
Adobe Flash Player シニアプロダクトマネージャー Justin Everett-Church
Comments from Sponsor
Performance is also good using WebCam. This aproach is very good.
by Adobe, Flash Player sr-product manager Justin Everett-Church

KnightAquioux

  1. // forked from checkmate's adobe challenge 1
  2. /**
  3.  * 
  4.  * "Use Flash Player 10 drawing API,
  5.  *  specifically drawTriangles.
  6.  *  My favorite part of the new capabilities
  7.  *  is the ability to specify
  8.  *  UVT texture mapping data."
  9.  *                     by Justin Everett-Church
  10.  *  
  11.  * This code is a example of drawTriangle.
  12.  */
  13. /** 
  14.  * Elastic Rectangle を改造して布っぽいものにしてみました。
  15.  * http://wonderfl.net/code/e040d9da0f2a2bb74095a325a5a0dd9cdab7c5cb
  16.  * "a" でアンカー、"j" でジョイントの表示・非表示切り替えはそのまま
  17.  * perlinNoise による模様の代わりに WebCamera の映像を変形させます。 
  18.  */
  19. package {
  20.     
  21.     import flash.display.Bitmap;
  22.     import flash.display.BitmapData;
  23.     import flash.display.GraphicsBitmapFill;
  24.     import flash.display.GraphicsEndFill;
  25.     import flash.display.GraphicsPath;
  26.     import flash.display.GraphicsSolidFill;
  27.     import flash.display.GraphicsTrianglePath;
  28.     import flash.display.GraphicsStroke;
  29.     import flash.display.IGraphicsData;
  30.     import flash.display.Sprite;
  31.     import flash.events.Event;
  32.     import flash.events.KeyboardEvent;
  33.     import flash.events.MouseEvent;
  34.     import flash.media.Camera;
  35.     import flash.media.Video;
  36.     
  37.     [SWF(width="600", height="600", backgroundColor="0x000000", frameRate="60")]
  38.     public class drawTriangleTest extends Sprite{
  39.     
  40.         // セグメント数関連
  41.         private const SEGMENT_W:uint = 7;
  42.         private const SEGMENT_H:uint = 5;
  43.         
  44.         // イメージの BitmapData
  45.         private var imageBitmapData:BitmapData;
  46.         
  47.         // セグメント化クラス
  48.         private var segmentation:Segmentation;
  49.         
  50.         // コンテナ
  51.         private var anchorContainer:Sprite;
  52.         private var jointContainer:Sprite;
  53.         private var imageContainer:Sprite;
  54.         // 格納 Vector
  55.         private var anchorVector:Vector.<Anchor>;
  56.         private var jointVector:Vector.<Joint>;
  57.         
  58.         // ジョイント生成用
  59.         private var anchorPairVector:Vector.<int>;
  60.         
  61.         // イメージ表示用 GraphicsData
  62.         private var imageGraphicsData:Vector.<IGraphicsData>;
  63.         private var trianglePath:GraphicsTrianglePath;
  64.         // ジョイント表示用 GraphicsData
  65.         private var jointGraphicsData:Vector.<IGraphicsData>;
  66.         private var jointPath:GraphicsPath;
  67.         
  68.         private var draggingAnchor:Anchor;
  69.         private var anchorVisible:Boolean = false;
  70.         private var jointVisible:Boolean  = false;
  71.         private var camera:Camera;
  72.         private var video:Video;
  73.         private const CAMERA_WIDTH:uint  = 180;
  74.         private const CAMERA_HEIGHT:uint = 280;
  75.         public function drawTriangleTest() {
  76.             Wonderfl.capture_delay(10);
  77.             
  78.             // カメラ
  79.             camera = Camera.getCamera();
  80.             if (camera != null) {
  81.                 setup();
  82.             } else {
  83.                 throw new Error("カメラがありません。");
  84.             }
  85.         }
  86.         
  87.         private function setup():void {
  88.             // camera のセットアップ
  89.             camera.setMode(CAMERA_WIDTH, CAMERA_HEIGHT, 60);
  90.             
  91.             // video のセットアップ
  92.             video = new Video(CAMERA_WIDTH, CAMERA_HEIGHT);
  93.             video.attachCamera(camera);
  94.             imageBitmapData = new BitmapData(CAMERA_WIDTH, CAMERA_HEIGHT);
  95.             imageBitmapData.draw(video);
  96.             
  97.             next();
  98.         }
  99.         
  100.         private function next():void {
  101.             // セグメント化クラスのインスタンス生成
  102.             segmentation = new Segmentation(SEGMENT_W, SEGMENT_H);
  103.             
  104.             // 各コンテナの生成
  105.             initStage();
  106.             // GraphicsTrianglePath 用 Vector の生成
  107.             var verticies:Vector.<Number> = new Vector.<Number>();        // vertics の生成
  108.             var indicies:Vector.<int>   = segmentation.getIndicies();    // inducides の生成
  109.             var uvDatas:Vector.<Number> = segmentation.getUvDatas();    // uvDatas の生成
  110.             
  111.             // imageGraphicsData の生成
  112.             imageGraphicsData = new Vector.<IGraphicsData>(3);
  113.             imageGraphicsData.push(new GraphicsBitmapFill(imageBitmapData));
  114.             imageGraphicsData.push(trianglePath = new GraphicsTrianglePath(verticies, indicies, uvDatas));
  115.             imageGraphicsData.push(new GraphicsEndFill());
  116.             
  117.             // アンカーの生成(↑で作った uvDatas を使う)
  118.             createAnchor(uvDatas);
  119.             // アンカーのペアリング
  120.             anchorPairVector = segmentation.getVertexPair();
  121.             
  122.             // ジョイントの生成
  123.             createJoint();
  124.             // 固定アンカーの設定
  125.             var anchor:Anchor = anchorVector[0];
  126.             anchor.isFix = true;
  127.             anchor.x = 20;
  128.             anchor = anchorVector[SEGMENT_W];
  129.             anchor.isFix = true;
  130.             anchor.x = stage.stageWidth - 20;
  131.             
  132.             // ジョイント表示用 graphicsData の生成
  133.             // 線の状態
  134.             var stroke:GraphicsStroke = new GraphicsStroke(0);
  135.             stroke.fill = new GraphicsSolidFill(0xFF0000, 0.5);
  136.             // パス
  137.             var commands:Vector.<int> = segmentation.getPathCommands(anchorPairVector);            // コマンド
  138.             var data:Vector.<Number> = segmentation.getPathData(anchorVector, anchorPairVector);// データ
  139.             jointPath = new GraphicsPath(commands, data);
  140.             // GraphicsData
  141.             jointGraphicsData = new Vector.<IGraphicsData>(2);
  142.             jointGraphicsData.push(stroke);
  143.             jointGraphicsData.push(jointPath);
  144.             
  145.             // イベントハンドラ
  146.             anchorContainer.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  147.             anchorContainer.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  148.             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  149.             addEventListener(Event.ENTER_FRAME, enterFrameHandlerandler);
  150.         }
  151.         
  152.         // 各コンテナの生成
  153.         private function initStage():void {
  154.             imageContainer  = new Sprite();
  155.             jointContainer  = new Sprite();
  156.             anchorContainer = new Sprite();
  157.             addChild(imageContainer);
  158.             addChild(jointContainer);
  159.             addChild(anchorContainer);
  160.         }
  161.         
  162.         // アンカーの生成
  163.         private function createAnchor(uvData:Vector.<Number>):void {
  164.             Anchor.left   = 0;
  165.             Anchor.right  = stage.stageWidth;
  166.             Anchor.top    = 0;
  167.             Anchor.bottom = stage.stageHeight;
  168.             var n:uint = uvData.length / 2;
  169.             anchorVector = new Vector.<Anchor>(n);
  170.             var imageWidth:uint  = imageBitmapData.width;
  171.             var imageHeight:uint = imageBitmapData.height;
  172.             var offsetX:Number = (stage.stageWidth  - imageWidth)  / 2;
  173.             var offsetY:Number = 20;//(stage.stageHeight - imageHeight) / 2;
  174.             for (var i:uint = 0; i < n; i++) {
  175.                 var anchor:Anchor = new Anchor(15, 0xFFFFFF);
  176.                 anchor.x = imageWidth  * uvData[i * 2]     + offsetX;
  177.                 anchor.y = imageHeight * uvData[i * 2 + 1] + offsetY;
  178.                 anchorContainer.addChild(anchor);
  179.                 anchorVector[i] = anchor;
  180.             }
  181.         }
  182.         
  183.         // ジョイントの生成
  184.         private function createJoint():void {
  185.             var n:uint = anchorPairVector.length / 2;
  186.             jointVector = new Vector.<Joint>(n);
  187.             for (var i:uint = 0; i < n; i++) {
  188.                 var a:uint = anchorPairVector[i * 2];
  189.                 var b:uint = anchorPairVector[i * 2 + 1];
  190.                 var joint:Joint = new Joint(anchorVector[a], anchorVector[b]);
  191.                 jointVector[i] = joint;
  192.             }
  193.         }
  194.         
  195.         // キーボードイベント
  196.         private function keyDownHandler(event:KeyboardEvent):void {
  197.             if (event.charCode == 97) {        // "a" キーでアンカー表示
  198.                 anchorVisible = !anchorVisible;
  199.                 for each (var anchor:Anchor in anchorVector) {
  200.                     anchor.isVisible = anchorVisible;
  201.                 }
  202.             }
  203.             if (event.charCode == 106) {    // "j" キーでジョイント表示
  204.                 jointVisible = !jointVisible;
  205.                 if (!jointVisible) {
  206.                     jointContainer.graphics.clear();
  207.                 }
  208.             }
  209.         }
  210.         // マウスイベント
  211.         private function mouseDownHandler(event:MouseEvent):void {
  212.             draggingAnchor = Anchor(event.target);
  213.             draggingAnchor.mouseDown(true);
  214.         }
  215.         private function mouseUpHandler(event:MouseEvent):void {
  216.             if (draggingAnchor != null) {
  217.                 draggingAnchor.mouseDown(false);
  218.             }
  219.         }
  220.         // フレームイベント
  221.         private function enterFrameHandlerandler(event:Event):void {
  222.             for each (var joint:Joint in jointVector) {
  223.                 joint.update();
  224.             }
  225.             for each (var anchor:Anchor in anchorVector) {
  226.                 anchor.update();
  227.             }
  228.             
  229.             // カメラ映像更新
  230.             imageBitmapData.draw(video);
  231.             
  232.             // イメージの表示
  233.             // vertics の更新
  234.             trianglePath.vertices = segmentation.getVerticies(anchorVector);
  235.             // 描画
  236.             imageContainer.graphics.clear();
  237.             imageContainer.graphics.drawGraphicsData(imageGraphicsData);
  238.             
  239.             // ジョイントの表示
  240.             if (jointVisible) {
  241.                 // data の更新
  242.                 jointPath.data = segmentation.getPathData(anchorVector, anchorPairVector);
  243.                 // 描画
  244.                 jointContainer.graphics.clear();
  245.                 jointContainer.graphics.drawGraphicsData(jointGraphicsData);
  246.             }
  247.         }
  248.     }
  249. }
  250. import flash.display.GraphicsPathCommand;
  251. class Segmentation {
  252.     private var segW:uint;        // セグメント数(幅)
  253.     private var segH:uint;        // セグメント数(高)
  254.     private var numOfVertex:uint;    // 頂点数
  255.     private var pairVector:Vector.<int>;
  256.     
  257.     // コンストラクタ
  258.     public function Segmentation(segW:uint, segH:uint) {
  259.         this.segW = segW;
  260.         this.segH = segH;
  261.         numOfVertex = (segW + 1) * (segH + 1);
  262.     }
  263.     
  264.     // ---- drawTriangle 用 -----
  265.     // verticies の生成(updata のたびに呼ばれる)
  266.     public function getVerticies(anchorVector:Vector.<Anchor>):Vector.<Number> {
  267.         var n:uint = numOfVertex;
  268.         var verticies:Vector.<Number> = new Vector.<Number>(n * 2);
  269.         for (var i:int = 0; i < n; i++) {
  270.             verticies[i * 2]     = anchorVector[i].x;
  271.             verticies[i * 2 + 1] = anchorVector[i].y;
  272.         }
  273.         return verticies;
  274.     }
  275.     // indicies の生成(最初に一度だけ呼ばれる)
  276.     public function getIndicies():Vector.<int> {
  277.         var sW:uint = segW;
  278.         var sH:uint = segH;
  279.         var indicies:Vector.<int> = new Vector.<int>(sW * sH * 6);
  280.         var cnt:uint = 0;
  281.         for (var i:uint = 0; i < sH; i++) {
  282.             for (var j:uint = 0; j < sW; j++) {
  283.                 var leftTop:uint  = i * (sW + 1) + j;
  284.                 var rightTop:uint = i * (sW + 1) + j + 1;
  285.                 var leftBottom:uint  = (i + 1) * (sW + 1) + j;
  286.                 var rightBottom:uint = (i + 1) * (sW + 1) + j + 1;
  287.                 indicies[cnt]     = leftTop;
  288.                 indicies[cnt + 1] = rightTop;
  289.                 indicies[cnt + 2] = leftBottom;
  290.                 indicies[cnt + 3] = rightTop;
  291.                 indicies[cnt + 4] = rightBottom;
  292.                 indicies[cnt + 5] = leftBottom;
  293.                 cnt += 6;
  294.             }
  295.         }
  296.         return indicies;
  297.     }
  298.     // uvDatas の生成(最初に一度だけ呼ばれる)
  299.     public function getUvDatas():Vector.<Number> {
  300.         var sW:uint = segW;
  301.         var sH:uint = segH;
  302.         var uvDatas:Vector.<Number> = new Vector.<Number>(numOfVertex * 2);
  303.         var cnt:uint = 0;
  304.         for (var i:uint = 0; i < sH + 1; i++) {
  305.             for (var j:uint = 0; j < sW + 1; j++) {
  306.                 uvDatas[cnt++] = j / sW;
  307.                 uvDatas[cnt++] = i / sH;
  308.             }
  309.         }
  310.         return uvDatas;
  311.     }
  312.     
  313.     // ----- ジョイント用 -----
  314.     // パスの commands の生成(最初に一度だけ呼ばれる)
  315.     public function getPathCommands(pair:Vector.<int>):Vector.<int> {
  316.         var n:uint = pair.length;
  317.         var commands:Vector.<int> = new Vector.<int>(n);
  318.         n /= 2;
  319.         for (var i:uint = 0; i < n; i++) {
  320.             commands[i * 2]     = GraphicsPathCommand.MOVE_TO;
  321.             commands[i * 2 + 1] = GraphicsPathCommand.LINE_TO;
  322.         }
  323.         return commands;
  324.     }
  325.     // パスの data の生成(updata のたびに呼ばれる)
  326.     public function getPathData(anchors:Vector.<Anchor>, pair:Vector.<int>):Vector.<Number> {
  327.         var n:uint = pair.length;
  328.         var data:Vector.<Number> = new Vector.<Number>(n * 2);
  329.         for (var i:uint = 0; i < n; i++) {
  330.             var anchor:Anchor = anchors[pair[i]];
  331.             data[i * 2]     = anchor.x;
  332.             data[i * 2 + 1] = anchor.y;
  333.         }
  334.         return data;
  335.     }
  336.     
  337.     // ----- 頂点のペアリング -----
  338.     public function getVertexPair():Vector.<int> {
  339.         var sW:uint = segW;
  340.         var sH:uint = segH;
  341.         pairVector = new Vector.<int>();
  342.         // 横
  343.         for (var i:uint = 0; i < sH + 1; i++) {
  344.             for (var j:uint = 0; j < sW; j++) {
  345.                 var a:uint = i * (sW + 1) + j;
  346.                 var b:uint = i * (sW + 1) + j + 1;
  347.                 pairVector.push(a, b);
  348.             }
  349.         }
  350.         // 縦
  351.         for (i = 0; i < sH; i++) {
  352.             for (j = 0; j < sW+1; j++) {
  353.                 a =  i      * (sW + 1) + j;
  354.                 b = (i + 1) * (sW + 1) + j;
  355.                 pairVector.push(a, b);
  356.             }
  357.         }
  358.         
  359.         // 斜め(左上から右下)
  360.         for (i = 0; i < sH; i++) {
  361.             for (j = 0; j < sW; j++) {
  362.                 a = i * (sW + 1) + j;
  363.                 b = (i + 1) * (sW + 1) + j + 1;
  364.                 pairVector.push(a, b);
  365.             }
  366.         }
  367.         // 斜め(右上から左下)
  368.         for (i = 0; i < sH; i++) {
  369.             for (j = 0; j < sW; j++) {
  370.                 a =  i      * (sW + 1) + j + 1;
  371.                 b = (i + 1) * (sW + 1) + j;
  372.                 pairVector.push(a, b);
  373.             }
  374.         }
  375.         
  376.         if (sW % 2 == 0) {
  377.             // 横斜め(左上から右下)
  378.             for (i = 0; i < sH; i++) {
  379.                 for (j = 0; j < sW - 1; j += 2) {
  380.                     a = i * (sW + 1) + j;
  381.                     b = (i + 1) * (sW + 1) + j + 2;
  382.                     pairVector.push(a, b);
  383.                 }
  384.             }
  385.             // 横斜め(右上から左下)
  386.             for (i = 0; i < sH; i++) {
  387.                 for (j = 0; j < sW; j+=2) {
  388.                     a =  i      * (sW + 1) + j + 2;
  389.                     b = (i + 1) * (sW + 1) + j;
  390.                     pairVector.push(a, b);
  391.                 }
  392.             }
  393.         }
  394.         if (sH % 2 == 0) {
  395.             // 縦斜め(左上から右下)
  396.             for (i = 0; i < sH; i += 2) {
  397.                 for (j = 0; j < sW; j++) {
  398.                     a = i * (sW + 1) + j;
  399.                     b = (i + 2) * (sW + 1) + j + 1;
  400.                     pairVector.push(a, b);
  401.                 }
  402.             }
  403.             // 縦斜め(右上から左下)
  404.             for (i = 0; i < sH; i+=2) {
  405.                 for (j = 0; j < sW; j++) {
  406.                     a =  i      * (sW + 1) + j + 1;
  407.                     b = (i + 2) * (sW + 1) + j;
  408.                     pairVector.push(a, b);
  409.                 }
  410.             }
  411.         }
  412.         return pairVector;
  413.     }
  414. }
  415. import flash.display.Sprite;
  416. class Anchor extends Sprite {
  417.     // 物理的数値
  418.     static public var gravity:Number  = 0.47;    // 重力
  419.     static public var friction:Number = 0.92;    // 空気抵抗
  420.     static public var floorFriction:Number = 1;    // 床面抵抗
  421.     static public var bounce:Number = 1;        // 跳ね返り
  422.     // 壁面値
  423.     static public var left:Number;
  424.     static public var right:Number;
  425.     static public var top:Number;
  426.     static public var bottom:Number;
  427.     
  428.     // 固定フラグ
  429.     private var _isFix:Boolean = false;
  430.     public function set isFix(value:Boolean):void {
  431.         this.isVisible = _isFix = value;
  432.         circleDraw(true);
  433.     }
  434.     
  435.     private var _isVisible:Boolean = false;
  436.     public function set isVisible(value:Boolean):void {
  437.         if(!_isFix){
  438.             _isVisible = value;
  439.             circleDraw(_isVisible);
  440.         }
  441.     }
  442.     
  443.     // 計算用変数
  444.     // 速度
  445.     private var vx:Number = 0;
  446.     private var vy:Number = 0;
  447.     // 前フレームの座標値
  448.     private var prevX:Number = 0;
  449.     private var prevY:Number = 0;
  450.     // 剛性反映用の値
  451.     private var sx:Number = 0;
  452.     private var sy:Number = 0;
  453.     // ドラッグ判定
  454.     private var isMouseDown:Boolean = false;
  455.     
  456.     private var radius:Number;
  457.     private var color:uint;
  458.     
  459.     private const LIMIT:Number = 10.0;
  460.     public function Anchor(radius:Number = 10.0, color:uint = 0x0000FF):void {
  461.         this.radius = radius;
  462.         this.color  = color;
  463.         circleDraw(_isVisible);
  464.         buttonMode = true;
  465.     }
  466.     
  467.     // 円描画
  468.     private function circleDraw(flg:Boolean):void {
  469.         var a:Number = flg ? 0.25 : 0.0;
  470.         graphics.clear();
  471.         graphics.beginFill(color, a);
  472.         graphics.drawCircle(00, radius);
  473.         graphics.endFill();
  474.     }
  475.     // このアンカーがマウスドラッグ中か否か
  476.     public function mouseDown(flg:Boolean):void {
  477.         isMouseDown = flg;
  478.         (isMouseDown) ? startDrag() : stopDrag();
  479.     }
  480.     // アクセル
  481.     public function accelalete(valX:Number, valY:Number):void {
  482.         vx = valX;
  483.         vy = valY;
  484.     }
  485.     // ジョイントの剛性値を反映
  486.     public function setStiffness(valX:Number, valY:Number):void {
  487.         sx += valX;
  488.         sy += valY;
  489.     }
  490.     public function update():void {
  491.         if (isMouseDown) {    // ドラッグしている場合
  492.             // 壁処理
  493.             if (x < left) { x = left; }        // 左側面
  494.             if (x > right) { x = right; }    // 右側面
  495.             if (y < top) { y = top; }        // 天井
  496.             if (y > bottom) { y = bottom; }    // 床
  497.             // 計算
  498.             var tmpX:Number = x;
  499.             var tmpY:Number = y;
  500.             vx = x - prevX;
  501.             vy = y - prevY;
  502.             prevX = tmpX;
  503.             prevY = tmpY;
  504.         } else {            // ドラッグしていない場合
  505.             if(!_isFix){
  506.                 // 壁処理
  507.                 if (x < left) {
  508.                     x = left;
  509.                     vx *= floorFriction;
  510.                     vx *= bounce;
  511.                 } else if (x > right) {
  512.                     x = right;
  513.                     vx *= floorFriction;
  514.                     vx *= bounce;
  515.                 }
  516.                 if (y < top) {
  517.                     y = top;
  518.                     vy *= floorFriction;
  519.                     vy *= bounce;
  520.                 } else if (y > bottom) {
  521.                     y = bottom;
  522.                     vy *= floorFriction;
  523.                     vy *= bounce;
  524.                 }
  525.                 // 計算
  526.                 vx = Math.max( -LIMIT, Math.min(LIMIT, vx));
  527.                 vy = Math.max( -LIMIT, Math.min(LIMIT, vy));
  528.                 vx += sx;
  529.                 vy += sy;
  530.                 vx *= friction;
  531.                 vy *= friction;
  532.                 vy += gravity;
  533.                 x += vx;
  534.                 y += vy;
  535.             }
  536.             // 剛性値の初期化
  537.             sx = 0;
  538.             sy = 0;
  539.         }
  540.     }
  541. }
  542. class Joint {
  543.     // 物理的数値
  544.     static public var stiffness:Number = 0.025;// 剛性値
  545.     // 両端のアンカー
  546.     private var a:Anchor;    // 片端のアンカー
  547.     private var b:Anchor;    // もう片端のアンカー
  548.     // アンカー間の値
  549.     private var defaultDistance:Number = 0;    // アンカー間の距離(既定値)
  550.     private var distanceXY:Number;            // アンカー間の距離(実際の値)
  551.     private var distanceX:Number;    // distanceXY を求めるための X座標値
  552.     private var distanceY:Number;    // distanceXY を求めるための Y座標値
  553.     public function Joint(a:Anchor, b:Anchor):void {
  554.         this.a = a;
  555.         this.b = b;
  556.         getAnchorData();
  557.         defaultDistance = distanceXY;
  558.     }
  559.     // ジョイントの剛性計算をおこない、対象アンカーに反映させる
  560.     public function update():void {
  561.         getAnchorData();
  562.         var s:Number  = stiffness * (distanceXY - defaultDistance);
  563.         var sx:Number = s * distanceX / distanceXY;
  564.         var sy:Number = s * distanceY / distanceXY;
  565.         a.setStiffness(-sx, -sy);
  566.         b.setStiffness( sx,  sy);
  567.     }
  568.     // アンカー間の値を更新
  569.     private function getAnchorData():void {
  570.         var x:Number = a.x - b.x;
  571.         var y:Number = a.y - b.y;
  572.         distanceXY = Math.sqrt(x * x + y * y);
  573.         distanceX = x;
  574.         distanceY = y;
  575.     }
  576. }
flash swf thumbnail play
出題者からのコメント
これもまた、ウェブカムとdrawTrianglesメソッドを用いた優れたチャレンジでした。デザインに注力すれば、さらに良い作品になったと思います。
Adobe Flash Player シニアプロダクトマネージャー Justin Everett-Church
Comments from Sponsor
Another good challeng using WebCam and drawTriangle. If he/she tryed hard on design, it would be much better.
by Adobe, Flash Player sr-product manager Justin Everett-Church

Queenumhr

  1. /*
  2. **このAS3のコードはMITライセンスですが、
  3. **絵はGPLライセンスです。
  4. http://start.typepad.jp/typecast/
  5. アニメーションしない顔文字のgif
  6. http://mztm.heteml.jp/umhr/wonderfl/emoticons.gif
  7. 縦書き+ケータの絵文字。
  8. 絵文字の指定方法は絵文字名がsunの
  9. 場合は[m:sun]と書く。
  10. 文字コードで指定できるようにすれば、
  11. 普通にケータイメールビューアーが作れるかもね。
  12. なんかチェックメイトのお題が
  13. テキストエンジンになってたのでついでに応募。
  14. how to useの範囲内の使い方しかしてないので、
  15. 賑やかし要員の自覚ありですがw
  16. Adobeさん、さらなるテキスト周りの機能拡充を
  17. 期待してますよ!
  18. という願いを込めて。
  19. 参考
  20. Adobe Flash CS4 詳細!ActionScript 3.0入門ノート
  21. http://oshige.com/flash/as3note_cs4/
  22. http://help.adobe.com/ja_JP/AS3LCR/Flash_10.0/flash/text/engine/TextBlock.html
  23. http://help.adobe.com/ja_JP/AS3LCR/Flash_10.0/flash/text/engine/EastAsianJustifier.html
  24. http://level0.kayac.com/2008/12/textbox.php
  25. */
  26. package {
  27.     import flash.display.DisplayObject;
  28.     import flash.display.Sprite;
  29.     import flash.display.Bitmap;
  30.     import flash.display.BitmapData;
  31.     import flash.geom.Matrix;
  32.     import flash.text.engine.FontDescription;
  33.     import flash.text.engine.TextBlock;
  34.     import flash.text.engine.TextElement;
  35.     import flash.text.engine.TextLine;
  36.     import flash.text.engine.TextRotation;
  37.     import flash.text.engine.ElementFormat;
  38.     import flash.text.engine.EastAsianJustifier;
  39.     
  40.     import flash.text.engine.GraphicElement;
  41.     import flash.text.engine.GroupElement;
  42.     //import flash.text.engine.TextLine;
  43.     //import flash.text.engine.ElementFormat;
  44.     //import flash.text.engine.FontDescription;
  45.     import flash.text.engine.ContentElement;
  46.     
  47.     
  48.     import flash.text.TextField;
  49.     import flash.events.MouseEvent;
  50.     
  51.     [SWF(width = "465", height = "465", backgroundColor = 0xFFFFFF, frameRate = "30")]
  52.     public class Main3 extends Sprite {
  53.         
  54.         private var numFromName:Array = ["sun","cloud","rain","snow","thunder","typhoon","mist","sprinkle","aries","taurus","gemini","cancer","leo","virgo","libra","scorpius","sagittarius","capricornus","aquarius","pisces","sports","baseball","golf","tennis","soccer","ski","basketball","motorsports","train","pocketbell","subway","bullettrain","car","rvcar","bus","ship","airplane","house","building","postoffice","hospital","bank","atm","hotel","24hours","gasstation","parking","signaler","toilet","restaurant","cafe","bar","beer","fastfood","boutique","hairsalon","karaoke","movie","upwardright","carouselpony","music","art","drama","event","ticket","smoking","nosmoking","camera","bag","book","ribbon","present","birthday","telephone","mobilephone","memo","tv","game","cd","heart","spade","diamond","club","eye","ear","rock","scissors","paper","downwardright","upwardleft","foot","shoe","eyeglass","wheelchair","newmoon","moon1","moon2","moon3","fullmoon","dog","cat","yacht","xmas","downwardleft","phoneto","mailto","faxto","info01","info02","mail","by-d","d-point","yen","free","id","key","enter","clear","search","new","flag","freedial","sharp","mobaq","one","two","three","four","five","six","seven","eight","nine","zero","ok","heart01","heart02","heart03","heart04","smile","angry","despair","sad","wobbly","up","note","cute","spa","kissmark","shine","flair","annoy","punch","bomb","notes","down","sleepy","sign01","sign02","sign03","impact","sweat01","sweat02","dash","sign04","sign05","slate","pouch","pen","shadow","chair","night","soon","on","end","clock","appli01","appli02","t-shirt","moneybag","rouge","denim","snowboard","bell","door","dollar","pc","loveletter","wrench","pencil","crown","ring","sandclock","bicycle","japanesetea","watch","think","confident","coldsweats01","coldsweats02","pout","gawk","lovely","good","bleah","wink","happy02","bearing","catface","crying","weep","ng","clip","copyright","tm","run","secret","recycle","r-mark","danger","ban","empty","pass","full","leftright","updown","school","wave","fuji","clover","cherry","tulip","banana","apple","bud","maple","cherryblossom","riceball","cake","bottle","noodle","bread","snail","chick","penguin","fish","delicious","happy01","horse","pig","wine","shock"];
  55.         private var inputTF:TextField = new TextField();
  56.         private var commentBase:Sprite = new Sprite();
  57.         private var loadFiles_array:Array;
  58.         private var MultiLoader:MultiLoaderClass = new MultiLoaderClass("http://mztm.heteml.jp/crossdomain.xml");
  59.         private var emotionIcon:Object = {};
  60.         public function Main3():void {
  61.             //xmlの読み込み
  62.             loadFiles_array = MultiLoader.setLoad(["http://mztm.heteml.jp/umhr/wonderfl/emoticons.gif"],onComp);
  63.         }
  64.         private function onComp():void{
  65.             for (var i:int = 0; i < 250; i++) {
  66.                 var bd:BitmapData = new BitmapData(2020false);
  67.                 bd.draw(loadFiles_array[0],new Matrix(1,0,0,1,-20*(i%20),-20*(Math.floor(i*0.05))))
  68.                 emotionIcon["m"+i] = new Bitmap(bd);
  69.             }
  70.             
  71.             
  72.             
  73.             addChild(commentBase);
  74.             inputTF.x = 12;
  75.             inputTF.y = this.stage.stageHeight-24-110;
  76.             inputTF.width = this.stage.stageWidth - 24;
  77.             inputTF.height = 108;
  78.             inputTF.text = "ASオタク[m:pc][m:shadow][m:book]の諸君ハロー[m:sign01]\n[m:impact]むしむし蒸し暑い日[m:sun]が続いていますね[m:wobbly]。涼しい部屋[m:chair]でゲーム[m:tv][m:game]ばっかりしてないで、海[m:wave]へ山[m:fuji]へ外[m:shoe]で遊び[m:run]ましょう!\nそれと食事[m:restaurant]も忘れちゃいけない[m:sign02]暑い日にこそ熱い食べ物[m:noodle]で、たくさん汗[m:sweat01]をかいて[m:beer]たくさん笑って[m:smile]、ぐっすり[m:sleepy]眠れば、心も体も夏バテ知らず[m:up]\n心技体揃ってこそコレFlash[m:shine]クリエイター[m:happy01]なり。\nとか無理してたくさん絵文字を使ってみましたが、なんか電車内のレンタルパレットの広告みたいですよね。ヤングっぽいケータイ文章の勘所が全くわかりません。\n***\nこのAS3のコードはMITライセンスですが、絵はGPLライセンスです。ご注意ください。";
  79.             inputTF.border = true;
  80.             inputTF.type = "input";
  81.             inputTF.wordWrap = true;
  82.             addChild(inputTF);
  83.             var btnText:TextField = new TextField();
  84.             btnText.x = this.stage.stageWidth-90;
  85.             btnText.y = this.stage.stageHeight - 18;
  86.             btnText.width = 170;
  87.             btnText.height = 21;
  88.             btnText.text = "to TextBlock";
  89.             btnText.selectable = false;
  90.             addChild(btnText);
  91.             
  92.             var button:Sprite = new Sprite();
  93.             button.graphics.lineStyle (2, 0x999999, 1.0);
  94.             button.graphics.beginFill (0xCCCCCC, 0);
  95.             button.graphics.drawRoundRect (this.stage.stageWidth-110this.stage.stageHeight - 22 , 100 , 20 , 10 , 10);
  96.             button.buttonMode = true;
  97.             button.addEventListener(MouseEvent.CLICK,CLICK);
  98.             addChild(button);
  99.             
  100.             
  101.             CLICK();
  102.         }
  103.         private function CLICK(e:MouseEvent = null):void {
  104.             while (commentBase.numChildren) {
  105.                 commentBase.removeChildAt(0);
  106.             }
  107.             var fontDescription:FontDescription = new FontDescription("MS Mincho");
  108.             var format:ElementFormat = new ElementFormat();
  109.             format.fontSize = 15;
  110.             format.fontDescription = fontDescription;
  111.             
  112.             
  113.             var txt_array:Array = inputTF.text.split("\r");
  114.             var linePosition:Number = stage.stageWidth - 30;
  115.             
  116.             for (var i:int = 0; i < txt_array.length; i++) {
  117.                 setTB(groupElementFromText(txt_array[i]));
  118.             }
  119.             function setTB(groupElmt:GroupElement):void{
  120.                 var textBlock:TextBlock = new TextBlock(groupElmt,null,(new EastAsianJustifier()),TextRotation.ROTATE_90);
  121.                 var previousLine:TextLine = null;
  122.                 while (true) {
  123.                     var textLine:TextLine = textBlock.createTextLine(previousLine,300);
  124.                     if (textLine == null
  125.                         break;
  126.                     textLine.y = 16;
  127.                     textLine.x = linePosition;
  128.                     linePosition -= 24;
  129.                     commentBase.addChild(textLine);                
  130.                     previousLine = textLine;
  131.                 }
  132.             }
  133.         }
  134.         private function groupElementFromText(txt:String):GroupElement{
  135.             var i:int;
  136.             var format:ElementFormat = new ElementFormat((new FontDescription("MS Mincho")),15);
  137.             var format3:ElementFormat = new ElementFormat();
  138.             format3.baselineShift = (20-format.fontSize)/2;
  139.             
  140.             //[m:sun]の部分を取り出す。
  141.             var pattern:RegExp = /\[m:[a-zA-Z0-9]+\]/g;
  142.             var num_array:Array = txt.match(pattern);
  143.             var str_array:Array = txt.split(pattern);
  144.             var _length:int = Math.max(num_array.length , str_array.length);
  145.             var txt_array:Array = [];
  146.             //文章と絵文字を組み合わせる。
  147.             for (i = 0; i < _length; i++) {
  148.                 if(str_array[i]){
  149.                     txt_array.push(str_array[i])
  150.                 }
  151.                 if(num_array[i]){
  152.                     var num:int = numFromName.indexOf(num_array[i].slice(3,-1));
  153.                     txt_array.push(num)
  154.                 }
  155.             }
  156.             
  157.             //文章と絵文字を場合分けしてgroupVectorに入れる。
  158.             var groupVector:Vector.<ContentElement> = new Vector.<ContentElement>();
  159.             for (i = 0; i < txt_array.length; i++) {
  160.                 if(isNaN(txt_array[i])){
  161.                     var textElement:TextElement = new TextElement(txt_array[i], format); 
  162.                     groupVector.push(textElement);
  163.                 }else{
  164.                     var graphicElmt1:GraphicElement = new GraphicElement(newBitmap({draw:emotionIcon["m"+txt_array[i]]}) ,2424, format3);
  165.                     graphicElmt1.textRotation = TextRotation.ROTATE_270;
  166.                     groupVector.push(graphicElmt1);
  167.                 }
  168.             }
  169.             
  170.             var groupElmt:GroupElement = new GroupElement(groupVector);
  171.             return groupElmt;
  172.         }
  173.         private function newBitmap(... args):Bitmap {
  174.             var _length:int = args.length;
  175.             var bd:BitmapData;
  176.             var bitmap:Bitmap;
  177.             var strObj:Object = { width:100 , height:100, transparent:true, fillColor:0xFFFFFFFF };
  178.             var tempDO:DisplayObject;
  179.             for (var i:int = 0; i < _length; i++) {
  180.                 var _obj:Object = args[i];
  181.                 for (var _str:String in _obj) {
  182.                     if (_str == "draw") {
  183.                         tempDO = _obj[_str];
  184.                         strObj.width = _obj[_str].width;
  185.                         strObj.height = _obj[_str].height;
  186.                     }else {
  187.                         strObj[_str] = _obj[_str];
  188.                     }
  189.                 }
  190.             }
  191.             bd = new BitmapData(strObj.width, strObj.height, strObj.transparent, strObj.fillColor);
  192.             if (tempDO) {
  193.                 bd.draw(tempDO)
  194.             }
  195.             bitmap = new Bitmap(bd);
  196.             return bitmap;
  197.         }
  198.     }
  199. }
  200. class MultiLoaderClass{
  201.     import flash.system.Security;
  202.     import flash.net.URLRequest;
  203.     import flash.net.URLLoader;
  204.     import flash.events.Event;
  205.     import flash.events.IOErrorEvent;
  206.     import flash.display.Loader;
  207.     private var onComplete:Function = function():void{};
  208.     private var loadNum:int;
  209.     private var loadCompNum:int;
  210.     public function MultiLoaderClass(_str:String = null){
  211.         if(_str != null){
  212.             Security.loadPolicyFile(_str);
  213.         }
  214.     }
  215.     public function setLoad(__item_array:Array,_onComp:Function = null):Array{
  216.         loadCompNum = loadNum = 0;
  217.         onComplete = _onComp;
  218.         var _array:Array = new Array();
  219.         var _length:int = __item_array.length;
  220.         for (var i:int = 0; i < _length; i++) {
  221.             if(__item_array[i] == null){continue};
  222.             var _extension:String = __item_array[i].substr(-4,4).toLowerCase();//拡張子を取り出す。
  223.             if(_extension == ".xml"){
  224.                 loadNum ++;
  225.                 _array[i] = fnURLLoader(__item_array[i]);
  226.             }else if(_extension == ".jpg" || _extension == ".png" || _extension == ".gif"){
  227.                 loadNum ++;
  228.                 _array[i] = fnLoader(__item_array[i]);
  229.             }else{
  230.                 //_array[i] = null;
  231.             }
  232.         }
  233.         return _array;
  234.     }
  235.     private function fnURLLoader(__url:String):URLLoader{
  236.         var _loader : URLLoader = new URLLoader();
  237.         _loader.load(new URLRequest(__url));
  238.         _loader.addEventListener (Event.COMPLETE,completeHandler);
  239.         _loader.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);
  240.         return _loader;
  241.     }
  242.     private function fnLoader(__url:String):Loader{
  243.         var _loader:Loader = new Loader();
  244.         _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
  245.         _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
  246.         _loader.load(new URLRequest(__url));
  247.         //_loader.name = __url;
  248.         return _loader;
  249.     }
  250.     private function completeHandler(event:Event = null):void {
  251.         loadCompNum ++;
  252.         if(loadCompNum == loadNum){
  253.             onComplete();
  254.         }
  255.         //var loaderInfo:LoaderInfo=event.currentTarget as LoaderInfo;
  256.         //var loader:Loader=loaderInfo.loader;
  257.         //addChild(loader);
  258.     }
  259.     private function ioErrorHandler(event:IOErrorEvent):void {
  260.         //event.text = "Error #2035: URL が見つかりません。 URL: file:///~~~~~";
  261.         //event.text = "Error #2036: 読み込みが未完了です。 URL: http://~~~~~";
  262.         //から、URLのみを取り出す。
  263.         //trace(String(event.text).substr(String(event.text).indexOf(" URL: ")+6),"*****");
  264.         completeHandler();
  265.     }
  266. }
flash swf thumbnail play
出題者からのコメント
素晴らしいチャレンジです。スマートフォンがFlash Player10を採用すれば、この作品は実際にアプリとして利用可能でしょう。余談ですが「ASオタクの諸君ハロー」という書き出しがいいですね!
Adobe Flash Player シニアプロダクトマネージャー Justin Everett-Church
Comments from Sponsor
It is great challenge. Once smart phone implement Flash Player 10, this emoji challenge will be used in actual application. Besides, it is great it start with "Hello AS Geeks!!" I like that!
by Adobe, Flash Player sr-product manager Justin Everett-Church

ad