Massmedian

今回は、一足はやいクリスマスでしたが、いかがでしたでしょうか?
ご応募やコメントをたくさんいただき、誠にありがとうございました。
みているだけでも、クリスマスが楽しみになってきました(まだ少し早いですが・・・)。
これから、お仕事上でも色々とアイディアが必要となる時期かと思います。
これを機に、たくさんwonderflをつかって、クリスマスのクリエイティブが生まれることを。
そして、それがスキルアップにつながることを。
なによりも、素敵なクリスマスが過ごせるよう祈っております。

This time is about X'MAS. It's quite early for Christmas, but how was it?
Thank you very much for your participation and comments. Just looking at the Flash, I became looking forward to X'MAS season(eventhough, it's a little bit early)
From now on, it will be the time for creating many ideas.
We hope wonderfl inspire lots of the X'MAS creative works, and it will improve the developer's skills. Last but not least, we hope that you will have a good holiday season!

  1. Queen
    clockmaker
    presentブレーン年間購読+マッサージグッズ
    "BRAIN" one year subscription + Massage Items
  2. Bishop
    nanlow
    presentブレーン年間購読+マッサージグッズ
    "BRAIN" one year subscription + Massage Items
  3. Knight
    該当者なし Not corresponding

View All Other Challengers

Queenclockmaker

  1. /**
  2.  * ネットで投稿されたメッセージが
  3.  * クリスマスの夜空を飾ります
  4.  * 
  5.  * クリスマスメッセージは
  6.  * 「Twitter」と「はてなブックマーク」で送ることができます
  7.  * 
  8.  * ※投稿はFlash内のボタンを押して、
  9.  * Twitterの場合は[]内にコメントを
  10.  * はてなブックマークの場合は、ブックマークコメントを記入下さい
  11.  * 
  12.  * このFlashはwonderfl上の様々なテクニックを元に作られました
  13.  * 
  14.  * Twitter連動
  15.  * http://wonderfl.net/code/04d6d1ae7e943b7faab88623ed83404e7a40c5f7
  16.  * 
  17.  * キラキラ3D
  18.  * http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c
  19.  * 
  20.  * 文字のパーティクル化
  21.  * http://wonderfl.net/code/08ec1c2c8da8e9e487867a8e2ab8cddeb75f8986
  22.  * 
  23.  * 木を作る再帰関数
  24.  * http://wonderfl.net/code/00cbe3ecbf0db2e865bc410a8ea54677c19ba4c6 
  25.  * 
  26.  * 配列のシャッフル
  27.  * http://wonderfl.net/code/8cfa39c9e91a268791142fe605c010dc30338588 
  28.  * 
  29.  * BetweenAS3の時間調整
  30.  * http://wonderfl.net/code/59af9d8a3cc45e4c2e6fcf12a9bc9ea55b1576e7
  31.  * 
  32.  */
  33. package {
  34.     import com.bit101.components.Label;
  35.     
  36.     import flash.display.*;
  37.     import flash.events.*;
  38.     import flash.geom.Matrix;
  39.     import flash.net.*;
  40.     import flash.system.*;
  41.     import flash.text.*;
  42.     import flash.utils.*;
  43.     
  44.     import jp.progression.casts.*;
  45.     import jp.progression.commands.lists.LoaderList;
  46.     import jp.progression.commands.lists.SerialList;
  47.     import jp.progression.commands.net.*;
  48.     import jp.progression.data.getResourceById;
  49.     
  50.     import org.libspark.betweenas3.BetweenAS3;
  51.     import org.libspark.betweenas3.easing.*;
  52.     import org.libspark.betweenas3.tweens.ITween;
  53.     import org.papervision3d.cameras.Camera3D;
  54.     import org.papervision3d.core.effects.*;
  55.     import org.papervision3d.core.geom.Pixels;
  56.     import org.papervision3d.core.geom.renderables.Pixel3D;
  57.     import org.papervision3d.core.math.Number3D;
  58.     import org.papervision3d.materials.*;
  59.     import org.papervision3d.objects.DisplayObject3D;
  60.     import org.papervision3d.objects.primitives.*;
  61.     import org.papervision3d.render.BasicRenderEngine;
  62.     import org.papervision3d.scenes.Scene3D;
  63.     import org.papervision3d.view.Viewport3D;
  64.     import org.papervision3d.view.layer.BitmapEffectLayer;
  65.     [SWF(width=465, height=465, frameRate=30, backgroundColor=0)]
  66.     public class Main extends CastDocument {
  67.         static public const URL_HATENA:String = "http://pipes.yahooapis.com/pipes/pipe.run?_id=a9fa16f111d33689315b50bd196f691e&_render=rss";
  68.         static public const URL_TWITTER:String = "http://search.twitter.com/search.atom?q=%23XmasMessage&rpp=50";
  69.         static public const URL_IMG_BG:String = "http://clockmaker.jp/labs/091021_checkmate/assets/bg.png";
  70.         static public const URL_IMG_TITLE:String = "http://clockmaker.jp/labs/091021_checkmate/assets/title.png";
  71.         static public const URL_IMG_BTN_HATENA:String = "http://clockmaker.jp/labs/091021_checkmate/assets/btn-hatena.png";
  72.         static public const URL_IMG_BTN_TWITTER:String = "http://clockmaker.jp/labs/091021_checkmate/assets/btn-twitter.png";
  73.         static private const MAX_PARTICLES:int = 2500;
  74.         // color
  75.         public static const WHITE:uint = 0xFFF0F0F0;
  76.         public static const GREEN:uint = 0xFF008800;
  77.         public static const RED:uint = 0xFFCC0000;
  78.         public static const GOLD:uint = 0xFFFFCC66;
  79.         public static const SILVER:uint = 0xFFCCCCCC;
  80.         public static const COLORS:Array = [WHITE, GREEN, RED, GOLD, SILVER];
  81.         // 3d
  82.         private var scene:Scene3D = new Scene3D();
  83.         private var renderer:BasicRenderEngine = new BasicRenderEngine();
  84.         private var viewport:Viewport3D = new Viewport3D(465465);
  85.         private var camera:Camera3D = new Camera3D()
  86.         // 3d objects
  87.         private const MAX_RADIUS:int = 10000;
  88.         private const PIXCEL_MARGIN:Number = 1.25;
  89.         private var textPixels:Pixels;
  90.         private var treePixels:Pixels;
  91.         private var pixelArr:Array = [];
  92.         private var bfx:BitmapEffectLayer;
  93.         private var dmyObjs:Array = [];
  94.         private var tweens:Array = [];
  95.         // 3d camera
  96.         public var cameraDistance:Number  = 1000;
  97.         public var cameraYaw:Number = 0;
  98.         public var cameraPitch:Number = 0;
  99.         // 2d 
  100.         private var canvas:BitmapData;
  101.         private var mtx:Matrix;
  102.         private var progress:ProgressBar;
  103.         private var loading:Label;
  104.         private var loadingTween:ITween;
  105.         // array of objs
  106.         private var data:Array = [];
  107.         // fractal
  108.         private var level:int = 0;
  109.         // data
  110.         private var index:int = 0;
  111.         private const RESET_TIMER:Timer = new Timer(11 * 1000);
  112.         
  113.         /**
  114.          * Progression 4 では atReady から処理が始まります
  115.          */        
  116.         override protected function atReady() : void{
  117.             stage.quality = StageQuality.MEDIUM;
  118.             
  119.             // 3D
  120.             addChild(viewport);
  121.             
  122.             // progress bar
  123.             progress = new ProgressBar();
  124.             progress.value = 0;
  125.             this.addChild(progress)
  126.             progress.x = int(stage.stageWidth / 2 - progress.width/2);
  127.             progress.y = int(stage.stageHeight / 2 + 10);
  128.             
  129.             // loading
  130.             loading = new Label(this, stage.stageWidth / 2 - 33, stage.stageHeight / 2 - 10"NOW LOADING");
  131.             loadingTween = BetweenAS3.tween(loading, { alpha:1 }, { alpha:0.25 }, 0.05);
  132.             loadingTween = BetweenAS3.serial(loadingTween, BetweenAS3.reverse(loadingTween));
  133.             loadingTween.stopOnComplete = false;
  134.             loadingTween.play();
  135.             
  136.             var context:LoaderContext = new LoaderContext(true);
  137.             var loaderList:LoaderList = new LoaderList(null,
  138.                 new LoadBitmapData(new URLRequest(URL_IMG_BG), {context:context}),
  139.                 new LoadBitmapData(new URLRequest(URL_IMG_TITLE), {context:context}),
  140.                 new LoadURL(new URLRequest(URL_TWITTER), {context:context}),
  141.                 new LoadURL(new URLRequest(URL_HATENA), {context:context}),
  142.                 new LoadBitmapData(new URLRequest(URL_IMG_BTN_HATENA), {context:context}),
  143.                 new LoadBitmapData(new URLRequest(URL_IMG_BTN_TWITTER), {context:context})
  144.                 );
  145.             loaderList.onProgress = function():void{
  146.                 progress.value = 0.5 * (loaderList.loaded / loaderList.numCommands)
  147.             }
  148.             
  149.             new SerialList(null,
  150.                 loaderList,
  151.                 function():void{
  152.                     
  153.                     // Twitter連携 by http://wonderfl.net/code/04d6d1ae7e943b7faab88623ed83404e7a40c5f7 (coppieee)
  154.                     default xml namespace = new Namespace("http://www.w3.org/2005/Atom");
  155.                     var xml:XML = XML(getResourceById(URL_TWITTER).data);
  156.                     for (var i:int = 0; i < xml.entry.length(); i++) {
  157.                         // コメントを抽出
  158.                         var comment:String = scan(xml.entry[i].title,/\[(.+)\]/);
  159.                         // RT は除外
  160.                         if(xml.entry[i].title.indexOf("RT") > -1continue;
  161.                         // コメントなしは除外
  162.                         if(comment == ""continue;
  163.                         // データに追加
  164.                         data.push({
  165.                             img : xml.entry[i].link.(@type == "image/png").@href,
  166.                             name : xml.entry[i].author.name.split(" (")[0],
  167.                             comment : comment
  168.                         });
  169.                     }
  170.                     
  171.                     xml = XML(getResourceById(URL_HATENA).data);
  172.                     
  173.                     for (i = 0; i < xml.channel.item.length(); i++) {
  174.                         if(xml.channel.item[i].description != undefined){
  175.                             comment = xml.channel.item[i].description;
  176.                             var name:String = xml.channel.item[i].title;
  177.                             var imgurl:String = "http://www.st-hatena.com/users/" + name.substr(0,2) + "/" + name + "/profile.gif";
  178.                             data.push({
  179.                                 img : imgurl,
  180.                                 name : name,
  181.                                 comment : comment
  182.                             });
  183.                         }
  184.                     }
  185.                     
  186.                     data = shuffle(data);
  187.                     data = data.slice(08)
  188.                 },
  189.                 init3d
  190.             ).execute();
  191.         }
  192.         /**
  193.          * Papervision3D関係のごにょごにょ 
  194.          */        
  195.         private function init3d():void {
  196.             // カメラの設定
  197.             camera.target = DisplayObject3D.ZERO;
  198.             // ビットマップエフェクトレイヤー
  199.             bfx = new BitmapEffectLayer(viewport, stage.stageWidth, stage.stageHeight);
  200.             bfx.addEffect(new BitmapColorEffect(1110.75));
  201.             viewport.containerSprite.addLayer(bfx);
  202.             // ピクセル3D
  203.             textPixels = new Pixels(bfx);
  204.             scene.addChild(textPixels);
  205.             treePixels = new Pixels(bfx);
  206.             scene.addChild(treePixels);
  207.             
  208.             var i:int;
  209.             var arr:Array = [];
  210.             // snow
  211.             var star:Array = [0xFFFFFFFF, 0xFFcccccc, 0xFF666666, 0xFF333333]
  212.             for (i = 0; i < 1500; i++) {
  213.                 treePixels.addPixel3D(new Pixel3D(star[star.length * Math.random() | 0],
  214.                     10000 * (Math.random() - 0.5),
  215.                     10000 * (Math.random()) - 1000,
  216.                     10000 * (Math.random() - 0.5)));
  217.             }
  218.             for (i = 0; i < 255; i++) {
  219.                 treePixels.addPixel3D(new Pixel3D(0xFF0066CC,
  220.                     100 * (Math.floor(i / 15) - 7),
  221.                     -1000,
  222.                     100 * (i % 15 - 7)));
  223.             }
  224.             // ダミーオブジェクトを作成
  225.             for (var k:int = 0; k < data.length; k++) {
  226.                 dmyObjs[k] = new DisplayObject3D();
  227.                 while (true) {
  228.                     var angle:Number = 360 * Math.random();
  229.                     dmyObjs[k].x = 2000 * Math.sin(angle * Number3D.toRADIANS);
  230.                     dmyObjs[k].y = 2000 * (Math.random() - 0.5);
  231.                     dmyObjs[k].z = 2000 * Math.cos(angle * Number3D.toRADIANS);
  232.                     if (k == 0)
  233.                         break;
  234.                     else {
  235.                         if (DisplayObject3D(dmyObjs[k]).distanceTo(dmyObjs[k - 1]) >= 500)
  236.                             break;
  237.                     }
  238.                 }
  239.                 dmyObjs[k].lookAt(DisplayObject3D.ZERO);
  240.                 scene.addChild(dmyObjs[k]);
  241.             }
  242.             for (i = 0; i < MAX_PARTICLES; i++) {
  243.                 var p:Pixel3D = new Pixel3D(COLORS[COLORS.length * Math.random() | 0]);
  244.                 textPixels.addPixel3D(p);
  245.             }
  246.             drawTree(0, -10000100090, GOLD);
  247.             
  248.             loading.text = "NOW RENDERING"
  249.             loading.x = stage.stageWidth / 2 - 39
  250.             var cmd:SerialList = new SerialList();
  251.             var renderIndex:int=0;
  252.             for (i = 0; i < data.length; i++) {
  253.                 cmd.addCommand(
  254.                     function():void{
  255.                         preRenderText(renderIndex);
  256.                         createText(renderIndex);
  257.                         renderIndex ++;
  258.                         
  259.                         progress.value = 0.5 + 0.5 * (renderIndex / data.length);
  260.                     },
  261.                     0.05
  262.                 );
  263.             }
  264.             cmd.addCommand(
  265.                 function():void{
  266.                     // remove loading
  267.                     removeChild(loading);
  268.                     removeChild(progress);
  269.                     loadingTween.stop();
  270.                     loadingTween = null;
  271.                     
  272.                     // ui
  273.                     addChildAt(new CastBitmap(getResourceById(URL_IMG_BG).data), 0);
  274.                     addChild(new CastBitmap(getResourceById(URL_IMG_TITLE).data, "auto"false, {x:20, y:376}));
  275.                     
  276.                     var hatenaBtn:CastButton = new CastButton({x:20, y:433});
  277.                     hatenaBtn.addChild(new Bitmap(getResourceById(URL_IMG_BTN_HATENA).data));
  278.                     hatenaBtn.onCastMouseUp = function():void{
  279.                         navigateToURL(new URLRequest("http://b.hatena.ne.jp/append?http://wonderfl.net/code/d5de28ad1f65364ee33b964101222be41a7320af"));
  280.                     }
  281.                     hatenaBtn.buttonMode = true;
  282.                     addChild(hatenaBtn);
  283.                     
  284.                     var tweetBtn:CastButton = new CastButton({x:240, y:433});
  285.                     tweetBtn.addChild(new Bitmap(getResourceById(URL_IMG_BTN_TWITTER).data));
  286.                     tweetBtn.onCastMouseUp = function():void{
  287.                         navigateToURL(new URLRequest("http://twitter.com/home/?status=" + escapeMultiByte("#XmasMessage [] http://j.mp/xmaswon")));
  288.                     };
  289.                     tweetBtn.buttonMode = true;
  290.                     addChild(tweetBtn);
  291.                     
  292.                     // キラキラロジック by http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c (sake)
  293.                     canvas = new BitmapData(720 / 4485 / 4false, 0x000000);
  294.                     var bmp:Bitmap = new Bitmap(canvas, PixelSnapping.NEVER, false);
  295.                     bmp.scaleX = bmp.scaleY = 4;
  296.                     bmp.smoothing = true;
  297.                     bmp.blendMode = BlendMode.ADD;
  298.                     addChildAt(bmp,2);
  299.                     mtx = new Matrix();
  300.                     mtx.scale(0.250.25);
  301.                     // tree
  302.                     drawTree(0, -10000100090, GOLD);
  303.                     // タイマーを作る
  304.                     RESET_TIMER.addEventListener(TimerEvent.TIMER, timerHandler);
  305.                     RESET_TIMER.start();
  306.                     // エンターフレーム
  307.                     addEventListener(Event.ENTER_FRAME, loop);
  308.                 },
  309.                 timerHandler
  310.             );
  311.             cmd.execute();
  312.         }
  313.         private function timerHandler(e:TimerEvent = null):void {
  314.             var i:int;
  315.             var arr:Array = [];
  316.             for (i = 0; i < textPixels.pixels.length; i++) {
  317.                 arr[i] = BetweenAS3.serial(
  318.                     BetweenAS3.delay(
  319.                         BetweenAS3.to(textPixels.pixels[i], getRandomPos(), 3, Expo.easeInOut),
  320.                         Math.random()));
  321.             }
  322.             BetweenAS3.serial(
  323.                 BetweenAS3.parallelTweens(arr),
  324.                 BetweenAS3.func(function():void {
  325.                     setTimeout(motionText, 2 * 1000);
  326.                 })
  327.                 ).play();
  328.             //
  329.             index++;
  330.             if (index == data.length - 1)
  331.                 index = 0;
  332.             //
  333.             var cameraTarget:DisplayObject3D = new DisplayObject3D();
  334.             cameraTarget.copyTransform(dmyObjs[index]);
  335.             cameraTarget.moveBackward(250);
  336.             var dis:Number = cameraTarget.distanceTo(DisplayObject3D.ZERO);
  337.             var rot:Number = Math.atan2(cameraTarget.x, cameraTarget.z);
  338.             
  339.             BetweenAS3.parallel(
  340.                 BetweenAS3.delay(
  341.                     BetweenAS3.bezier(this, {
  342.                         cameraYaw: rot,
  343.                         cameraDistance: dis,
  344.                         cameraPitch: cameraTarget.y
  345.                     }, null, getRandomPos(), 10.5, Expo.easeInOut),
  346.                 1.0) ,
  347.                 BetweenAS3.serial(
  348.                     BetweenAS3.to(camera, {
  349.                         fov: 60
  350.                     }, 4, Sine.easeInOut),
  351.                     BetweenAS3.to(camera, {
  352.                         fov: 50
  353.                     }, 8, Sine.easeInOut)
  354.                     )
  355.                 ).play();
  356.         }
  357.         private var preRenderedTests:Array = [];
  358.         private function preRenderText(itemIndex:int):void {
  359.             preRenderedTests[itemIndex] = [];
  360.             var text:TextField = new TextField();
  361.             text.multiline = true;
  362.             text.autoSize = "left";
  363.             text.htmlText = "<font face='Arial' size='24'>WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW</font>";
  364.             trace(data[itemIndex].comment);
  365.             
  366.             var size:int = 24;
  367.             while(text.textWidth * text.textHeight > MAX_PARTICLES){
  368.                 text.htmlText = "<font face='Arial' size='" + size +"'>" + data[itemIndex].comment + "</font>"
  369. //                                +"<br><font face='Arial' size='" + size / 2 + "'>" + String(data[itemIndex].name).toUpperCase() + "</font>";
  370.                 size--;
  371.             }
  372.             
  373.             var cap:BitmapData = new BitmapData(text.textWidth + 10, text.textHeight, true, 0xFFFFFFFF);
  374.             cap.lock();
  375.             cap.draw(text);
  376.             // particle motion
  377.             var cnt:int = 0;
  378.             for (var i:int = 0; i < text.textWidth + 10; i++) {
  379.                 for (var j:int = 0; j < text.textHeight; j++) {
  380.                     if (cap.getPixel(i, j) == 0xFFFFFF)
  381.                         continue;
  382.                     if(preRenderedTests[itemIndex].length >= MAX_PARTICLES) break
  383.                     preRenderedTests[itemIndex].push({x: i, y: j, textWidth: text.textWidth, textHeight: text.textHeight});
  384.                 }
  385.             }
  386.             cap.unlock();
  387.             cap.dispose();
  388.         }
  389.         /**
  390.          * テキストをBitmapData化してトゥイーンとして作成 
  391.          * @param itemIndex
  392.          */        
  393.         private function createText(itemIndex:int):void {
  394.             var t:DisplayObject3D = dmyObjs[itemIndex];
  395.             // particle motion
  396.             var cnt:int = 0;
  397.             var arr:Array = [];
  398.             for (var i:int = 0; i < preRenderedTests[itemIndex].length; i++) {
  399.                 var pix:Object = preRenderedTests[itemIndex][i];
  400.                 var p:Pixel3D = textPixels.pixels[i];
  401.                 var vec:DisplayObject3D = new DisplayObject3D();
  402.                 vec.x = (pix.x - pix.textWidth / 2) * PIXCEL_MARGIN;
  403.                 vec.y = (pix.textHeight / 2 - pix.y) * PIXCEL_MARGIN;
  404.                 vec.z = 0;
  405.                 vec.transform.calculateMultiply(t.transform, vec.transform);
  406.                 arr[i] = BetweenAS3.bezier(p, {
  407.                         x: vec.x,
  408.                         y: vec.y,
  409.                         z: vec.z
  410.                     }, null, getRandomPos(), 1.2 + Math.random() * 0.25 + i * 0.002, Expo.easeOut);
  411.             }
  412.             tweens.push(arr);
  413.         }
  414.         private function motionText():void {
  415.             var tw:ITween = BetweenAS3.parallelTweens(tweens[index]);
  416.             // トゥイーンのデュレーションを調整
  417.             tw = BetweenAS3.scale(tw, 3.5 / tw.duration);
  418.             tw.play();
  419.         }
  420.         /**
  421.          * エンターフレームイベント 
  422.          */        
  423.         private function loop(e:Event = null):void {
  424.             // カメラ
  425.             camera.x = cameraDistance * Math.sin(cameraYaw);
  426.             camera.y = cameraPitch;
  427.             camera.z = cameraDistance * Math.cos(cameraYaw);
  428.             
  429.             // レンダリング
  430.             renderer.renderScene(scene, camera, viewport);
  431.             
  432.             // キラキラ
  433.             canvas.fillRect(canvas.rect, 0x000000);
  434.             canvas.draw(viewport, mtx);
  435.         }
  436.         private function getRandomPos():Object {
  437.             return {
  438.                     x: MAX_RADIUS * (Math.random() - 0.5),
  439.                     y: MAX_RADIUS * (Math.random() - 0.5),
  440.                     z: MAX_RADIUS * (Math.random() - 0.5)
  441.                 };
  442.         }
  443.         /**
  444.          * 木を作る再帰関数
  445.          * http://wonderfl.net/code/00cbe3ecbf0db2e865bc410a8ea54677c19ba4c6 
  446.          * @param x
  447.          * @param y
  448.          * @param z
  449.          * @param length
  450.          * @param angle
  451.          * @param cf
  452.          * 
  453.          */
  454.         private function drawTree(x:Number, y:Number, z:Number, length:Number, angle:Number, cf:int):void {
  455.             level += 1;
  456.             var destx:Number = x + length * Math.cos(angle * (Math.PI / 180));
  457.             var desty:Number = y + length * Math.sin(angle * (Math.PI / 180));
  458.             var destz:Number = z + length * (Math.random() - 0.5) * 2;
  459.             if (Math.random() < 0.5)
  460.                 cf = COLORS[COLORS.length * Math.random() | 0];
  461.             var max:int = 10 - level / 1.5;
  462.             for (var i:int = 0; i < max; i++) {
  463.                 treePixels.addPixel3D(new Pixel3D(cf,
  464.                     destx * i / max + x * (max - i) / max,
  465.                     desty * i / max + y * (max - i) / max,
  466.                     destz * i / max + z * (max - i) / max
  467.                     ));
  468.             }
  469.             if (level < 6) {
  470.                 drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
  471.                 drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
  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.             }
  475.             level -= 1;
  476.         }
  477.         
  478.         /**
  479.          * 1行でArrayをシャッフルする by nemu90kWw
  480.          * http://wonderfl.net/code/8cfa39c9e91a268791142fe605c010dc30338588 
  481.          */        
  482.         public function shuffle(array:Array):Array{
  483.             return array.sort(function():int{return int(Math.random()*3)-1});
  484.         }
  485.         
  486.         /**
  487.          * @see http://takumakei.blogspot.com/2009/05/actionscriptrubystringscan.html
  488.          */ 
  489.         //package com.blogspot.takumakei.utils
  490.         //{
  491.         //public
  492.         public function scan(str:String, re:RegExp):Array
  493.         {
  494.             if(!re.global){
  495.                 var flags:String = 'g';
  496.                 
  497.                 if(re.dotall)
  498.                     flags += 's';
  499.                 if(re.multiline)
  500.                     flags += 'm';
  501.                 if(re.ignoreCase)
  502.                     flags += 'i';
  503.                 if(re.extended)
  504.                     flags += 'x';
  505.                 re = new RegExp(re.source, flags);                    
  506.             }
  507.             var r:Array = [];
  508.             var m:Array = re.exec(str);
  509.             while(null != m){
  510.                 if(1 == m.length)
  511.                     r.push(m[0]);
  512.                 else
  513.                     r.push(m.slice(1, m.length));
  514.                 m = re.exec(str);
  515.             }
  516.             return r;
  517.         }
  518.         //}
  519.     }
  520. }
  521. import flash.display.*;
  522. class ProgressBar extends Sprite {
  523.     private var edge:Sprite = new Sprite;
  524.     private var cont:Sprite = new Sprite;
  525.     
  526.     private var _value:Number = 0;
  527.     
  528.     public function set value(v:Number):void {
  529.         _value = v;
  530.         cont.scaleX = _value;
  531.     }
  532.     
  533.     public function get value():Number {
  534.         return _value;
  535.     }
  536.     
  537.     public function ProgressBar() {
  538.         edge.graphics.lineStyle(1, 0xFFFFFF);
  539.         edge.graphics.drawRect(0.50.510010);
  540.         
  541.         cont.graphics.beginFill(0x555555);
  542.         cont.graphics.drawRect(0010010);
  543.         
  544.         addChild(cont);
  545.         addChild(edge);
  546.         
  547.         value = 0;
  548.     }
  549. }
flash swf thumbnail play
出題者からのコメント
夜空の変化を楽しむ自分と、メッセージを待つ自分と、思わずうっとりしてしまいました。クリスマスそのものの演出で、静寂も素敵ですが、音楽があるともっと、情緒的になると感じました。 「はてな」や「Twitter」の連携はもちろんのこと、非常に可能性を感じました。このたびは、おめでとうございます。
Comments from Sponsor
The change of night sky and the message are adorable. This performance of X'MAS Flash brought my emotion with silence, but it would be even better if there is some additional music. The cooperation between "HATENA" and "Twitter" made us think of possibility. Congratulations!

Bishopnanlow

  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. }
flash swf thumbnail play
出題者からのコメント
このたびは、おめでとうございます。
ツリーにストーリーがあり、見ていてできあがっていく様の待ちどうしさもあり、素敵でした。色の選定や演出しかたも、好きです。色々な展開が楽しめそうです。
Comments from Sponsor
Congratulations!
This tree made me imagine some stories. It was fantastic time while waiting for each steps through the whole picture. I love the colors and direction. These expressions may be applied to many other themes.

ad