Checkmate

Massmedian

Win the Prize

クリスマスカラーをつかって、イルミネーションを演出してください。

Win the Prize

Produce illumination pattern with Christmas Colors.

Checkmateの遊び方
CHECKMATEは世界初のFlash詰め将棋イベントです。出題される問題にFORKする(プログラムを書き換える)ことで、回答します。
下記、スポンサーからの問題にForkボタンをクリックして、プログラムを改造してみましょう。さぁ、今こそあなたの知恵と技術を見せる時。LET's TRY CHECKMATE!
How to participate CHECKMATE
CHECKMATE is the world's first ever chess like quiz solving Flash contest. Solve questions by FORKing, meaning re-writing programs. Question statement given by sponsor is as follows. Click "Fork" button and revise programs. Now is the time to show what you've got. LET's TRY CHECKMATE!
Checkmate Challengers
Schedule
Fork acceptance period: 2009-10-07/24T00:00+9:00 | Judging period: 2009-10-24/30T00:00+9:00 | Result presentation: 2009-10-31T00:00+9:00
結果発表 Result presentation
massmedian2

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

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

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


ad

FORKED
  1. //セキュリティサンドボックス侵害で詰んだ
  2. //これが本当のチェックメイト!
  3. package {
  4.     import flash.display.*;
  5.     import flash.events.*;
  6.     import flash.net.*;
  7.     import flash.geom.*;
  8.     import flash.system.LoaderContext;
  9.     import flash.text.TextField;
  10.     import flash.text.TextFieldAutoSize;
  11.     import flash.text.TextFormat;
  12.     [SWF(backgroundColor=0x00,frameRate=60)]
  13.     public class FlashTest extends Sprite {
  14.         /*
  15.          * [Checkmate Vol4 by MASSMEDIAN]
  16.          * Please produce the illumination freely with a color palette. 
  17.          *
  18.          * usage of Palette class
  19.          *   A single value is used.
  20.          *     var white:uint = Palette.WHITE;
  21.          *     var green:uint = Palette.GREEN;
  22.          *     var red:uint = Palette.RED;
  23.          *     var gold:uint = Palette.GOLD;
  24.          *     var silver:uint = Palette.SILVER;
  25.          *     var black:uint = Palette.BLACK;
  26.          *   All the values are used.
  27.          *     var colors:Array = Palette.getColors();
  28.          */
  29.         private function init( e:Event = null ):void {
  30.             resize();
  31.             //drawXmasTree();
  32.             
  33.              new IconGetter(function(b:BitmapData):void {
  34.                  _image = b;
  35.                 createSnow();
  36.              },function(e:SecurityError):void {
  37.                  var tf:TextField = new TextField();
  38.                  tf.textColor = 0xFFFFFF;
  39.                 tf.autoSize = TextFieldAutoSize.LEFT;
  40.                 var f:TextFormat = new TextFormat();
  41.                 f.size = 20
  42.                 tf.defaultTextFormat = f;
  43.                 
  44.                 tf.text = e.toString().substring(010);
  45.                 addChild(tf);
  46.                  //var b:BitmapData = new BitmapData(tf.height, tf.width);
  47.                  //b.draw(tf);
  48.                  //_image = b;
  49.                  //createSnow();
  50.             });
  51.             //new TextField().tetC
  52.             //var tf:TextField = new TextField();
  53.             //tf.autoSize = TextFieldAutoSize.LEFT;
  54.             //tf.defaultTextFormat = new TextFormat(null, 20);
  55.             //tf.defaultTextFormat.size
  56.             //tf.text = e.toString();
  57.             
  58.             
  59.             //showPaletteMap();
  60.         }
  61.         private var _image:BitmapData;
  62.         
  63.         public var rect:Rectangle= new Rectangle();
  64.         public var center:Point = new Point();
  65.         
  66.         private const SLOW_LENGTH:int = 1000;
  67.         private var _snow:Vector.<Snow> = new Vector.<Snow>();
  68.         
  69.         private var _twincles:BitmapData;
  70.         private var _canvas:BitmapData;
  71.         
  72.         private var _matrix:Matrix;
  73.         private var _ctf:ColorTransform = new ColorTransform( 0.750.80.80.95 );
  74.         
  75.         private function createSnow():void {
  76.             // The value used for generation is prepared.
  77.             const RADIAN:Number = Math.PI*2;
  78.             const COLORS:Array = Palette.getColors();
  79.             
  80.             // The canvas to draw in illumination.
  81.             var snow:Snow, speed:Number, angle:Number;
  82.             for (var i:int = 0; i < _image.height; i++ )
  83.             {
  84.                 for (var j:int = 0; j < _image.width; j++ )
  85.                 {
  86.                     
  87.                 
  88.             //for ( var i :int = 0; i < SLOW_LENGTH; ++i ) {
  89.                 
  90.                 snow = new Snow();
  91.                 //snow.x   = (Math.random()-0.5)*50 + center.x;
  92.                 //snow.y   = Math.random()*rect.height;
  93.                 //snow.vx = (Math.random()-0.5) * 4;
  94.                 //snow.vy = Math.random()*-2;
  95.                 //snow.color = COLORS[int(COLORS.length*Math.random())];
  96.                 snow.x = i * 202 / _image.width +130;
  97.                 snow.y = j * 202 / _image.height+130;
  98.                 snow.color = _image.getPixel(i,j);
  99.                 _snow.push( snow );
  100.             //}
  101.                 }
  102.             }
  103.             
  104.             // The canvas to draw in illumination.
  105.             _canvas = new BitmapData( rect.height, rect.height, true0 );
  106.             var cbm :Bitmap = addChild( new Bitmap( _canvas ) ) as Bitmap;
  107.             cbm.smoothing = true;
  108.             
  109.             // The canvas to draw in twincles.
  110.             _twincles = new BitmapData( rect.width/4>>0, rect.height/4>>0true0 );
  111.             var tbm:Bitmap = addChild( new Bitmap( _twincles ) ) as Bitmap;
  112.             tbm.scaleX = tbm.scaleY = 4;
  113.             tbm.smoothing = true;
  114.             tbm.blendMode = BlendMode.ADD;
  115.             
  116.             // Matrix to draw by size of 1/4
  117.             _matrix = new Matrix(0.25000.25);
  118.             
  119.             addEventListener( Event.ENTER_FRAME, updateSnow );
  120.             
  121.         }
  122.         
  123.         private function updateSnow(e:Event):void {
  124.             _canvas.lock();
  125.             for eachvar snow:Snow in _snow ) {
  126.                 // The Brownian motion is added.
  127.                 snow.vx += (Math.random()-0.5)*0.01;
  128.                 snow.vy += (Math.random()-0.5)*0.01;
  129.                 
  130.                 // Gravity is added.
  131.                 //snow.vy += 0.015;
  132.                 
  133.                 // The wind drag is added.
  134.                 snow.vx *= 0.987;
  135.                 snow.vy *= 0.987;
  136.                 
  137.                 // The speed is added to the position. 
  138.                 snow.x += snow.vx;
  139.                 snow.y += snow.vy;
  140.                 
  141.                 // draw to canvas in position.
  142.                 _canvas.setPixel32( snow.x, snow.y, snow.color | 0xFF<<24 );
  143.                 
  144.                 // It resets it when going out of the area. 
  145.                 if( snow.x < rect.x -50 ||  snow.y < rect.y -50 || snow.x > rect.width +50 || snow.y > rect.height + 50 ) {
  146.                     snow.x = center.y + (Math.random() -0.5) * 10;
  147.                     snow.y = Math.random() *-30;
  148.                     snow.vx = (Math.random() -0.5) * 3;
  149.                     snow.vy = Math.random() *-3;
  150.                 }
  151.             }
  152.             // ColorTransform(effect that dose blackout) is made to adjust. 
  153.             _canvas.colorTransform( _canvas.rect, _ctf );
  154.             _canvas.unlock();
  155.             
  156.              // draw to canvas in twincles by using Matrix.
  157.             _twincles.draw( _canvas, _matrix );
  158.         }
  159.         
  160.         
  161.         private function resize( e:Event = null ):void {
  162.             rect.width = stage.stageWidth;
  163.             rect.height= stage.stageHeight;
  164.             
  165.             center.x = rect.width /2>>0;
  166.             center.y = rect.height /2>>0;
  167.         }
  168.         
  169.         private function drawXmasTree():void {
  170.             var loader :Loader = new Loader();
  171.             addChild( loader );
  172.             loader.load( new URLRequest("http://swf-dev.wonderfl.net/static/assets/checkmate04/tree.jpg"),new LoaderContext(true));
  173.         }
  174.         private function showPaletteMap():void {
  175.             var colors:Array = Palette.getColors();
  176.             var palette:Sprite = addChild( new ColorMap( colors ) ) as Sprite;
  177.             palette.x = ( rect.width - palette.width )  /2 >>0;
  178.             palette.y = ( rect.height- palette.height ) /2 >>0;
  179.         }
  180.         
  181.         public function FlashTest() {
  182.             if( stage ) init();
  183.             else addEventListener( Event.ADDED_TO_STAGE, init );
  184.         }
  185.     }
  186. }
  187. /* for Checkmate */
  188. class Palette {
  189.     public static const WHITE:uint = 0xF0F0F0;
  190.     public static const GREEN:uint = 0x008800;
  191.     public static const RED:uint = 0xCC0000;
  192.     public static const GOLD:uint = 0xFFCC66;
  193.     public static const SILVER:uint = 0xCCCCCC;
  194.     public static const BLACK:uint = 0x101010;
  195.     public static const COLORS:/*uint*/Array = [ WHITE, GREEN,  RED, GOLD, SILVER, BLACK ];
  196.     public static function getColors():Array { return COLORS.slice(); }
  197. }
  198. /* for Example. */
  199. class Snow {
  200.     public var x:Number = 0;
  201.     public var y:Number = 0;
  202.     public var vx:Number = 0;
  203.     public var vy:Number = 0;
  204.     public var color:uint = 0x00;
  205. }
  206. /* for debug. */
  207. import flash.display.*;
  208. class ColorMap extends Sprite {
  209.     public function ColorMap(colors:Array) {
  210.         var l:int = colors.length;
  211.         var rect:Sprite;
  212.         forvar i:int=0; i<l; ++i ) {
  213.             addChild( rect = new ColorRect( colors[ i ] ) );
  214.             rect.x =i * ColorRect.WIDTH;
  215.             rect.y =0;
  216.         }
  217.     }
  218. }
  219. /* for debug. */
  220. class ColorRect extends Sprite {
  221.     public static const WIDTH:int = 40;
  222.     public static const HEIGHT:int = 40;
  223.     public function ColorRect( color:uint ) {
  224.         super();
  225.         graphics.beginFill( color, 1 );
  226.         graphics.drawRect( 00, WIDTH, HEIGHT );
  227.         graphics.endFill();
  228.     }
  229. }
  230. //package 
  231. //{
  232.     import flash.display.Bitmap;
  233.     import flash.display.BitmapData;
  234.     import flash.display.Loader;
  235.     //import flash.display.Sprite;
  236.     //import flash.events.Event;
  237.     
  238.     //public
  239.     class IconGetter
  240.     {
  241.         private var l:Loader;
  242.         
  243.         private var _bmpf:Function//<BitmapData,void>
  244.         private var _errf:Function//<SecurityError,void>
  245.         public function IconGetter(bmpGetter:Function,errGetter:Function):void 
  246.         {
  247.             _bmpf = bmpGetter;
  248.             _errf = errGetter;
  249.             var icon:TwitterIcon = new TwitterIcon(onIconGet);
  250.             
  251.         }
  252.         private function onIconGet(xs:Array):void {
  253.             l = new Loader();
  254.             l.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
  255.             l.load(xs[int(xs.length*Math.random())])
  256.         }
  257.         private function onComplete(e:Event):void 
  258.         {
  259.             var bd:BitmapData = new BitmapData(l.width, l.height);
  260.             try{
  261.                 bd.draw(l);
  262.                 _bmpf(bd);
  263.             }catch (e:SecurityError) {
  264.                 _errf(e);
  265.             }
  266.             
  267.         }
  268.     }
  269. //}
  270. import flash.events.Event;
  271. import flash.net.URLLoader;
  272. import flash.net.URLRequest;
  273. //import flash.net.
  274. class TwitterIcon
  275. {
  276.     private var _xs:Array;
  277.     public function TwitterIcon(arraySetter:Function)
  278.     {
  279.         var loadTexts:Function = function (rpp:int, arraySetter:Function):void {
  280.             var textLoader:URLLoader = new URLLoader(new URLRequest("http://search.twitter.com/search.atom?q=%23illumination&rpp=" + rpp));
  281.             textLoader.addEventListener(Event.COMPLETE, function(e:Event):void {
  282.                 default xml namespace = new Namespace("http://www.w3.org/2005/Atom");
  283.                 var htmlText:XML = XML(textLoader.data);
  284.                 //var title:XMLList = htmlText.entry.title;
  285.                 var imgs:XMLList = htmlText.entry.link.(@type=="image/png").@href;
  286.                 var xs:Array = [];
  287.                 for each(var i:XML in  imgs)
  288.                 {
  289.                     xs.push(new URLRequest(i.toString()));
  290.                     //xs.push.apply(null,scan(c.toString(),/\[(.+)\]/));
  291.                 }
  292.                 if (xs.length >= 1)
  293.                 {
  294.                     //_texts = xs;
  295.                     arraySetter(xs);
  296.                 }
  297.             });
  298.         }
  299.         loadTexts(10,arraySetter);
  300.     }
  301. }
  302. /**
  303.  * @see http://takumakei.blogspot.com/2009/05/actionscriptrubystringscan.html
  304.  */ 
  305. //package com.blogspot.takumakei.utils
  306. //{
  307.     //public
  308.     function scan(str:String, re:RegExp):Array
  309.     {
  310.         if(!re.global){
  311.             var flags:String = 'g';
  312.             
  313.             if(re.dotall)
  314.                 flags += 's';
  315.             if(re.multiline)
  316.                 flags += 'm';
  317.             if(re.ignoreCase)
  318.                 flags += 'i';
  319.             if(re.extended)
  320.                 flags += 'x';
  321.             re = new RegExp(re.source, flags);                    
  322.         }
  323.         var r:Array = [];
  324.         var m:Array = re.exec(str);
  325.         while(null != m){
  326.             if(1 == m.length)
  327.                 r.push(m[0]);
  328.             else
  329.                 r.push(m.slice(1, m.length));
  330.             m = re.exec(str);
  331.         }
  332.         return r;
  333.     }
  334. //}
noswf
  1. // forked from checkmate's Checkmate vol4 Massmedian
  2. package
  3. {
  4.     import flash.display.Bitmap;
  5.     import flash.display.BitmapData;
  6.     import flash.display.BlendMode;
  7.     import flash.filters.BlurFilter;
  8.     import flash.display.PixelSnapping;
  9.     import flash.events.MouseEvent;
  10.     import flash.events.Event;
  11.     import flash.geom.Matrix;
  12.     import flash.geom.ColorTransform;
  13.     import flash.geom.Rectangle;
  14.     import flash.geom.Point;
  15.     import org.papervision3d.core.effects.utils.BitmapClearMode;
  16.     import org.papervision3d.core.geom.Pixels;
  17.     import org.papervision3d.view.BasicView;
  18.     import org.papervision3d.view.layer.BitmapEffectLayer;
  19.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]
  20.     public class Main extends BasicView{
  21.         private const RECT:Rectangle = new Rectangle(00465465);
  22.         private const ZEROS:Point = new Point(00);
  23.         private var _pixels:Pixels;
  24.         private var _canvas:BitmapData;
  25.         private var _head:Particle;
  26.         private var _blurFilter:BlurFilter;
  27.         private var _colorTransForm:ColorTransform;
  28.         private var _mode:Number;
  29.         
  30.         private var mtx:Matrix;
  31.         public function Main()
  32.         {
  33.             super(00truetrue);
  34.             var layer:BitmapEffectLayer=new BitmapEffectLayer(viewport, 465465true0, BitmapClearMode.CLEAR_PRE, true);
  35.             layer.clearBeforeRender=true;
  36.             viewport.containerSprite.addLayer(layer);
  37.             camera.z=-750;
  38.             camera.y=-100;
  39.             
  40.             _pixels=new Pixels(layer);
  41.             scene.addChild(_pixels);
  42.             
  43.             var p:Particle = _head = new Particle();
  44.             for (var i:uint = 0; i < 6800; ++i){
  45.                 p = p.next = new Particle();
  46.             }
  47.             
  48.             _canvas=new BitmapData(465 / 4465 / 4false, 0x000000);
  49.             var bmp:Bitmap=new Bitmap(_canvas, PixelSnapping.NEVER, true);
  50.             bmp.scaleX=bmp.scaleY=4;
  51.             bmp.smoothing=true;
  52.             bmp.blendMode=BlendMode.ADD;
  53.             addChild(bmp);
  54.             _blurFilter = new BlurFilter(111);
  55.             _colorTransForm = new ColorTransform(0.950.950.95);
  56.             mtx = new Matrix(0.25000.25);
  57.             startRendering();
  58.             addEventListener(Event.ENTER_FRAME, onFrame);
  59.             stage.addEventListener(MouseEvent.MOUSE_MOVE, _move);
  60.             _iniset();
  61.         }
  62.         
  63.         private function _iniset():void{
  64.             var p:Particle = _head;
  65.             var i:Number = 1;
  66.             var z:Number = 180;
  67.             do {
  68.                 p.angle = i + i * Math.random();
  69.                 p.radius = i / 11;
  70.                 if(p.radius > z && i < 4500){
  71.                   p.radius = p.radius  - 100 * Math.ceil(i/3300);
  72.                 }
  73.                 if(i >= 4500){
  74.                   p.radius = 60;
  75.                 }
  76.                 p.yy= -(i / 11);
  77.                 if(i >= 5800){
  78.                     p.yy= -(5800 / 11);
  79.                     p.radius = 320 * Math.random() + 80;
  80.                 }
  81.                 p.xx=(p.radius * Math.cos(p.angle * Math.PI / 180));
  82.                 p.zz=(p.radius * Math.sin(p.angle * Math.PI / 180));
  83.                 if(i >= 5800){
  84.                 p.setPixel3Dsnow();
  85.                 }else{
  86.                 p.setPixel3D();
  87.                 }
  88.                 _pixels.addPixel3D(p.pix3d);
  89.                 _pixels.y = 300;
  90.                 i ++;
  91.             } while (p = p.next);
  92.         }
  93.         private function _move(e:MouseEvent = null):void{
  94.             camera.z = -(mouseX) - 430;
  95.             camera.y = mouseY - 230;
  96.         }
  97.         private function onFrame(e:Event):void
  98.         {
  99.             _canvas.lock();
  100.             _canvas.fillRect(_canvas.rect, 0x000000);
  101.             _canvas.draw(viewport, mtx);
  102.             _canvas.applyFilter(_canvas, RECT, ZEROS, _blurFilter);
  103.             _canvas.colorTransform(RECT, _colorTransForm);
  104.             _canvas.draw(_canvas, nullnull, BlendMode.ADD);
  105.             _canvas.unlock();
  106.             _pixels.rotationY+=0.5;
  107.         }
  108.     }
  109. }
  110. internal class Particle {
  111.     import org.papervision3d.core.geom.renderables.Pixel3D;
  112.     public var radius:Number;
  113.     public var angle:Number;
  114.     public var xx:Number = 0;
  115.     public var yy:Number = 0;
  116.     public var zz:Number = 0;
  117.     public var pix3d:Pixel3D;
  118.     public var next:Particle;
  119.         public function setPixel3D():void
  120.         {
  121.             pix3d=new Pixel3D((0xee << 24 | 0xff * Math.random() << 16 | 0xff * Math.random() << 8 | 0x99 * Math.random() ), xx, yy, zz);
  122.         }
  123.         public function setPixel3Dsnow():void
  124.         {
  125.             pix3d=new Pixel3D((0xff * Math.random() << 24 | 0xff << 16 | 0xff << 8 | 0xff ), xx, yy, zz);
  126.         }
  127. }
noswf

Checkmate vol4 Massmedian Neon Tree [diff(410)]

  1. /**
  2.  * ステージクリックで明かりがついたり消えたりします。
  3.  * 
  4.  * 
  5.  * -参考-
  6.  * 
  7.  * キラキラPixel3D!
  8.  * http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c
  9.  */
  10. package
  11. {
  12.     import flash.display.BlendMode;
  13.     import flash.events.Event;
  14.     import flash.events.MouseEvent;
  15.     import flash.filters.BitmapFilterQuality;
  16.     import flash.filters.BlurFilter;
  17.     import flash.geom.ColorTransform;
  18.     import gs.TweenMax;
  19.     import net.hires.debug.Stats;
  20.     import org.papervision3d.core.effects.BitmapColorEffect;
  21.     import org.papervision3d.core.effects.BitmapLayerEffect;
  22.     import org.papervision3d.core.effects.utils.BitmapClearMode;
  23.     import org.papervision3d.core.effects.utils.BitmapDrawCommand;
  24.     import org.papervision3d.core.geom.Pixels;
  25.     import org.papervision3d.core.geom.renderables.Pixel3D;
  26.     import org.papervision3d.lights.PointLight3D;
  27.     import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
  28.     import org.papervision3d.objects.DisplayObject3D;
  29.     import org.papervision3d.objects.primitives.Sphere;
  30.     import org.papervision3d.view.BasicView;
  31.     import org.papervision3d.view.layer.BitmapEffectLayer;
  32.     [SWF(backgroundColor = 0x000000, width = "465", height = "465", frameRate = 60)]
  33.     public class Main extends BasicView
  34.     {
  35.         private const STAR_COLOR:uint = 0xFFC460
  36.         private const STAR_RADIUS:uint = 50;
  37.         private const LEAF_COLOR:uint = 0x274905;
  38.         private const LEAF_RADIUS:uint = 300;
  39.         private const LEAF_HEIGHT:Number = 700;
  40.         private const TRUNK_COLOR:uint = 0x822e01;
  41.         private const TRUNK_RADIUS:uint = 50;
  42.         private const TRUNK_HEIGHT:Number = 120;
  43.         private const PLANT_COLOR:uint = 0x4f1700;
  44.         private const PLANT_RADIUS:uint = 90;
  45.         private const PLANT_HEIGHT:Number = 40;
  46.         private const SPHERE_COUNT:uint = 30;
  47.         private const SPHERE_COLOR_LIST:Array = [0xFC0A0A, 0xFC0A0A, 0x3E33FF,0x666666];
  48.         private const LACE_COUNT:uint = 1000;
  49.         private const LACE_COLOR:uint = 0xCCFFF4AA;
  50.         private const SNOW_COUNT:uint = 500;
  51.         private const SNOW_COLOR:uint = 0x99FFFFFF;
  52.         private const SNOW_AREA_R:Number = 500;
  53.         private var _sphereList:Vector.<Sphere>=new Vector.<Sphere>();
  54.         private var _my:Number = 0;
  55.         private var _isLight:Boolean = false;
  56.         private var _root:DisplayObject3D, _tree:Tree, _bfx:BitmapEffectLayer, _snow:Snow;
  57.         public function Main():void
  58.         {
  59.             super(465465false);
  60.             Wonderfl.capture_delay(15);
  61.             if (!stage)
  62.                 addEventListener(Event.ADDED_TO_STAGE, _init);
  63.             else
  64.                 _init();
  65.         }
  66.         private function _init(e:Event = null):void
  67.         {
  68.             removeEventListener(Event.ADDED_TO_STAGE, _init);
  69.             _root = scene.addChild(new DisplayObject3D());
  70.             var light:PointLight3D = new PointLight3D(false);
  71.             light.z = -1000;
  72.             light.x = -1000;
  73.             light.y = 1000;
  74.             var objList:Array = [];
  75.             _tree = new Tree(STAR_COLOR, STAR_RADIUS, LEAF_COLOR, LEAF_RADIUS, LEAF_HEIGHT, TRUNK_COLOR, TRUNK_RADIUS, TRUNK_HEIGHT, PLANT_COLOR, PLANT_RADIUS, PLANT_HEIGHT);
  76.             _root.addChild(_tree);
  77.             objList.push(_tree)
  78.             _tree.y = -400;
  79.             var sphBaseRad:Number =  (2 * Math.PI) / SPHERE_COUNT;
  80.             for (var i:int = 0; i < SPHERE_COUNT; i++)
  81.             {
  82.                 var sphMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0x666666, SPHERE_COLOR_LIST[Math.floor((SPHERE_COLOR_LIST.length - 0.01) * Math.random())]);
  83.                 objList.push(_createSphere(sphMaterial, sphBaseRad * i));
  84.             }
  85.             _createBitmapEffectLayer(objList);
  86.             var pixels:Pixels  = new Pixels(_bfx);
  87.             _root.addChild(pixels);
  88.             _createLacePixels(pixels, LACE_COUNT);
  89.             //addChild(new Stats());
  90.             _start();
  91.             graphics.beginFill(0);
  92.             graphics.drawRect(00465465);
  93.             graphics.endFill();
  94.         }
  95.         private function _start():void
  96.         {
  97.             _tree.start(0.30.045);
  98.             _sphereStart(2.60.075);
  99.             TweenMax.delayedCall(5.60, _openingComplete);
  100.             _snow = new Snow(SNOW_COUNT, SNOW_COLOR, SNOW_AREA_R);
  101.             addChildAt(_snow, 1);
  102.             startRendering();
  103.         }
  104.         private function _openingComplete():void
  105.         {
  106.             stage.addEventListener(MouseEvent.CLICK, _onClickHandler);
  107.             _onClickHandler();
  108.         }
  109.         private function _createBitmapEffectLayer(list:Array):void
  110.         {
  111.             _bfx = new BitmapEffectLayer(viewport, 465465true, 0x00FFFFFF, BitmapClearMode.CLEAR_PRE, falsefalse);
  112.             _bfx.addEffect(new BitmapColorEffect(1.01.01.00.9));
  113.             _bfx.addEffect(new BitmapLayerEffect(new BlurFilter(1010, BitmapFilterQuality.LOW), false));
  114.             _bfx.drawCommand = new BitmapDrawCommand(nullnew ColorTransform(1.01.01.01.0, -32, -16, -32, -16), BlendMode.ADD);
  115.             for (var i:int = 0; i < list.length; i++)
  116.             {
  117.                 _bfx.addDisplayObject3D(list[i]);
  118.             }
  119.         }
  120.         private function _createSphere(mat:FlatShadeMaterial, rad:Number = 0):Sphere
  121.         {
  122.             var result:Sphere = new Sphere(mat, 1534);
  123.             var pt:Pt = _treeOutLinePt(rad, 22080);
  124.             result.x = pt.x;
  125.             result.y = pt.y;
  126.             result.z = pt.z;
  127.             result.rotationY = 360 * Math.random();
  128.             _sphereList.push(result);
  129.             return result;
  130.         }
  131.         private function _createLacePixels(pixels:Pixels, num:uint):void
  132.         {
  133.             for (var i:int = 0; i < num; ++i) 
  134.             {
  135.                 var pt:Pt = _treeOutLinePt(Math.PI * 2 * Math.random(), 8050 * Math.sin(Math.PI * 0.5 * Math.random())-20);
  136.                 var px:Pixel3D = new Pixel3D(LACE_COLOR, pt.x, pt.y, pt.z);
  137.                 pixels.addPixel3D(px);
  138.             }
  139.         }
  140.         private function _treeOutLinePt(rad:Number, top:Number = 0, bottom:Number = 0):Pt
  141.         {
  142.             var result:Pt = new Pt();
  143.             var posY:Number = (LEAF_HEIGHT - top) * ( _tree.getOutLine(Math.random() * LEAF_HEIGHT) / LEAF_RADIUS) + bottom;
  144.             var r:Number = _tree.getOutLine(posY);
  145.             result.x = r * Math.cos(rad);
  146.             result.y = posY + _tree.leafBaseY + _tree.y;
  147.             result.z = r * Math.sin(rad);
  148.             return result;
  149.         }
  150.         private function _sphereStart(delayTime:Number = 0, speed:Number = 0.04):void
  151.         {
  152.             for (var i:int = 0; i < _sphereList.length; i++) 
  153.             {
  154.                 TweenMax.delayedCall(i * speed + delayTime, _addChildSphere, [_sphereList[i]]);
  155.             }
  156.             _sphereList = null;
  157.         }
  158.         private function _addChildSphere(sphere:Sphere):void
  159.         {
  160.             _root.addChild(sphere);
  161.         }
  162.         override protected function onRenderTick(event:Event = null):void
  163.         {
  164.             super.onRenderTick(event);
  165.             _root.rotationY -= (stage.mouseX - stage.stageWidth * 0.5) * 0.008;
  166.             _my += ((stage.mouseY - stage.stageHeight * 0.5) * 2.0 - _my) * 0.08;
  167.             camera.y = _my;
  168.             camera.zoom = 40 - _my * 0.025
  169.             _snow.update(_root.rotationY,camera.y,camera.zoom);
  170.         }
  171.         private function _onClickHandler(e:MouseEvent = null):void
  172.         {
  173.             _isLight = !_isLight;
  174.             if (_isLight)
  175.             {    
  176.                 viewport.containerSprite.addLayer(_bfx);
  177.                 _snow.show();
  178.             }else
  179.             {    
  180.                 viewport.containerSprite.removeLayer(_bfx);
  181.                 _snow.hide();
  182.             }
  183.         }
  184.     }
  185. }
  186. import flash.display.Bitmap;
  187. import flash.display.BitmapData;
  188. import flash.display.BlendMode;
  189. import flash.display.PixelSnapping;
  190. import flash.geom.Matrix;
  191. import gs.TweenMax;
  192. import org.papervision3d.core.effects.utils.BitmapClearMode;
  193. import org.papervision3d.core.geom.Lines3D;
  194. import org.papervision3d.core.geom.Pixels;
  195. import org.papervision3d.core.geom.renderables.Line3D;
  196. import org.papervision3d.core.geom.renderables.Vertex3D;
  197. import org.papervision3d.core.geom.renderables.Pixel3D;
  198. import org.papervision3d.core.proto.CameraObject3D;
  199. import org.papervision3d.materials.special.LineMaterial;
  200. import org.papervision3d.objects.DisplayObject3D;
  201. import org.papervision3d.view.BasicView;
  202. import org.papervision3d.view.layer.BitmapEffectLayer;
  203. class Tree extends Lines3D
  204. {        
  205.     private const LINE_SIZE:uint = 3;
  206.     private const MARGIN:Number = 5;
  207.     private var _rad:Number = 0;
  208.     private var _h:Number = 0;
  209.     private var _list:Vector.<Line3D>=new Vector.<Line3D>();
  210.     private var _v3d:Vertex3D, _interval_rad:Number, _starMaterial:LineMaterial, _starRadius:Number, _leafMaterial:LineMaterial, _leafRadius:Number, _leafHeight:Number, _leafBaseY:Number, _trunkMaterial:LineMaterial, _trunkRadius:Number, _plantMaterial:LineMaterial, _plantRadius:Number;
  211.     public function Tree(starColor:uint, starRadius:Number, leafColor:uint, leafRadius:Number, leafHeight:Number, trunkColor:uint, trunkRadius:Number, trunkHeight:Number, plantColor:uint, plantRadius:Number, plantHeight:Number)
  212.     {
  213.         _init(starColor, starRadius, leafColor, leafRadius, leafHeight, trunkColor, trunkRadius, trunkHeight, plantColor, plantRadius, plantHeight);
  214.     }
  215.     private function _init(starColor:uint, starRadius:Number, leafColor:uint, leafRadius:Number, leafHeight:Number, trunkColor:uint, trunkRadius:Number, trunkHeight:Number, plantColor:uint, plantRadius:Number, plantHeight:Number):void
  216.     {
  217.         _v3d = new Vertex3D(_trunkRadius * Math.cos(_rad), _trunkRadius * Math.sin(_rad), _h);
  218.         _interval_rad = 110 / 180 * Math.PI;
  219.         _starMaterial = new LineMaterial(starColor, 1);
  220.         _starRadius = starRadius;
  221.         _leafMaterial = new LineMaterial(leafColor, 1);
  222.         _leafRadius = leafRadius;
  223.         _trunkMaterial = new LineMaterial(trunkColor, 1);
  224.         _trunkRadius = trunkRadius;
  225.         _plantMaterial = new LineMaterial(plantColor, 1);
  226.         _plantRadius = plantRadius;
  227.         _createPlant(plantHeight);
  228.         _createTrunk(trunkHeight);
  229.         _createLeaf(leafHeight);
  230.         _createStar();
  231.     }
  232.     private function _createTrunk(height:Number):void
  233.     {
  234.         var margin:Number = MARGIN * 1.2;
  235.         var num:uint = Math.floor(height / margin);
  236.         for (var i:int = 0; i < num; i++)
  237.         {
  238.             _h += margin;
  239.             var newV3d:Vertex3D = _createV3d(_trunkRadius, _h);
  240.             var line:Line3D = new Line3D(this, _trunkMaterial, LINE_SIZE, _v3d, newV3d);
  241.             _list.push(line);
  242.             _v3d = newV3d;
  243.         }
  244.         _h -= MARGIN * 2
  245.     }
  246.     private function _createLeaf(height:Number):void
  247.     {
  248.         var margin:Number=MARGIN*2.0
  249.         var num:uint = Math.floor(height / margin);
  250.         _leafBaseY = _h;
  251.         for (var i:int = 0; i < num; i++)
  252.         {
  253.             _h += margin;
  254.             var newV3d:Vertex3D = _createV3d(_leafCurve(i,num), _h);
  255.             var line:Line3D = new Line3D(this, _leafMaterial, LINE_SIZE, _v3d, newV3d);
  256.             _list.push(line);
  257.             _v3d = newV3d;
  258.         }
  259.         _leafHeight = _h - _leafBaseY;
  260.         _h -= MARGIN*5
  261.     }
  262.     private function _createStar():void
  263.     {
  264.         _createStarV3d(0, _h);
  265.         _createStarV3d(3, _h);
  266.         _createStarV3d(1, _h);
  267.         _createStarV3d(4, _h);
  268.         _createStarV3d(2, _h);
  269.         _createStarV3d(0, _h);
  270.     }
  271.     private function _createPlant(height:Number):void
  272.     {
  273.         var margin:Number = MARGIN;
  274.         var num:uint = uint(height / margin);
  275.         var r:Number = _plantRadius;
  276.         for (var i:int = 0; i < num; i+=4)
  277.         {
  278.             for (var j:int = 0; j < 4; j++)
  279.             {    
  280.                 _createPlantV3d(j, _h, r);
  281.                 _h += margin
  282.             }
  283.             r += 2;
  284.         }
  285.         r *= 1.1;
  286.         for (var k:int = 0; k < 4; k++)
  287.         {    
  288.             _createPlantV3d(k, _h, r);
  289.             _h += margin
  290.         }
  291.         _createPlantV3d(0, _h, 0);
  292.         _h -= MARGIN*4
  293.     }
  294.     private function _createV3d(r:Number, h:Number):Vertex3D
  295.     {
  296.         _rad += _interval_rad;
  297.         return new Vertex3D(r * Math.cos(_rad), h, r * Math.sin(_rad));
  298.     }
  299.     private function _leafCurve(i:Number,max:Number):Number
  300.     {
  301.         var a:Number = 0.06;
  302.         var b:Number=0.1
  303.         return _leafRadius * (1-Math.sin(i / max * Math.PI*0.5))
  304.     }
  305.     private function _createStarV3d(i:uint, baseY:Number):void
  306.     {
  307.         var baseRad:Number = 72 / 180 * Math.PI;
  308.         var newV3d:Vertex3D = new Vertex3D(_starRadius * Math.cos(baseRad * i), _starRadius * Math.sin(baseRad * i)+baseY, 0);
  309.         var line:Line3D = new Line3D(this, _starMaterial, LINE_SIZE, _v3d, newV3d);
  310.         _list.push(line);
  311.         _v3d = newV3d;
  312.     }
  313.     private function _createPlantV3d(i:uint, h:Number, r:Number):void
  314.     {
  315.         var baseRad:Number = Math.PI *0.5;
  316.         var newV3d:Vertex3D = new Vertex3D(r * Math.cos(baseRad * i), h, r * Math.sin(baseRad * i));
  317.         var line:Line3D = new Line3D(this, _plantMaterial, LINE_SIZE, _v3d, newV3d);
  318.         _list.push(line);
  319.         _v3d = newV3d;
  320.     }
  321.     public function getOutLine(y:Number):Number
  322.     {
  323.         return _leafCurve(y, _leafHeight);
  324.     }
  325.     public function start(delayTime:Number=0, speed:Number=0.04):void
  326.     {
  327.         for (var i:int = 0; i < _list.length; i++) 
  328.         {
  329.             TweenMax.delayedCall(i * speed + delayTime, _addLine, [_list[i]]);
  330.         }
  331.         _list = null;
  332.     }
  333.     private function _addLine(line3D:Line3D):void
  334.     {
  335.         addLine(line3D)
  336.     }
  337.     public function get leafHeight():Number { return _leafHeight };
  338.     public function get leafBaseY():Number { return _leafBaseY };
  339. }
  340. class Snow extends BasicView
  341. {
  342.     private var _list:Vector.<Pixel3D>=new Vector.<Pixel3D>();
  343.     private var _root:DisplayObject3D, _bmp:Bitmap, _mtx:Matrix;
  344.     public function Snow(count:uint, color:uint, areaR:Number)
  345.     {
  346.         super(465465false);
  347.         _init(count, color, areaR);
  348.     }
  349.     private function _init(count:uint, color:uint, areaR:Number):void
  350.     {
  351.         _root = scene.addChild(new DisplayObject3D());
  352.         var bfx:BitmapEffectLayer = new BitmapEffectLayer(viewport, 465465true, 0x00FFFFFF, BitmapClearMode.CLEAR_PRE, falsefalse);
  353.         bfx.clearBeforeRender=true;
  354.         viewport.containerSprite.addLayer(bfx);
  355.         var pixels:Pixels  = new Pixels(bfx);
  356.         var rad:Number, r:Number;
  357.         for (var i:int = 0; i < count; ++i) 
  358.         {
  359.             rad = 2 * Math.PI * Math.random();
  360.             r = areaR * Math.random();
  361.             var px:Pixel3D = new Pixel3D(color, r * Math.cos(rad), Math.random() * 1000 - 400, r * Math.sin(rad));
  362.             pixels.addPixel3D(px);
  363.             _list.push(px)
  364.         }
  365.         _root.addChild(pixels);
  366.         _bmp = new Bitmap(new BitmapData(465 / 4465 / 4false, 0x00000000), PixelSnapping.NEVER, true);
  367.         _bmp.scaleX = _bmp.scaleY = 4;
  368.         _bmp.smoothing = true;
  369.         _bmp.blendMode=BlendMode.ADD;
  370.         _mtx = new Matrix(0.25000.25);
  371.     }
  372.     public function update(rotationY:Number, cameraY:Number, cameraZoom:Number):void
  373.     {
  374.         super.onRenderTick();
  375.         var px:Pixel3D;
  376.         for (var i:int = 0; i < _list.length; i++)
  377.         {
  378.             px = _list[i] as Pixel3D;
  379.             px.y = (px.y < -400) ? 600 : px.y - 1;
  380.         }
  381.         var canvas:BitmapData=_bmp.bitmapData
  382.         canvas.fillRect(canvas.rect, 0x00000000);
  383.         canvas.draw(viewport, _mtx);
  384.         _root.rotationY = rotationY;
  385.         camera.y = cameraY;
  386.         camera.zoom = cameraZoom;
  387.     }    
  388.     public function show():void { addChild(_bmp) };
  389.     public function hide():void { removeChild(_bmp) };
  390. }
  391. class Pt
  392. {
  393.     public var x:Number, y:Number, z:Number, color:uint;
  394.     public function Pt(x:Number = 0, y:Number = 0, z:Number = 0, color:uint = 0)
  395.     {
  396.         this.x = x;
  397.         this.y = y;
  398.         this.z = z;
  399.         this.color = color;
  400.     }
  401. }
noswf
  1. /**
  2.  * ネットで投稿されたメッセージが
  3.  * クリスマスの夜空を飾ります
  4.  * 
  5.  * クリスマスメッセージは
  6.  * 「Twitter」と「はてなブックマーク」で送ることができます
  7.  * ※追記:11/5(木)、Twitter仕様変更によりTwitter投稿はできなくなりました
  8.  * 
  9.  * ※投稿はFlash内のボタンを押して、
  10.  * Twitterの場合は[]内にコメントを
  11.  * はてなブックマークの場合は、ブックマークコメントを記入下さい
  12.  * 
  13.  * このFlashはwonderfl上の様々なテクニックを元に作られました
  14.  * 
  15.  * Twitter連動
  16.  * http://wonderfl.net/code/04d6d1ae7e943b7faab88623ed83404e7a40c5f7
  17.  * 
  18.  * キラキラ3D
  19.  * http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c
  20.  * 
  21.  * 文字のパーティクル化
  22.  * http://wonderfl.net/code/08ec1c2c8da8e9e487867a8e2ab8cddeb75f8986
  23.  * 
  24.  * 木を作る再帰関数
  25.  * http://wonderfl.net/code/00cbe3ecbf0db2e865bc410a8ea54677c19ba4c6 
  26.  * 
  27.  * 配列のシャッフル
  28.  * http://wonderfl.net/code/8cfa39c9e91a268791142fe605c010dc30338588 
  29.  * 
  30.  * BetweenAS3の時間調整
  31.  * http://wonderfl.net/code/59af9d8a3cc45e4c2e6fcf12a9bc9ea55b1576e7
  32.  * 
  33.  */
  34. package {
  35.     import com.bit101.components.Label;
  36.     
  37.     import flash.display.*;
  38.     import flash.events.*;
  39.     import flash.geom.Matrix;
  40.     import flash.net.*;
  41.     import flash.system.*;
  42.     import flash.text.*;
  43.     import flash.utils.*;
  44.     
  45.     import jp.progression.casts.*;
  46.     import jp.progression.commands.lists.LoaderList;
  47.     import jp.progression.commands.lists.SerialList;
  48.     import jp.progression.commands.net.*;
  49.     import jp.progression.data.getResourceById;
  50.     
  51.     import org.libspark.betweenas3.BetweenAS3;
  52.     import org.libspark.betweenas3.easing.*;
  53.     import org.libspark.betweenas3.tweens.ITween;
  54.     import org.papervision3d.cameras.Camera3D;
  55.     import org.papervision3d.core.effects.*;
  56.     import org.papervision3d.core.geom.Pixels;
  57.     import org.papervision3d.core.geom.renderables.Pixel3D;
  58.     import org.papervision3d.core.math.Number3D;
  59.     import org.papervision3d.materials.*;
  60.     import org.papervision3d.objects.DisplayObject3D;
  61.     import org.papervision3d.objects.primitives.*;
  62.     import org.papervision3d.render.BasicRenderEngine;
  63.     import org.papervision3d.scenes.Scene3D;
  64.     import org.papervision3d.view.Viewport3D;
  65.     import org.papervision3d.view.layer.BitmapEffectLayer;
  66.     [SWF(width=465, height=465, frameRate=30, backgroundColor=0)]
  67.     public class Main extends CastDocument {
  68.         static public const URL_HATENA:String = "http://pipes.yahooapis.com/pipes/pipe.run?_id=a9fa16f111d33689315b50bd196f691e&_render=rss";
  69.         //static public const URL_TWITTER:String = "http://search.twitter.com/search.atom?q=%23XmasMessage&rpp=50";
  70.         static public const URL_TWITTER:String =  "http://clockmaker.jp/labs/091022_pv3d_xmas/search.atom";
  71.         static public const URL_IMG_BG:String = "http://clockmaker.jp/labs/091021_checkmate/assets/bg.png";
  72.         static public const URL_IMG_TITLE:String = "http://clockmaker.jp/labs/091021_checkmate/assets/title.png";
  73.         static public const URL_IMG_BTN_HATENA:String = "http://clockmaker.jp/labs/091021_checkmate/assets/btn-hatena.png";
  74.         static public const URL_IMG_BTN_TWITTER:String = "http://clockmaker.jp/labs/091021_checkmate/assets/btn-twitter.png";
  75.         static private const MAX_PARTICLES:int = 2500;
  76.         // color
  77.         public static const WHITE:uint = 0xFFF0F0F0;
  78.         public static const GREEN:uint = 0xFF008800;
  79.         public static const RED:uint = 0xFFCC0000;
  80.         public static const GOLD:uint = 0xFFFFCC66;
  81.         public static const SILVER:uint = 0xFFCCCCCC;
  82.         public static const COLORS:Array = [WHITE, GREEN, RED, GOLD, SILVER];
  83.         // 3d
  84.         private var scene:Scene3D = new Scene3D();
  85.         private var renderer:BasicRenderEngine = new BasicRenderEngine();
  86.         private var viewport:Viewport3D = new Viewport3D(465465);
  87.         private var camera:Camera3D = new Camera3D()
  88.         // 3d objects
  89.         private const MAX_RADIUS:int = 10000;
  90.         private const PIXCEL_MARGIN:Number = 1.25;
  91.         private var textPixels:Pixels;
  92.         private var treePixels:Pixels;
  93.         private var pixelArr:Array = [];
  94.         private var bfx:BitmapEffectLayer;
  95.         private var dmyObjs:Array = [];
  96.         private var tweens:Array = [];
  97.         // 3d camera
  98.         public var cameraDistance:Number  = 1000;
  99.         public var cameraYaw:Number = 0;
  100.         public var cameraPitch:Number = 0;
  101.         // 2d 
  102.         private var canvas:BitmapData;
  103.         private var mtx:Matrix;
  104.         private var progress:ProgressBar;
  105.         private var loading:Label;
  106.         private var loadingTween:ITween;
  107.         // array of objs
  108.         private var data:Array = [];
  109.         // fractal
  110.         private var level:int = 0;
  111.         // data
  112.         private var index:int = 0;
  113.         private const RESET_TIMER:Timer = new Timer(11 * 1000);
  114.         
  115.         /**
  116.          * Progression 4 では atReady から処理が始まります
  117.          */        
  118.         override protected function atReady() : void{
  119.             stage.quality = StageQuality.MEDIUM;
  120.             
  121.             // 3D
  122.             addChild(viewport);
  123.             
  124.             // progress bar
  125.             progress = new ProgressBar();
  126.             progress.value = 0;
  127.             this.addChild(progress)
  128.             progress.x = int(stage.stageWidth / 2 - progress.width/2);
  129.             progress.y = int(stage.stageHeight / 2 + 10);
  130.             
  131.             // loading
  132.             loading = new Label(this, stage.stageWidth / 2 - 33, stage.stageHeight / 2 - 10"NOW LOADING");
  133.             loadingTween = BetweenAS3.tween(loading, { alpha:1 }, { alpha:0.25 }, 0.05);
  134.             loadingTween = BetweenAS3.serial(loadingTween, BetweenAS3.reverse(loadingTween));
  135.             loadingTween.stopOnComplete = false;
  136.             loadingTween.play();
  137.             
  138.             var context:LoaderContext = new LoaderContext(true);
  139.             var loaderList:LoaderList = new LoaderList(null,
  140.                 new LoadBitmapData(new URLRequest(URL_IMG_BG), {context:context}),
  141.                 new LoadBitmapData(new URLRequest(URL_IMG_TITLE), {context:context}),
  142.                 new LoadURL(new URLRequest(URL_TWITTER), {context:context}),
  143.                 new LoadURL(new URLRequest(URL_HATENA), {context:context}),
  144.                 new LoadBitmapData(new URLRequest(URL_IMG_BTN_HATENA), {context:context}),
  145.                 new LoadBitmapData(new URLRequest(URL_IMG_BTN_TWITTER), {context:context})
  146.                 );
  147.             loaderList.onProgress = function():void{
  148.                 progress.value = 0.5 * (loaderList.loaded / loaderList.numCommands)
  149.             }
  150.             
  151.             new SerialList(null,
  152.                 loaderList,
  153.                 function():void{
  154.                     
  155.                     // Twitter連携 by http://wonderfl.net/code/04d6d1ae7e943b7faab88623ed83404e7a40c5f7 (coppieee)
  156.                     default xml namespace = new Namespace("http://www.w3.org/2005/Atom");
  157.                     var xml:XML = XML(getResourceById(URL_TWITTER).data);
  158.                     for (var i:int = 0; i < xml.entry.length(); i++) {
  159.                         // コメントを抽出
  160.                         var comment:String = scan(xml.entry[i].title,/\[(.+)\]/);
  161.                         // RT は除外
  162.                         if(xml.entry[i].title.indexOf("RT") > -1continue;
  163.                         // コメントなしは除外
  164.                         if(comment == ""continue;
  165.                         // データに追加
  166.                         data.push({
  167.                             img : xml.entry[i].link.(@type == "image/png").@href,
  168.                             name : xml.entry[i].author.name.split(" (")[0],
  169.                             comment : comment
  170.                         });
  171.                     }
  172.                     
  173.                     xml = XML(getResourceById(URL_HATENA).data);
  174.                     
  175.                     for (i = 0; i < xml.channel.item.length(); i++) {
  176.                         if(xml.channel.item[i].description != undefined){
  177.                             comment = xml.channel.item[i].description;
  178.                             var name:String = xml.channel.item[i].title;
  179.                             var imgurl:String = "http://www.st-hatena.com/users/" + name.substr(0,2) + "/" + name + "/profile.gif";
  180.                             data.push({
  181.                                 img : imgurl,
  182.                                 name : name,
  183.                                 comment : comment
  184.                             });
  185.                         }
  186.                     }
  187.                     
  188.                     data = shuffle(data);
  189.                     data = data.slice(08)
  190.                 },
  191.                 init3d
  192.             ).execute();
  193.         }
  194.         /**
  195.          * Papervision3D関係のごにょごにょ 
  196.          */        
  197.         private function init3d():void {
  198.             // カメラの設定
  199.             camera.target = DisplayObject3D.ZERO;
  200.             // ビットマップエフェクトレイヤー
  201.             bfx = new BitmapEffectLayer(viewport, stage.stageWidth, stage.stageHeight);
  202.             bfx.addEffect(new BitmapColorEffect(1110.75));
  203.             viewport.containerSprite.addLayer(bfx);
  204.             // ピクセル3D
  205.             textPixels = new Pixels(bfx);
  206.             scene.addChild(textPixels);
  207.             treePixels = new Pixels(bfx);
  208.             scene.addChild(treePixels);
  209.             
  210.             var i:int;
  211.             var arr:Array = [];
  212.             // snow
  213.             var star:Array = [0xFFFFFFFF, 0xFFcccccc, 0xFF666666, 0xFF333333]
  214.             for (i = 0; i < 1500; i++) {
  215.                 treePixels.addPixel3D(new Pixel3D(star[star.length * Math.random() | 0],
  216.                     10000 * (Math.random() - 0.5),
  217.                     10000 * (Math.random()) - 1000,
  218.                     10000 * (Math.random() - 0.5)));
  219.             }
  220.             for (i = 0; i < 255; i++) {
  221.                 treePixels.addPixel3D(new Pixel3D(0xFF0066CC,
  222.                     100 * (Math.floor(i / 15) - 7),
  223.                     -1000,
  224.                     100 * (i % 15 - 7)));
  225.             }
  226.             // ダミーオブジェクトを作成
  227.             for (var k:int = 0; k < data.length; k++) {
  228.                 dmyObjs[k] = new DisplayObject3D();
  229.                 while (true) {
  230.                     var angle:Number = 360 * Math.random();
  231.                     dmyObjs[k].x = 2000 * Math.sin(angle * Number3D.toRADIANS);
  232.                     dmyObjs[k].y = 2000 * (Math.random() - 0.5);
  233.                     dmyObjs[k].z = 2000 * Math.cos(angle * Number3D.toRADIANS);
  234.                     if (k == 0)
  235.                         break;
  236.                     else {
  237.                         if (DisplayObject3D(dmyObjs[k]).distanceTo(dmyObjs[k - 1]) >= 500)
  238.                             break;
  239.                     }
  240.                 }
  241.                 dmyObjs[k].lookAt(DisplayObject3D.ZERO);
  242.                 scene.addChild(dmyObjs[k]);
  243.             }
  244.             for (i = 0; i < MAX_PARTICLES; i++) {
  245.                 var p:Pixel3D = new Pixel3D(COLORS[COLORS.length * Math.random() | 0]);
  246.                 textPixels.addPixel3D(p);
  247.             }
  248.             drawTree(0, -10000100090, GOLD);
  249.             
  250.             loading.text = "NOW RENDERING"
  251.             loading.x = stage.stageWidth / 2 - 39
  252.             var cmd:SerialList = new SerialList();
  253.             var renderIndex:int=0;
  254.             for (i = 0; i < data.length; i++) {
  255.                 cmd.addCommand(
  256.                     function():void{
  257.                         preRenderText(renderIndex);
  258.                         createText(renderIndex);
  259.                         renderIndex ++;
  260.                         
  261.                         progress.value = 0.5 + 0.5 * (renderIndex / data.length);
  262.                     },
  263.                     0.05
  264.                 );
  265.             }
  266.             cmd.addCommand(
  267.                 function():void{
  268.                     // remove loading
  269.                     removeChild(loading);
  270.                     removeChild(progress);
  271.                     loadingTween.stop();
  272.                     loadingTween = null;
  273.                     
  274.                     // ui
  275.                     addChildAt(new CastBitmap(getResourceById(URL_IMG_BG).data), 0);
  276.                     addChild(new CastBitmap(getResourceById(URL_IMG_TITLE).data, "auto"false, {x:20, y:376}));
  277.                     
  278.                     var hatenaBtn:CastButton = new CastButton({x:20, y:433});
  279.                     hatenaBtn.addChild(new Bitmap(getResourceById(URL_IMG_BTN_HATENA).data));
  280.                     hatenaBtn.onCastMouseUp = function():void{
  281.                         navigateToURL(new URLRequest("http://b.hatena.ne.jp/append?http://wonderfl.net/code/d5de28ad1f65364ee33b964101222be41a7320af"));
  282.                     }
  283.                     hatenaBtn.buttonMode = true;
  284.                     addChild(hatenaBtn);
  285.                     
  286.                     var tweetBtn:CastButton = new CastButton({x:240, y:433});
  287.                     tweetBtn.addChild(new Bitmap(getResourceById(URL_IMG_BTN_TWITTER).data));
  288.                     tweetBtn.onCastMouseUp = function():void{
  289.                         navigateToURL(new URLRequest("http://twitter.com/home/?status=" + escapeMultiByte("#XmasMessage [] http://j.mp/xmaswon")));
  290.                     };
  291.                     tweetBtn.buttonMode = true;
  292.                     addChild(tweetBtn);
  293.                     
  294.                     // キラキラロジック by http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c (sake)
  295.                     canvas = new BitmapData(720 / 4485 / 4false, 0x000000);
  296.                     var bmp:Bitmap = new Bitmap(canvas, PixelSnapping.NEVER, false);
  297.                     bmp.scaleX = bmp.scaleY = 4;
  298.                     bmp.smoothing = true;
  299.                     bmp.blendMode = BlendMode.ADD;
  300.                     addChildAt(bmp,2);
  301.                     mtx = new Matrix();
  302.                     mtx.scale(0.250.25);
  303.                     // tree
  304.                     drawTree(0, -10000100090, GOLD);
  305.                     // タイマーを作る
  306.                     RESET_TIMER.addEventListener(TimerEvent.TIMER, timerHandler);
  307.                     RESET_TIMER.start();
  308.                     // エンターフレーム
  309.                     addEventListener(Event.ENTER_FRAME, loop);
  310.                 },
  311.                 timerHandler
  312.             );
  313.             cmd.execute();
  314.         }
  315.         private function timerHandler(e:TimerEvent = null):void {
  316.             var i:int;
  317.             var arr:Array = [];
  318.             for (i = 0; i < textPixels.pixels.length; i++) {
  319.                 arr[i] = BetweenAS3.serial(
  320.                     BetweenAS3.delay(
  321.                         BetweenAS3.to(textPixels.pixels[i], getRandomPos(), 3, Expo.easeInOut),
  322.                         Math.random()));
  323.             }
  324.             BetweenAS3.serial(
  325.                 BetweenAS3.parallelTweens(arr),
  326.                 BetweenAS3.func(function():void {
  327.                     setTimeout(motionText, 2 * 1000);
  328.                 })
  329.                 ).play();
  330.             //
  331.             index++;
  332.             if (index == data.length - 1)
  333.                 index = 0;
  334.             //
  335.             var cameraTarget:DisplayObject3D = new DisplayObject3D();
  336.             cameraTarget.copyTransform(dmyObjs[index]);
  337.             cameraTarget.moveBackward(250);
  338.             var dis:Number = cameraTarget.distanceTo(DisplayObject3D.ZERO);
  339.             var rot:Number = Math.atan2(cameraTarget.x, cameraTarget.z);
  340.             
  341.             BetweenAS3.parallel(
  342.                 BetweenAS3.delay(
  343.                     BetweenAS3.bezier(this, {
  344.                         cameraYaw: rot,
  345.                         cameraDistance: dis,
  346.                         cameraPitch: cameraTarget.y
  347.                     }, null, getRandomPos(), 10.5, Expo.easeInOut),
  348.                 1.0) ,
  349.                 BetweenAS3.serial(
  350.                     BetweenAS3.to(camera, {
  351.                         fov: 60
  352.                     }, 4, Sine.easeInOut),
  353.                     BetweenAS3.to(camera, {
  354.                         fov: 50
  355.                     }, 8, Sine.easeInOut)
  356.                     )
  357.                 ).play();
  358.         }
  359.         private var preRenderedTests:Array = [];
  360.         private function preRenderText(itemIndex:int):void {
  361.             preRenderedTests[itemIndex] = [];
  362.             var text:TextField = new TextField();
  363.             text.multiline = true;
  364.             text.autoSize = "left";
  365.             text.htmlText = "<font face='Arial' size='24'>WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW</font>";
  366.             trace(data[itemIndex].comment);
  367.             
  368.             var size:int = 24;
  369.             while(text.textWidth * text.textHeight > MAX_PARTICLES){
  370.                 text.htmlText = "<font face='Arial' size='" + size +"'>" + data[itemIndex].comment + "</font>"
  371. //                                +"<br><font face='Arial' size='" + size / 2 + "'>" + String(data[itemIndex].name).toUpperCase() + "</font>";
  372.                 size--;
  373.             }
  374.             
  375.             var cap:BitmapData = new BitmapData(text.textWidth + 10, text.textHeight, true, 0xFFFFFFFF);
  376.             cap.lock();
  377.             cap.draw(text);
  378.             // particle motion
  379.             var cnt:int = 0;
  380.             for (var i:int = 0; i < text.textWidth + 10; i++) {
  381.                 for (var j:int = 0; j < text.textHeight; j++) {
  382.                     if (cap.getPixel(i, j) == 0xFFFFFF)
  383.                         continue;
  384.                     if(preRenderedTests[itemIndex].length >= MAX_PARTICLES) break
  385.                     preRenderedTests[itemIndex].push({x: i, y: j, textWidth: text.textWidth, textHeight: text.textHeight});
  386.                 }
  387.             }
  388.             cap.unlock();
  389.             cap.dispose();
  390.         }
  391.         /**
  392.          * テキストをBitmapData化してトゥイーンとして作成 
  393.          * @param itemIndex
  394.          */        
  395.         private function createText(itemIndex:int):void {
  396.             var t:DisplayObject3D = dmyObjs[itemIndex];
  397.             // particle motion
  398.             var cnt:int = 0;
  399.             var arr:Array = [];
  400.             for (var i:int = 0; i < preRenderedTests[itemIndex].length; i++) {
  401.                 var pix:Object = preRenderedTests[itemIndex][i];
  402.                 var p:Pixel3D = textPixels.pixels[i];
  403.                 var vec:DisplayObject3D = new DisplayObject3D();
  404.                 vec.x = (pix.x - pix.textWidth / 2) * PIXCEL_MARGIN;
  405.                 vec.y = (pix.textHeight / 2 - pix.y) * PIXCEL_MARGIN;
  406.                 vec.z = 0;
  407.                 vec.transform.calculateMultiply(t.transform, vec.transform);
  408.                 arr[i] = BetweenAS3.bezier(p, {
  409.                         x: vec.x,
  410.                         y: vec.y,
  411.                         z: vec.z
  412.                     }, null, getRandomPos(), 1.2 + Math.random() * 0.25 + i * 0.002, Expo.easeOut);
  413.             }
  414.             tweens.push(arr);
  415.         }
  416.         private function motionText():void {
  417.             var tw:ITween = BetweenAS3.parallelTweens(tweens[index]);
  418.             // トゥイーンのデュレーションを調整
  419.             tw = BetweenAS3.scale(tw, 3.5 / tw.duration);
  420.             tw.play();
  421.         }
  422.         /**
  423.          * エンターフレームイベント 
  424.          */        
  425.         private function loop(e:Event = null):void {
  426.             // カメラ
  427.             camera.x = cameraDistance * Math.sin(cameraYaw);
  428.             camera.y = cameraPitch;
  429.             camera.z = cameraDistance * Math.cos(cameraYaw);
  430.             
  431.             // レンダリング
  432.             renderer.renderScene(scene, camera, viewport);
  433.             
  434.             // キラキラ
  435.             canvas.fillRect(canvas.rect, 0x000000);
  436.             canvas.draw(viewport, mtx);
  437.         }
  438.         private function getRandomPos():Object {
  439.             return {
  440.                     x: MAX_RADIUS * (Math.random() - 0.5),
  441.                     y: MAX_RADIUS * (Math.random() - 0.5),
  442.                     z: MAX_RADIUS * (Math.random() - 0.5)
  443.                 };
  444.         }
  445.         /**
  446.          * 木を作る再帰関数
  447.          * http://wonderfl.net/code/00cbe3ecbf0db2e865bc410a8ea54677c19ba4c6 
  448.          * @param x
  449.          * @param y
  450.          * @param z
  451.          * @param length
  452.          * @param angle
  453.          * @param cf
  454.          * 
  455.          */
  456.         private function drawTree(x:Number, y:Number, z:Number, length:Number, angle:Number, cf:int):void {
  457.             level += 1;
  458.             var destx:Number = x + length * Math.cos(angle * (Math.PI / 180));
  459.             var desty:Number = y + length * Math.sin(angle * (Math.PI / 180));
  460.             var destz:Number = z + length * (Math.random() - 0.5) * 2;
  461.             if (Math.random() < 0.5)
  462.                 cf = COLORS[COLORS.length * Math.random() | 0];
  463.             var max:int = 10 - level / 1.5;
  464.             for (var i:int = 0; i < max; i++) {
  465.                 treePixels.addPixel3D(new Pixel3D(cf,
  466.                     destx * i / max + x * (max - i) / max,
  467.                     desty * i / max + y * (max - i) / max,
  468.                     destz * i / max + z * (max - i) / max
  469.                     ));
  470.             }
  471.             if (level < 6) {
  472.                 drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
  473.                 drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
  474.                 drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
  475.                 drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
  476.             }
  477.             level -= 1;
  478.         }
  479.         
  480.         /**
  481.          * 1行でArrayをシャッフルする by nemu90kWw
  482.          * http://wonderfl.net/code/8cfa39c9e91a268791142fe605c010dc30338588 
  483.          */        
  484.         public function shuffle(array:Array):Array{
  485.             return array.sort(function():int{return int(Math.random()*3)-1});
  486.         }
  487.         
  488.         /**
  489.          * @see http://takumakei.blogspot.com/2009/05/actionscriptrubystringscan.html
  490.          */ 
  491.         //package com.blogspot.takumakei.utils
  492.         //{
  493.         //public
  494.         public function scan(str:String, re:RegExp):Array
  495.         {
  496.             if(!re.global){
  497.                 var flags:String = 'g';
  498.                 
  499.                 if(re.dotall)
  500.                     flags += 's';
  501.                 if(re.multiline)
  502.                     flags += 'm';
  503.                 if(re.ignoreCase)
  504.                     flags += 'i';
  505.                 if(re.extended)
  506.                     flags += 'x';
  507.                 re = new RegExp(re.source, flags);                    
  508.             }
  509.             var r:Array = [];
  510.             var m:Array = re.exec(str);
  511.             while(null != m){
  512.                 if(1 == m.length)
  513.                     r.push(m[0]);
  514.                 else
  515.                     r.push(m.slice(1, m.length));
  516.                 m = re.exec(str);
  517.             }
  518.             return r;
  519.         }
  520.         //}
  521.     }
  522. }
  523. import flash.display.*;
  524. class ProgressBar extends Sprite {
  525.     private var edge:Sprite = new Sprite;
  526.     private var cont:Sprite = new Sprite;
  527.     
  528.     private var _value:Number = 0;
  529.     
  530.     public function set value(v:Number):void {
  531.         _value = v;
  532.         cont.scaleX = _value;
  533.     }
  534.     
  535.     public function get value():Number {
  536.         return _value;
  537.     }
  538.     
  539.     public function ProgressBar() {
  540.         edge.graphics.lineStyle(1, 0xFFFFFF);
  541.         edge.graphics.drawRect(0.50.510010);
  542.         
  543.         cont.graphics.beginFill(0x555555);
  544.         cont.graphics.drawRect(0010010);
  545.         
  546.         addChild(cont);
  547.         addChild(edge);
  548.         
  549.         value = 0;
  550.     }
  551. }
noswf
  1. // forked from checkmate's Checkmate vol4 Massmedian
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.net.*;
  6.     import flash.geom.*;
  7.     import flash.system.LoaderContext;
  8.     [SWF(backgroundColor=0x00,width="465", height="465", frameRate=60)]
  9.     public class FlashTest extends Sprite {
  10.         /*
  11.          * [Checkmate Vol4 by MASSMEDIAN]
  12.          * Please produce the illumination freely with a color palette. 
  13.          *
  14.          * usage of Palette class
  15.          *   A single value is used.
  16.          *     var white:uint = Palette.WHITE;
  17.          *     var green:uint = Palette.GREEN;
  18.          *     var red:uint = Palette.RED;
  19.          *     var gold:uint = Palette.GOLD;
  20.          *     var silver:uint = Palette.SILVER;
  21.          *     var black:uint = Palette.BLACK;
  22.          *   All the values are used.
  23.          *     var colors:Array = Palette.getColors();
  24.          */
  25.         private function init( e:Event = null ):void {
  26.             resize();
  27.             drawXmasTree()
  28.         }
  29.         
  30.         public var rect:Rectangle = new Rectangle();
  31.         public var center:Point = new Point();
  32.         public var bmd1:BitmapData;
  33.         public var bmd2:BitmapData;
  34.         public var bmp:Bitmap;
  35.         public var loader :Loader;
  36.         
  37.         private const SLOW_LENGTH:int = 8000;
  38.         private var _snow:Vector.<Snow> = new Vector.<Snow>();
  39.         
  40.         private var _twincles:BitmapData;
  41.         private var _canvas:BitmapData;
  42.         
  43.         private var _matrix:Matrix;
  44.         private var _ctf:ColorTransform = new ColorTransform( 0.750.80.80.95 );
  45.         
  46.         private function createSnow():void {
  47.             // The value used for generation is prepared.
  48.             const RADIAN:Number = Math.PI*2;
  49.             const COLORS:Array = Palette.getColors();
  50.             
  51.             // The canvas to draw in illumination.
  52.             var snow:Snow, speed:Number, angle:Number;
  53.             forvar i :int = 0; i<SLOW_LENGTH; ++i ) {
  54.                 snow = new Snow();
  55.                 snow.x   = (Math.random()-0.5)*rect.width + center.x;
  56.                 snow.y   = Math.random()*rect.height;
  57.                 snow.vx = (Math.random()-0.5) * 4;
  58.                 snow.vy = Math.random()*-2;
  59.                 snow.color = COLORS[int(COLORS.length*Math.random())];
  60.                 _snow.push( snow );
  61.             }
  62.             
  63.             // The canvas to draw in illumination.
  64.             _canvas = new BitmapData( rect.width, rect.height, true0 );
  65.             var cbm :Bitmap = addChild( new Bitmap( _canvas ) ) as Bitmap;
  66.             cbm.smoothing = true;
  67.             
  68.             // The canvas to draw in twincles.
  69.             _twincles = new BitmapData( rect.width/4>>0, rect.height/4>>0true0 );
  70.             var tbm:Bitmap = addChild( new Bitmap( _twincles ) ) as Bitmap;
  71.             tbm.scaleX = tbm.scaleY = 4;
  72.             tbm.smoothing = true;
  73.             tbm.blendMode = BlendMode.ADD;
  74.             
  75.             // Matrix to draw by size of 1/4
  76.             _matrix = new Matrix(0.25000.25);
  77.             
  78.             addEventListener( Event.ENTER_FRAME, updateSnow );
  79.         }
  80.         
  81.         private function updateSnow(e:Event):void {
  82.             _canvas.lock();
  83.             for eachvar snow:Snow in _snow ) {
  84.                 // The Brownian motion is added.
  85.                 snow.vx += (Math.random()-0.5)*0.04;
  86.                 snow.vy += (Math.random()-0.5)*0.04;
  87.                 
  88.                 // Gravity is added.
  89.                 snow.vy += 0.015;
  90.                 
  91.                 // The wind drag is added.
  92.                 snow.vx *= 0.987;
  93.                 snow.vy *= 0.987;
  94.                 
  95.                 // The speed is added to the position. 
  96.                 snow.x += snow.vx;
  97.                 snow.y += snow.vy;
  98.                 
  99.                 // draw to canvas in position.
  100.                 _canvas.setPixel32( snow.x, snow.y, snow.color | 0xFF<<24 );
  101.                 
  102.                 // It resets it when going out of the area. 
  103.                 if( snow.x < rect.x -50 ||  snow.y < rect.y -50 || snow.x > rect.width +50 || snow.y > rect.height + 50 ) {
  104.                     snow.x = center.y + (Math.random() -0.5) * rect.width;
  105.                     snow.y = Math.random() *-30;
  106.                     snow.vx = (Math.random() -0.5) * 3;
  107.                     snow.vy = Math.random() *-3;
  108.                 }
  109.                 
  110.                 if (bmd2.getPixel(snow.x, snow.y) != 0) {
  111.                     snow.vx = 0;
  112.                     snow.vy = 0;
  113.                     snow.x += snow.vx;
  114.                     snow.y += snow.vy;
  115.                 }
  116.             }
  117.             // ColorTransform(effect that dose blackout) is made to adjust. 
  118.             _canvas.colorTransform( _canvas.rect, _ctf );
  119.             _canvas.unlock();
  120.             
  121.             // draw to canvas in twincles by using Matrix.
  122.             _twincles.draw( _canvas, _matrix );
  123.         }
  124.         
  125.         
  126.         private function resize( e:Event = null ):void {
  127.             rect.width = stage.stageWidth;
  128.             rect.height= stage.stageHeight;
  129.             
  130.             center.x = rect.width /2>>0;
  131.             center.y = rect.height /2>>0;
  132.         }
  133.         
  134.         private function drawXmasTree():void {
  135.             var context:LoaderContext = new LoaderContext(true);
  136.             
  137.             loader = new Loader();
  138.             loader.load( new URLRequest("http://swf-dev.wonderfl.net/static/assets/checkmate04/tree.jpg"), context );
  139.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete);
  140.         }
  141.         
  142.         private function complete(e:Event):void {
  143.                 bmd1 = new BitmapData(loader.width, loader.height, true);
  144.                 bmd1.draw(loader);
  145.                 bmd2 = bmd1.clone();
  146.                 bmp = new Bitmap(bmd2);
  147.                 addChild(bmp);
  148.                 createSnow();
  149.         }
  150.         
  151.         private function showPaletteMap():void {
  152.             var colors:Array = Palette.getColors();
  153.             var palette:Sprite = addChild( new ColorMap( colors ) ) as Sprite;
  154.             palette.x = ( rect.width - palette.width )  /2 >>0;
  155.             palette.y = ( rect.height- palette.height ) /2 >>0;
  156.         }
  157.         
  158.         public function FlashTest() {
  159.             if( stage ) init();
  160.             else addEventListener( Event.ADDED_TO_STAGE, init );
  161.         }
  162.     }
  163. }
  164. /* for Checkmate */
  165. class Palette {
  166.     public static const WHITE:uint = 0xF0F0F0;
  167.     public static const GREEN:uint = 0x008800;
  168.     public static const RED:uint = 0xCC0000;
  169.     public static const GOLD:uint = 0xFFCC66;
  170.     public static const SILVER:uint = 0xCCCCCC;
  171.     public static const BLACK:uint = 0x101010;
  172.     public static const COLORS:Array = [ WHITE, GREEN,  RED, GOLD, SILVER, BLACK ];
  173.     public static function getColors():Array { return COLORS.slice(); }
  174. }
  175. /* for Example. */
  176. class Snow {
  177.     public var x:Number = 0;
  178.     public var y:Number = 0;
  179.     public var vx:Number = 0;
  180.     public var vy:Number = 0;
  181.     public var color:uint = 0x00;
  182. }
  183. /* for debug. */
  184. import flash.display.*;
  185. class ColorMap extends Sprite {
  186.     public function ColorMap(colors:Array) {
  187.         var l:int = colors.length;
  188.         var rect:Sprite;
  189.         forvar i:int=0; i<l; ++i ) {
  190.             addChild( rect = new ColorRect( colors[ i ] ) );
  191.             rect.x =i * ColorRect.WIDTH;
  192.             rect.y =0;
  193.         }
  194.     }
  195. }
  196. /* for debug. */
  197. class ColorRect extends Sprite {
  198.     public static const WIDTH:int = 40;
  199.     public static const HEIGHT:int = 40;
  200.     public function ColorRect( color:uint ) {
  201.         super();
  202.         graphics.beginFill( color, 1 );
  203.         graphics.drawRect( 00, WIDTH, HEIGHT );
  204.         graphics.endFill();
  205.     }
  206. }
noswf

ad

ad ad

Get Adobe Flash Player