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

-
Produce illumination pattern with Christmas Colors.

- CHECKMATEは世界初のFlash詰め将棋イベントです。出題される問題にFORKする(プログラムを書き換える)ことで、回答します。
下記、スポンサーからの問題にForkボタンをクリックして、プログラムを改造してみましょう。さぁ、今こそあなたの知恵と技術を見せる時。LET's TRY 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!
※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!
wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)
Checkmate vol4 Massmedian forked from: Checkmate vol4 Massmedian
- //セキュリティサンドボックス侵害で詰んだ
- //これが本当のチェックメイト!
- package {
- import flash.display.*;
- import flash.events.*;
- import flash.net.*;
- import flash.geom.*;
- import flash.system.LoaderContext;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
- [SWF(backgroundColor=0x00,frameRate=60)]
- public class FlashTest extends Sprite {
- /*
- * [Checkmate Vol4 by MASSMEDIAN]
- * Please produce the illumination freely with a color palette.
- *
- * usage of Palette class
- * A single value is used.
- * var white:uint = Palette.WHITE;
- * var green:uint = Palette.GREEN;
- * var red:uint = Palette.RED;
- * var gold:uint = Palette.GOLD;
- * var silver:uint = Palette.SILVER;
- * var black:uint = Palette.BLACK;
- * All the values are used.
- * var colors:Array = Palette.getColors();
- */
- private function init( e:Event = null ):void {
- resize();
- //drawXmasTree();
- new IconGetter(function(b:BitmapData):void {
- _image = b;
- createSnow();
- },function(e:SecurityError):void {
- var tf:TextField = new TextField();
- tf.textColor = 0xFFFFFF;
- tf.autoSize = TextFieldAutoSize.LEFT;
- var f:TextFormat = new TextFormat();
- f.size = 20
- tf.defaultTextFormat = f;
- tf.text = e.toString().substring(0, 10);
- addChild(tf);
- //var b:BitmapData = new BitmapData(tf.height, tf.width);
- //b.draw(tf);
- //_image = b;
- //createSnow();
- });
- //new TextField().tetC
- //var tf:TextField = new TextField();
- //tf.autoSize = TextFieldAutoSize.LEFT;
- //tf.defaultTextFormat = new TextFormat(null, 20);
- //tf.defaultTextFormat.size
- //tf.text = e.toString();
- //showPaletteMap();
- }
- private var _image:BitmapData;
- public var rect:Rectangle= new Rectangle();
- public var center:Point = new Point();
- private const SLOW_LENGTH:int = 1000;
- private var _snow:Vector.<Snow> = new Vector.<Snow>();
- private var _twincles:BitmapData;
- private var _canvas:BitmapData;
- private var _matrix:Matrix;
- private var _ctf:ColorTransform = new ColorTransform( 0.75, 0.8, 0.8, 0.95 );
- private function createSnow():void {
- // The value used for generation is prepared.
- const RADIAN:Number = Math.PI*2;
- const COLORS:Array = Palette.getColors();
- // The canvas to draw in illumination.
- var snow:Snow, speed:Number, angle:Number;
- for (var i:int = 0; i < _image.height; i++ )
- {
- for (var j:int = 0; j < _image.width; j++ )
- {
- //for ( var i :int = 0; i < SLOW_LENGTH; ++i ) {
- snow = new Snow();
- //snow.x = (Math.random()-0.5)*50 + center.x;
- //snow.y = Math.random()*rect.height;
- //snow.vx = (Math.random()-0.5) * 4;
- //snow.vy = Math.random()*-2;
- //snow.color = COLORS[int(COLORS.length*Math.random())];
- snow.x = i * 202 / _image.width +130;
- snow.y = j * 202 / _image.height+130;
- snow.color = _image.getPixel(i,j);
- _snow.push( snow );
- //}
- }
- }
- // The canvas to draw in illumination.
- _canvas = new BitmapData( rect.height, rect.height, true, 0 );
- var cbm :Bitmap = addChild( new Bitmap( _canvas ) ) as Bitmap;
- cbm.smoothing = true;
- // The canvas to draw in twincles.
- _twincles = new BitmapData( rect.width/4>>0, rect.height/4>>0, true, 0 );
- var tbm:Bitmap = addChild( new Bitmap( _twincles ) ) as Bitmap;
- tbm.scaleX = tbm.scaleY = 4;
- tbm.smoothing = true;
- tbm.blendMode = BlendMode.ADD;
- // Matrix to draw by size of 1/4
- _matrix = new Matrix(0.25, 0, 0, 0.25);
- addEventListener( Event.ENTER_FRAME, updateSnow );
- }
- private function updateSnow(e:Event):void {
- _canvas.lock();
- for each( var snow:Snow in _snow ) {
- // The Brownian motion is added.
- snow.vx += (Math.random()-0.5)*0.01;
- snow.vy += (Math.random()-0.5)*0.01;
- // Gravity is added.
- //snow.vy += 0.015;
- // The wind drag is added.
- snow.vx *= 0.987;
- snow.vy *= 0.987;
- // The speed is added to the position.
- snow.x += snow.vx;
- snow.y += snow.vy;
- // draw to canvas in position.
- _canvas.setPixel32( snow.x, snow.y, snow.color | 0xFF<<24 );
- // It resets it when going out of the area.
- if( snow.x < rect.x -50 || snow.y < rect.y -50 || snow.x > rect.width +50 || snow.y > rect.height + 50 ) {
- snow.x = center.y + (Math.random() -0.5) * 10;
- snow.y = Math.random() *-30;
- snow.vx = (Math.random() -0.5) * 3;
- snow.vy = Math.random() *-3;
- }
- }
- // ColorTransform(effect that dose blackout) is made to adjust.
- _canvas.colorTransform( _canvas.rect, _ctf );
- _canvas.unlock();
- // draw to canvas in twincles by using Matrix.
- _twincles.draw( _canvas, _matrix );
- }
- private function resize( e:Event = null ):void {
- rect.width = stage.stageWidth;
- rect.height= stage.stageHeight;
- center.x = rect.width /2>>0;
- center.y = rect.height /2>>0;
- }
- private function drawXmasTree():void {
- var loader :Loader = new Loader();
- addChild( loader );
- loader.load( new URLRequest("http://swf-dev.wonderfl.net/static/assets/checkmate04/tree.jpg"),new LoaderContext(true));
- }
- private function showPaletteMap():void {
- var colors:Array = Palette.getColors();
- var palette:Sprite = addChild( new ColorMap( colors ) ) as Sprite;
- palette.x = ( rect.width - palette.width ) /2 >>0;
- palette.y = ( rect.height- palette.height ) /2 >>0;
- }
- public function FlashTest() {
- if( stage ) init();
- else addEventListener( Event.ADDED_TO_STAGE, init );
- }
- }
- }
- /* for Checkmate */
- class Palette {
- public static const WHITE:uint = 0xF0F0F0;
- public static const GREEN:uint = 0x008800;
- public static const RED:uint = 0xCC0000;
- public static const GOLD:uint = 0xFFCC66;
- public static const SILVER:uint = 0xCCCCCC;
- public static const BLACK:uint = 0x101010;
- public static const COLORS:/*uint*/Array = [ WHITE, GREEN, RED, GOLD, SILVER, BLACK ];
- public static function getColors():Array { return COLORS.slice(); }
- }
- /* for Example. */
- class Snow {
- public var x:Number = 0;
- public var y:Number = 0;
- public var vx:Number = 0;
- public var vy:Number = 0;
- public var color:uint = 0x00;
- }
- /* for debug. */
- import flash.display.*;
- class ColorMap extends Sprite {
- public function ColorMap(colors:Array) {
- var l:int = colors.length;
- var rect:Sprite;
- for( var i:int=0; i<l; ++i ) {
- addChild( rect = new ColorRect( colors[ i ] ) );
- rect.x =i * ColorRect.WIDTH;
- rect.y =0;
- }
- }
- }
- /* for debug. */
- class ColorRect extends Sprite {
- public static const WIDTH:int = 40;
- public static const HEIGHT:int = 40;
- public function ColorRect( color:uint ) {
- super();
- graphics.beginFill( color, 1 );
- graphics.drawRect( 0, 0, WIDTH, HEIGHT );
- graphics.endFill();
- }
- }
- //package
- //{
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Loader;
- //import flash.display.Sprite;
- //import flash.events.Event;
- //public
- class IconGetter
- {
- private var l:Loader;
- private var _bmpf:Function; //<BitmapData,void>
- private var _errf:Function; //<SecurityError,void>
- public function IconGetter(bmpGetter:Function,errGetter:Function):void
- {
- _bmpf = bmpGetter;
- _errf = errGetter;
- var icon:TwitterIcon = new TwitterIcon(onIconGet);
- }
- private function onIconGet(xs:Array):void {
- l = new Loader();
- l.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
- l.load(xs[int(xs.length*Math.random())])
- }
- private function onComplete(e:Event):void
- {
- var bd:BitmapData = new BitmapData(l.width, l.height);
- try{
- bd.draw(l);
- _bmpf(bd);
- }catch (e:SecurityError) {
- _errf(e);
- }
- }
- }
- //}
- import flash.events.Event;
- import flash.net.URLLoader;
- import flash.net.URLRequest;
- //import flash.net.
- class TwitterIcon
- {
- private var _xs:Array;
- public function TwitterIcon(arraySetter:Function)
- {
- var loadTexts:Function = function (rpp:int, arraySetter:Function):void {
- var textLoader:URLLoader = new URLLoader(new URLRequest("http://search.twitter.com/search.atom?q=%23illumination&rpp=" + rpp));
- textLoader.addEventListener(Event.COMPLETE, function(e:Event):void {
- default xml namespace = new Namespace("http://www.w3.org/2005/Atom");
- var htmlText:XML = XML(textLoader.data);
- //var title:XMLList = htmlText.entry.title;
- var imgs:XMLList = htmlText.entry.link.(@type=="image/png").@href;
- var xs:Array = [];
- for each(var i:XML in imgs)
- {
- xs.push(new URLRequest(i.toString()));
- //xs.push.apply(null,scan(c.toString(),/\[(.+)\]/));
- }
- if (xs.length >= 1)
- {
- //_texts = xs;
- arraySetter(xs);
- }
- });
- }
- loadTexts(10,arraySetter);
- }
- }
- /**
- * @see http://takumakei.blogspot.com/2009/05/actionscriptrubystringscan.html
- */
- //package com.blogspot.takumakei.utils
- //{
- //public
- function scan(str:String, re:RegExp):Array
- {
- if(!re.global){
- var flags:String = 'g';
- if(re.dotall)
- flags += 's';
- if(re.multiline)
- flags += 'm';
- if(re.ignoreCase)
- flags += 'i';
- if(re.extended)
- flags += 'x';
- re = new RegExp(re.source, flags);
- }
- var r:Array = [];
- var m:Array = re.exec(str);
- while(null != m){
- if(1 == m.length)
- r.push(m[0]);
- else
- r.push(m.slice(1, m.length));
- m = re.exec(str);
- }
- return r;
- }
- //}
Checkmate vol4 Massmedian forked from: Checkmate vol4 Massmedian
- // forked from checkmate's Checkmate vol4 Massmedian
- package
- {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.BlendMode;
- import flash.filters.BlurFilter;
- import flash.display.PixelSnapping;
- import flash.events.MouseEvent;
- import flash.events.Event;
- import flash.geom.Matrix;
- import flash.geom.ColorTransform;
- import flash.geom.Rectangle;
- import flash.geom.Point;
- import org.papervision3d.core.effects.utils.BitmapClearMode;
- import org.papervision3d.core.geom.Pixels;
- import org.papervision3d.view.BasicView;
- import org.papervision3d.view.layer.BitmapEffectLayer;
- [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]
- public class Main extends BasicView{
- private const RECT:Rectangle = new Rectangle(0, 0, 465, 465);
- private const ZEROS:Point = new Point(0, 0);
- private var _pixels:Pixels;
- private var _canvas:BitmapData;
- private var _head:Particle;
- private var _blurFilter:BlurFilter;
- private var _colorTransForm:ColorTransform;
- private var _mode:Number;
- private var mtx:Matrix;
- public function Main()
- {
- super(0, 0, true, true);
- var layer:BitmapEffectLayer=new BitmapEffectLayer(viewport, 465, 465, true, 0, BitmapClearMode.CLEAR_PRE, true);
- layer.clearBeforeRender=true;
- viewport.containerSprite.addLayer(layer);
- camera.z=-750;
- camera.y=-100;
- _pixels=new Pixels(layer);
- scene.addChild(_pixels);
- var p:Particle = _head = new Particle();
- for (var i:uint = 0; i < 6800; ++i){
- p = p.next = new Particle();
- }
- _canvas=new BitmapData(465 / 4, 465 / 4, false, 0x000000);
- var bmp:Bitmap=new Bitmap(_canvas, PixelSnapping.NEVER, true);
- bmp.scaleX=bmp.scaleY=4;
- bmp.smoothing=true;
- bmp.blendMode=BlendMode.ADD;
- addChild(bmp);
- _blurFilter = new BlurFilter(1, 1, 1);
- _colorTransForm = new ColorTransform(0.95, 0.95, 0.95);
- mtx = new Matrix(0.25, 0, 0, 0.25);
- startRendering();
- addEventListener(Event.ENTER_FRAME, onFrame);
- stage.addEventListener(MouseEvent.MOUSE_MOVE, _move);
- _iniset();
- }
- private function _iniset():void{
- var p:Particle = _head;
- var i:Number = 1;
- var z:Number = 180;
- do {
- p.angle = i + i * Math.random();
- p.radius = i / 11;
- if(p.radius > z && i < 4500){
- p.radius = p.radius - 100 * Math.ceil(i/3300);
- }
- if(i >= 4500){
- p.radius = 60;
- }
- p.yy= -(i / 11);
- if(i >= 5800){
- p.yy= -(5800 / 11);
- p.radius = 320 * Math.random() + 80;
- }
- p.xx=(p.radius * Math.cos(p.angle * Math.PI / 180));
- p.zz=(p.radius * Math.sin(p.angle * Math.PI / 180));
- if(i >= 5800){
- p.setPixel3Dsnow();
- }else{
- p.setPixel3D();
- }
- _pixels.addPixel3D(p.pix3d);
- _pixels.y = 300;
- i ++;
- } while (p = p.next);
- }
- private function _move(e:MouseEvent = null):void{
- camera.z = -(mouseX) - 430;
- camera.y = mouseY - 230;
- }
- private function onFrame(e:Event):void
- {
- _canvas.lock();
- _canvas.fillRect(_canvas.rect, 0x000000);
- _canvas.draw(viewport, mtx);
- _canvas.applyFilter(_canvas, RECT, ZEROS, _blurFilter);
- _canvas.colorTransform(RECT, _colorTransForm);
- _canvas.draw(_canvas, null, null, BlendMode.ADD);
- _canvas.unlock();
- _pixels.rotationY+=0.5;
- }
- }
- }
- internal class Particle {
- import org.papervision3d.core.geom.renderables.Pixel3D;
- public var radius:Number;
- public var angle:Number;
- public var xx:Number = 0;
- public var yy:Number = 0;
- public var zz:Number = 0;
- public var pix3d:Pixel3D;
- public var next:Particle;
- public function setPixel3D():void
- {
- pix3d=new Pixel3D((0xee << 24 | 0xff * Math.random() << 16 | 0xff * Math.random() << 8 | 0x99 * Math.random() ), xx, yy, zz);
- }
- public function setPixel3Dsnow():void
- {
- pix3d=new Pixel3D((0xff * Math.random() << 24 | 0xff << 16 | 0xff << 8 | 0xff ), xx, yy, zz);
- }
- }
- /**
- * ステージクリックで明かりがついたり消えたりします。
- *
- *
- * -参考-
- *
- * キラキラPixel3D!
- * http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c
- */
- package
- {
- import flash.display.BlendMode;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.filters.BitmapFilterQuality;
- import flash.filters.BlurFilter;
- import flash.geom.ColorTransform;
- import gs.TweenMax;
- import net.hires.debug.Stats;
- import org.papervision3d.core.effects.BitmapColorEffect;
- import org.papervision3d.core.effects.BitmapLayerEffect;
- import org.papervision3d.core.effects.utils.BitmapClearMode;
- import org.papervision3d.core.effects.utils.BitmapDrawCommand;
- import org.papervision3d.core.geom.Pixels;
- import org.papervision3d.core.geom.renderables.Pixel3D;
- import org.papervision3d.lights.PointLight3D;
- import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
- import org.papervision3d.objects.DisplayObject3D;
- import org.papervision3d.objects.primitives.Sphere;
- import org.papervision3d.view.BasicView;
- import org.papervision3d.view.layer.BitmapEffectLayer;
- [SWF(backgroundColor = 0x000000, width = "465", height = "465", frameRate = 60)]
- public class Main extends BasicView
- {
- private const STAR_COLOR:uint = 0xFFC460
- private const STAR_RADIUS:uint = 50;
- private const LEAF_COLOR:uint = 0x274905;
- private const LEAF_RADIUS:uint = 300;
- private const LEAF_HEIGHT:Number = 700;
- private const TRUNK_COLOR:uint = 0x822e01;
- private const TRUNK_RADIUS:uint = 50;
- private const TRUNK_HEIGHT:Number = 120;
- private const PLANT_COLOR:uint = 0x4f1700;
- private const PLANT_RADIUS:uint = 90;
- private const PLANT_HEIGHT:Number = 40;
- private const SPHERE_COUNT:uint = 30;
- private const SPHERE_COLOR_LIST:Array = [0xFC0A0A, 0xFC0A0A, 0x3E33FF,0x666666];
- private const LACE_COUNT:uint = 1000;
- private const LACE_COLOR:uint = 0xCCFFF4AA;
- private const SNOW_COUNT:uint = 500;
- private const SNOW_COLOR:uint = 0x99FFFFFF;
- private const SNOW_AREA_R:Number = 500;
- private var _sphereList:Vector.<Sphere>=new Vector.<Sphere>();
- private var _my:Number = 0;
- private var _isLight:Boolean = false;
- private var _root:DisplayObject3D, _tree:Tree, _bfx:BitmapEffectLayer, _snow:Snow;
- public function Main():void
- {
- super(465, 465, false);
- Wonderfl.capture_delay(15);
- if (!stage)
- addEventListener(Event.ADDED_TO_STAGE, _init);
- else
- _init();
- }
- private function _init(e:Event = null):void
- {
- removeEventListener(Event.ADDED_TO_STAGE, _init);
- _root = scene.addChild(new DisplayObject3D());
- var light:PointLight3D = new PointLight3D(false);
- light.z = -1000;
- light.x = -1000;
- light.y = 1000;
- var objList:Array = [];
- _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);
- _root.addChild(_tree);
- objList.push(_tree)
- _tree.y = -400;
- var sphBaseRad:Number = (2 * Math.PI) / SPHERE_COUNT;
- for (var i:int = 0; i < SPHERE_COUNT; i++)
- {
- var sphMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0x666666, SPHERE_COLOR_LIST[Math.floor((SPHERE_COLOR_LIST.length - 0.01) * Math.random())]);
- objList.push(_createSphere(sphMaterial, sphBaseRad * i));
- }
- _createBitmapEffectLayer(objList);
- var pixels:Pixels = new Pixels(_bfx);
- _root.addChild(pixels);
- _createLacePixels(pixels, LACE_COUNT);
- //addChild(new Stats());
- _start();
- graphics.beginFill(0);
- graphics.drawRect(0, 0, 465, 465);
- graphics.endFill();
- }
- private function _start():void
- {
- _tree.start(0.3, 0.045);
- _sphereStart(2.6, 0.075);
- TweenMax.delayedCall(5.60, _openingComplete);
- _snow = new Snow(SNOW_COUNT, SNOW_COLOR, SNOW_AREA_R);
- addChildAt(_snow, 1);
- startRendering();
- }
- private function _openingComplete():void
- {
- stage.addEventListener(MouseEvent.CLICK, _onClickHandler);
- _onClickHandler();
- }
- private function _createBitmapEffectLayer(list:Array):void
- {
- _bfx = new BitmapEffectLayer(viewport, 465, 465, true, 0x00FFFFFF, BitmapClearMode.CLEAR_PRE, false, false);
- _bfx.addEffect(new BitmapColorEffect(1.0, 1.0, 1.0, 0.9));
- _bfx.addEffect(new BitmapLayerEffect(new BlurFilter(10, 10, BitmapFilterQuality.LOW), false));
- _bfx.drawCommand = new BitmapDrawCommand(null, new ColorTransform(1.0, 1.0, 1.0, 1.0, -32, -16, -32, -16), BlendMode.ADD);
- for (var i:int = 0; i < list.length; i++)
- {
- _bfx.addDisplayObject3D(list[i]);
- }
- }
- private function _createSphere(mat:FlatShadeMaterial, rad:Number = 0):Sphere
- {
- var result:Sphere = new Sphere(mat, 15, 3, 4);
- var pt:Pt = _treeOutLinePt(rad, 220, 80);
- result.x = pt.x;
- result.y = pt.y;
- result.z = pt.z;
- result.rotationY = 360 * Math.random();
- _sphereList.push(result);
- return result;
- }
- private function _createLacePixels(pixels:Pixels, num:uint):void
- {
- for (var i:int = 0; i < num; ++i)
- {
- var pt:Pt = _treeOutLinePt(Math.PI * 2 * Math.random(), 80, 50 * Math.sin(Math.PI * 0.5 * Math.random())-20);
- var px:Pixel3D = new Pixel3D(LACE_COLOR, pt.x, pt.y, pt.z);
- pixels.addPixel3D(px);
- }
- }
- private function _treeOutLinePt(rad:Number, top:Number = 0, bottom:Number = 0):Pt
- {
- var result:Pt = new Pt();
- var posY:Number = (LEAF_HEIGHT - top) * ( _tree.getOutLine(Math.random() * LEAF_HEIGHT) / LEAF_RADIUS) + bottom;
- var r:Number = _tree.getOutLine(posY);
- result.x = r * Math.cos(rad);
- result.y = posY + _tree.leafBaseY + _tree.y;
- result.z = r * Math.sin(rad);
- return result;
- }
- private function _sphereStart(delayTime:Number = 0, speed:Number = 0.04):void
- {
- for (var i:int = 0; i < _sphereList.length; i++)
- {
- TweenMax.delayedCall(i * speed + delayTime, _addChildSphere, [_sphereList[i]]);
- }
- _sphereList = null;
- }
- private function _addChildSphere(sphere:Sphere):void
- {
- _root.addChild(sphere);
- }
- override protected function onRenderTick(event:Event = null):void
- {
- super.onRenderTick(event);
- _root.rotationY -= (stage.mouseX - stage.stageWidth * 0.5) * 0.008;
- _my += ((stage.mouseY - stage.stageHeight * 0.5) * 2.0 - _my) * 0.08;
- camera.y = _my;
- camera.zoom = 40 - _my * 0.025
- _snow.update(_root.rotationY,camera.y,camera.zoom);
- }
- private function _onClickHandler(e:MouseEvent = null):void
- {
- _isLight = !_isLight;
- if (_isLight)
- {
- viewport.containerSprite.addLayer(_bfx);
- _snow.show();
- }else
- {
- viewport.containerSprite.removeLayer(_bfx);
- _snow.hide();
- }
- }
- }
- }
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.BlendMode;
- import flash.display.PixelSnapping;
- import flash.geom.Matrix;
- import gs.TweenMax;
- import org.papervision3d.core.effects.utils.BitmapClearMode;
- import org.papervision3d.core.geom.Lines3D;
- import org.papervision3d.core.geom.Pixels;
- import org.papervision3d.core.geom.renderables.Line3D;
- import org.papervision3d.core.geom.renderables.Vertex3D;
- import org.papervision3d.core.geom.renderables.Pixel3D;
- import org.papervision3d.core.proto.CameraObject3D;
- import org.papervision3d.materials.special.LineMaterial;
- import org.papervision3d.objects.DisplayObject3D;
- import org.papervision3d.view.BasicView;
- import org.papervision3d.view.layer.BitmapEffectLayer;
- class Tree extends Lines3D
- {
- private const LINE_SIZE:uint = 3;
- private const MARGIN:Number = 5;
- private var _rad:Number = 0;
- private var _h:Number = 0;
- private var _list:Vector.<Line3D>=new Vector.<Line3D>();
- 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;
- 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)
- {
- _init(starColor, starRadius, leafColor, leafRadius, leafHeight, trunkColor, trunkRadius, trunkHeight, plantColor, plantRadius, plantHeight);
- }
- 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
- {
- _v3d = new Vertex3D(_trunkRadius * Math.cos(_rad), _trunkRadius * Math.sin(_rad), _h);
- _interval_rad = 110 / 180 * Math.PI;
- _starMaterial = new LineMaterial(starColor, 1);
- _starRadius = starRadius;
- _leafMaterial = new LineMaterial(leafColor, 1);
- _leafRadius = leafRadius;
- _trunkMaterial = new LineMaterial(trunkColor, 1);
- _trunkRadius = trunkRadius;
- _plantMaterial = new LineMaterial(plantColor, 1);
- _plantRadius = plantRadius;
- _createPlant(plantHeight);
- _createTrunk(trunkHeight);
- _createLeaf(leafHeight);
- _createStar();
- }
- private function _createTrunk(height:Number):void
- {
- var margin:Number = MARGIN * 1.2;
- var num:uint = Math.floor(height / margin);
- for (var i:int = 0; i < num; i++)
- {
- _h += margin;
- var newV3d:Vertex3D = _createV3d(_trunkRadius, _h);
- var line:Line3D = new Line3D(this, _trunkMaterial, LINE_SIZE, _v3d, newV3d);
- _list.push(line);
- _v3d = newV3d;
- }
- _h -= MARGIN * 2
- }
- private function _createLeaf(height:Number):void
- {
- var margin:Number=MARGIN*2.0
- var num:uint = Math.floor(height / margin);
- _leafBaseY = _h;
- for (var i:int = 0; i < num; i++)
- {
- _h += margin;
- var newV3d:Vertex3D = _createV3d(_leafCurve(i,num), _h);
- var line:Line3D = new Line3D(this, _leafMaterial, LINE_SIZE, _v3d, newV3d);
- _list.push(line);
- _v3d = newV3d;
- }
- _leafHeight = _h - _leafBaseY;
- _h -= MARGIN*5
- }
- private function _createStar():void
- {
- _createStarV3d(0, _h);
- _createStarV3d(3, _h);
- _createStarV3d(1, _h);
- _createStarV3d(4, _h);
- _createStarV3d(2, _h);
- _createStarV3d(0, _h);
- }
- private function _createPlant(height:Number):void
- {
- var margin:Number = MARGIN;
- var num:uint = uint(height / margin);
- var r:Number = _plantRadius;
- for (var i:int = 0; i < num; i+=4)
- {
- for (var j:int = 0; j < 4; j++)
- {
- _createPlantV3d(j, _h, r);
- _h += margin
- }
- r += 2;
- }
- r *= 1.1;
- for (var k:int = 0; k < 4; k++)
- {
- _createPlantV3d(k, _h, r);
- _h += margin
- }
- _createPlantV3d(0, _h, 0);
- _h -= MARGIN*4
- }
- private function _createV3d(r:Number, h:Number):Vertex3D
- {
- _rad += _interval_rad;
- return new Vertex3D(r * Math.cos(_rad), h, r * Math.sin(_rad));
- }
- private function _leafCurve(i:Number,max:Number):Number
- {
- var a:Number = 0.06;
- var b:Number=0.1
- return _leafRadius * (1-Math.sin(i / max * Math.PI*0.5))
- }
- private function _createStarV3d(i:uint, baseY:Number):void
- {
- var baseRad:Number = 72 / 180 * Math.PI;
- var newV3d:Vertex3D = new Vertex3D(_starRadius * Math.cos(baseRad * i), _starRadius * Math.sin(baseRad * i)+baseY, 0);
- var line:Line3D = new Line3D(this, _starMaterial, LINE_SIZE, _v3d, newV3d);
- _list.push(line);
- _v3d = newV3d;
- }
- private function _createPlantV3d(i:uint, h:Number, r:Number):void
- {
- var baseRad:Number = Math.PI *0.5;
- var newV3d:Vertex3D = new Vertex3D(r * Math.cos(baseRad * i), h, r * Math.sin(baseRad * i));
- var line:Line3D = new Line3D(this, _plantMaterial, LINE_SIZE, _v3d, newV3d);
- _list.push(line);
- _v3d = newV3d;
- }
- public function getOutLine(y:Number):Number
- {
- return _leafCurve(y, _leafHeight);
- }
- public function start(delayTime:Number=0, speed:Number=0.04):void
- {
- for (var i:int = 0; i < _list.length; i++)
- {
- TweenMax.delayedCall(i * speed + delayTime, _addLine, [_list[i]]);
- }
- _list = null;
- }
- private function _addLine(line3D:Line3D):void
- {
- addLine(line3D)
- }
- public function get leafHeight():Number { return _leafHeight };
- public function get leafBaseY():Number { return _leafBaseY };
- }
- class Snow extends BasicView
- {
- private var _list:Vector.<Pixel3D>=new Vector.<Pixel3D>();
- private var _root:DisplayObject3D, _bmp:Bitmap, _mtx:Matrix;
- public function Snow(count:uint, color:uint, areaR:Number)
- {
- super(465, 465, false);
- _init(count, color, areaR);
- }
- private function _init(count:uint, color:uint, areaR:Number):void
- {
- _root = scene.addChild(new DisplayObject3D());
- var bfx:BitmapEffectLayer = new BitmapEffectLayer(viewport, 465, 465, true, 0x00FFFFFF, BitmapClearMode.CLEAR_PRE, false, false);
- bfx.clearBeforeRender=true;
- viewport.containerSprite.addLayer(bfx);
- var pixels:Pixels = new Pixels(bfx);
- var rad:Number, r:Number;
- for (var i:int = 0; i < count; ++i)
- {
- rad = 2 * Math.PI * Math.random();
- r = areaR * Math.random();
- var px:Pixel3D = new Pixel3D(color, r * Math.cos(rad), Math.random() * 1000 - 400, r * Math.sin(rad));
- pixels.addPixel3D(px);
- _list.push(px)
- }
- _root.addChild(pixels);
- _bmp = new Bitmap(new BitmapData(465 / 4, 465 / 4, false, 0x00000000), PixelSnapping.NEVER, true);
- _bmp.scaleX = _bmp.scaleY = 4;
- _bmp.smoothing = true;
- _bmp.blendMode=BlendMode.ADD;
- _mtx = new Matrix(0.25, 0, 0, 0.25);
- }
- public function update(rotationY:Number, cameraY:Number, cameraZoom:Number):void
- {
- super.onRenderTick();
- var px:Pixel3D;
- for (var i:int = 0; i < _list.length; i++)
- {
- px = _list[i] as Pixel3D;
- px.y = (px.y < -400) ? 600 : px.y - 1;
- }
- var canvas:BitmapData=_bmp.bitmapData
- canvas.fillRect(canvas.rect, 0x00000000);
- canvas.draw(viewport, _mtx);
- _root.rotationY = rotationY;
- camera.y = cameraY;
- camera.zoom = cameraZoom;
- }
- public function show():void { addChild(_bmp) };
- public function hide():void { removeChild(_bmp) };
- }
- class Pt
- {
- public var x:Number, y:Number, z:Number, color:uint;
- public function Pt(x:Number = 0, y:Number = 0, z:Number = 0, color:uint = 0)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- this.color = color;
- }
- }
Checkmate vol4 Massmedian Xmas Message with Twitter
- /**
- * ネットで投稿されたメッセージが
- * クリスマスの夜空を飾ります
- *
- * クリスマスメッセージは
- * 「Twitter」と「はてなブックマーク」で送ることができます
- * ※追記:11/5(木)、Twitter仕様変更によりTwitter投稿はできなくなりました
- *
- * ※投稿はFlash内のボタンを押して、
- * Twitterの場合は[]内にコメントを
- * はてなブックマークの場合は、ブックマークコメントを記入下さい
- *
- * このFlashはwonderfl上の様々なテクニックを元に作られました
- *
- * Twitter連動
- * http://wonderfl.net/code/04d6d1ae7e943b7faab88623ed83404e7a40c5f7
- *
- * キラキラ3D
- * http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c
- *
- * 文字のパーティクル化
- * http://wonderfl.net/code/08ec1c2c8da8e9e487867a8e2ab8cddeb75f8986
- *
- * 木を作る再帰関数
- * http://wonderfl.net/code/00cbe3ecbf0db2e865bc410a8ea54677c19ba4c6
- *
- * 配列のシャッフル
- * http://wonderfl.net/code/8cfa39c9e91a268791142fe605c010dc30338588
- *
- * BetweenAS3の時間調整
- * http://wonderfl.net/code/59af9d8a3cc45e4c2e6fcf12a9bc9ea55b1576e7
- *
- */
- package {
- import com.bit101.components.Label;
- import flash.display.*;
- import flash.events.*;
- import flash.geom.Matrix;
- import flash.net.*;
- import flash.system.*;
- import flash.text.*;
- import flash.utils.*;
- import jp.progression.casts.*;
- import jp.progression.commands.lists.LoaderList;
- import jp.progression.commands.lists.SerialList;
- import jp.progression.commands.net.*;
- import jp.progression.data.getResourceById;
- import org.libspark.betweenas3.BetweenAS3;
- import org.libspark.betweenas3.easing.*;
- import org.libspark.betweenas3.tweens.ITween;
- import org.papervision3d.cameras.Camera3D;
- import org.papervision3d.core.effects.*;
- import org.papervision3d.core.geom.Pixels;
- import org.papervision3d.core.geom.renderables.Pixel3D;
- import org.papervision3d.core.math.Number3D;
- import org.papervision3d.materials.*;
- import org.papervision3d.objects.DisplayObject3D;
- import org.papervision3d.objects.primitives.*;
- import org.papervision3d.render.BasicRenderEngine;
- import org.papervision3d.scenes.Scene3D;
- import org.papervision3d.view.Viewport3D;
- import org.papervision3d.view.layer.BitmapEffectLayer;
- [SWF(width=465, height=465, frameRate=30, backgroundColor=0)]
- public class Main extends CastDocument {
- static public const URL_HATENA:String = "http://pipes.yahooapis.com/pipes/pipe.run?_id=a9fa16f111d33689315b50bd196f691e&_render=rss";
- //static public const URL_TWITTER:String = "http://search.twitter.com/search.atom?q=%23XmasMessage&rpp=50";
- static public const URL_TWITTER:String = "http://clockmaker.jp/labs/091022_pv3d_xmas/search.atom";
- static public const URL_IMG_BG:String = "http://clockmaker.jp/labs/091021_checkmate/assets/bg.png";
- static public const URL_IMG_TITLE:String = "http://clockmaker.jp/labs/091021_checkmate/assets/title.png";
- static public const URL_IMG_BTN_HATENA:String = "http://clockmaker.jp/labs/091021_checkmate/assets/btn-hatena.png";
- static public const URL_IMG_BTN_TWITTER:String = "http://clockmaker.jp/labs/091021_checkmate/assets/btn-twitter.png";
- static private const MAX_PARTICLES:int = 2500;
- // color
- public static const WHITE:uint = 0xFFF0F0F0;
- public static const GREEN:uint = 0xFF008800;
- public static const RED:uint = 0xFFCC0000;
- public static const GOLD:uint = 0xFFFFCC66;
- public static const SILVER:uint = 0xFFCCCCCC;
- public static const COLORS:Array = [WHITE, GREEN, RED, GOLD, SILVER];
- // 3d
- private var scene:Scene3D = new Scene3D();
- private var renderer:BasicRenderEngine = new BasicRenderEngine();
- private var viewport:Viewport3D = new Viewport3D(465, 465);
- private var camera:Camera3D = new Camera3D()
- // 3d objects
- private const MAX_RADIUS:int = 10000;
- private const PIXCEL_MARGIN:Number = 1.25;
- private var textPixels:Pixels;
- private var treePixels:Pixels;
- private var pixelArr:Array = [];
- private var bfx:BitmapEffectLayer;
- private var dmyObjs:Array = [];
- private var tweens:Array = [];
- // 3d camera
- public var cameraDistance:Number = 1000;
- public var cameraYaw:Number = 0;
- public var cameraPitch:Number = 0;
- // 2d
- private var canvas:BitmapData;
- private var mtx:Matrix;
- private var progress:ProgressBar;
- private var loading:Label;
- private var loadingTween:ITween;
- // array of objs
- private var data:Array = [];
- // fractal
- private var level:int = 0;
- // data
- private var index:int = 0;
- private const RESET_TIMER:Timer = new Timer(11 * 1000);
- /**
- * Progression 4 では atReady から処理が始まります
- */
- override protected function atReady() : void{
- stage.quality = StageQuality.MEDIUM;
- // 3D
- addChild(viewport);
- // progress bar
- progress = new ProgressBar();
- progress.value = 0;
- this.addChild(progress)
- progress.x = int(stage.stageWidth / 2 - progress.width/2);
- progress.y = int(stage.stageHeight / 2 + 10);
- // loading
- loading = new Label(this, stage.stageWidth / 2 - 33, stage.stageHeight / 2 - 10, "NOW LOADING");
- loadingTween = BetweenAS3.tween(loading, { alpha:1 }, { alpha:0.25 }, 0.05);
- loadingTween = BetweenAS3.serial(loadingTween, BetweenAS3.reverse(loadingTween));
- loadingTween.stopOnComplete = false;
- loadingTween.play();
- var context:LoaderContext = new LoaderContext(true);
- var loaderList:LoaderList = new LoaderList(null,
- new LoadBitmapData(new URLRequest(URL_IMG_BG), {context:context}),
- new LoadBitmapData(new URLRequest(URL_IMG_TITLE), {context:context}),
- new LoadURL(new URLRequest(URL_TWITTER), {context:context}),
- new LoadURL(new URLRequest(URL_HATENA), {context:context}),
- new LoadBitmapData(new URLRequest(URL_IMG_BTN_HATENA), {context:context}),
- new LoadBitmapData(new URLRequest(URL_IMG_BTN_TWITTER), {context:context})
- );
- loaderList.onProgress = function():void{
- progress.value = 0.5 * (loaderList.loaded / loaderList.numCommands)
- }
- new SerialList(null,
- loaderList,
- function():void{
- // Twitter連携 by http://wonderfl.net/code/04d6d1ae7e943b7faab88623ed83404e7a40c5f7 (coppieee)
- default xml namespace = new Namespace("http://www.w3.org/2005/Atom");
- var xml:XML = XML(getResourceById(URL_TWITTER).data);
- for (var i:int = 0; i < xml.entry.length(); i++) {
- // コメントを抽出
- var comment:String = scan(xml.entry[i].title,/\[(.+)\]/);
- // RT は除外
- if(xml.entry[i].title.indexOf("RT") > -1) continue;
- // コメントなしは除外
- if(comment == "") continue;
- // データに追加
- data.push({
- img : xml.entry[i].link.(@type == "image/png").@href,
- name : xml.entry[i].author.name.split(" (")[0],
- comment : comment
- });
- }
- xml = XML(getResourceById(URL_HATENA).data);
- for (i = 0; i < xml.channel.item.length(); i++) {
- if(xml.channel.item[i].description != undefined){
- comment = xml.channel.item[i].description;
- var name:String = xml.channel.item[i].title;
- var imgurl:String = "http://www.st-hatena.com/users/" + name.substr(0,2) + "/" + name + "/profile.gif";
- data.push({
- img : imgurl,
- name : name,
- comment : comment
- });
- }
- }
- data = shuffle(data);
- data = data.slice(0, 8)
- },
- init3d
- ).execute();
- }
- /**
- * Papervision3D関係のごにょごにょ
- */
- private function init3d():void {
- // カメラの設定
- camera.target = DisplayObject3D.ZERO;
- // ビットマップエフェクトレイヤー
- bfx = new BitmapEffectLayer(viewport, stage.stageWidth, stage.stageHeight);
- bfx.addEffect(new BitmapColorEffect(1, 1, 1, 0.75));
- viewport.containerSprite.addLayer(bfx);
- // ピクセル3D
- textPixels = new Pixels(bfx);
- scene.addChild(textPixels);
- treePixels = new Pixels(bfx);
- scene.addChild(treePixels);
- var i:int;
- var arr:Array = [];
- // snow
- var star:Array = [0xFFFFFFFF, 0xFFcccccc, 0xFF666666, 0xFF333333]
- for (i = 0; i < 1500; i++) {
- treePixels.addPixel3D(new Pixel3D(star[star.length * Math.random() | 0],
- 10000 * (Math.random() - 0.5),
- 10000 * (Math.random()) - 1000,
- 10000 * (Math.random() - 0.5)));
- }
- for (i = 0; i < 255; i++) {
- treePixels.addPixel3D(new Pixel3D(0xFF0066CC,
- 100 * (Math.floor(i / 15) - 7),
- -1000,
- 100 * (i % 15 - 7)));
- }
- // ダミーオブジェクトを作成
- for (var k:int = 0; k < data.length; k++) {
- dmyObjs[k] = new DisplayObject3D();
- while (true) {
- var angle:Number = 360 * Math.random();
- dmyObjs[k].x = 2000 * Math.sin(angle * Number3D.toRADIANS);
- dmyObjs[k].y = 2000 * (Math.random() - 0.5);
- dmyObjs[k].z = 2000 * Math.cos(angle * Number3D.toRADIANS);
- if (k == 0)
- break;
- else {
- if (DisplayObject3D(dmyObjs[k]).distanceTo(dmyObjs[k - 1]) >= 500)
- break;
- }
- }
- dmyObjs[k].lookAt(DisplayObject3D.ZERO);
- scene.addChild(dmyObjs[k]);
- }
- for (i = 0; i < MAX_PARTICLES; i++) {
- var p:Pixel3D = new Pixel3D(COLORS[COLORS.length * Math.random() | 0]);
- textPixels.addPixel3D(p);
- }
- drawTree(0, -1000, 0, 1000, 90, GOLD);
- loading.text = "NOW RENDERING"
- loading.x = stage.stageWidth / 2 - 39
- var cmd:SerialList = new SerialList();
- var renderIndex:int=0;
- for (i = 0; i < data.length; i++) {
- cmd.addCommand(
- function():void{
- preRenderText(renderIndex);
- createText(renderIndex);
- renderIndex ++;
- progress.value = 0.5 + 0.5 * (renderIndex / data.length);
- },
- 0.05
- );
- }
- cmd.addCommand(
- function():void{
- // remove loading
- removeChild(loading);
- removeChild(progress);
- loadingTween.stop();
- loadingTween = null;
- // ui
- addChildAt(new CastBitmap(getResourceById(URL_IMG_BG).data), 0);
- addChild(new CastBitmap(getResourceById(URL_IMG_TITLE).data, "auto", false, {x:20, y:376}));
- var hatenaBtn:CastButton = new CastButton({x:20, y:433});
- hatenaBtn.addChild(new Bitmap(getResourceById(URL_IMG_BTN_HATENA).data));
- hatenaBtn.onCastMouseUp = function():void{
- navigateToURL(new URLRequest("http://b.hatena.ne.jp/append?http://wonderfl.net/code/d5de28ad1f65364ee33b964101222be41a7320af"));
- }
- hatenaBtn.buttonMode = true;
- addChild(hatenaBtn);
- var tweetBtn:CastButton = new CastButton({x:240, y:433});
- tweetBtn.addChild(new Bitmap(getResourceById(URL_IMG_BTN_TWITTER).data));
- tweetBtn.onCastMouseUp = function():void{
- navigateToURL(new URLRequest("http://twitter.com/home/?status=" + escapeMultiByte("#XmasMessage [] http://j.mp/xmaswon")));
- };
- tweetBtn.buttonMode = true;
- addChild(tweetBtn);
- // キラキラロジック by http://wonderfl.net/code/c0f513f31389ba07e375331256c2bfa3a8b9006c (sake)
- canvas = new BitmapData(720 / 4, 485 / 4, false, 0x000000);
- var bmp:Bitmap = new Bitmap(canvas, PixelSnapping.NEVER, false);
- bmp.scaleX = bmp.scaleY = 4;
- bmp.smoothing = true;
- bmp.blendMode = BlendMode.ADD;
- addChildAt(bmp,2);
- mtx = new Matrix();
- mtx.scale(0.25, 0.25);
- // tree
- drawTree(0, -1000, 0, 1000, 90, GOLD);
- // タイマーを作る
- RESET_TIMER.addEventListener(TimerEvent.TIMER, timerHandler);
- RESET_TIMER.start();
- // エンターフレーム
- addEventListener(Event.ENTER_FRAME, loop);
- },
- timerHandler
- );
- cmd.execute();
- }
- private function timerHandler(e:TimerEvent = null):void {
- var i:int;
- var arr:Array = [];
- for (i = 0; i < textPixels.pixels.length; i++) {
- arr[i] = BetweenAS3.serial(
- BetweenAS3.delay(
- BetweenAS3.to(textPixels.pixels[i], getRandomPos(), 3, Expo.easeInOut),
- Math.random()));
- }
- BetweenAS3.serial(
- BetweenAS3.parallelTweens(arr),
- BetweenAS3.func(function():void {
- setTimeout(motionText, 2 * 1000);
- })
- ).play();
- //
- index++;
- if (index == data.length - 1)
- index = 0;
- //
- var cameraTarget:DisplayObject3D = new DisplayObject3D();
- cameraTarget.copyTransform(dmyObjs[index]);
- cameraTarget.moveBackward(250);
- var dis:Number = cameraTarget.distanceTo(DisplayObject3D.ZERO);
- var rot:Number = Math.atan2(cameraTarget.x, cameraTarget.z);
- BetweenAS3.parallel(
- BetweenAS3.delay(
- BetweenAS3.bezier(this, {
- cameraYaw: rot,
- cameraDistance: dis,
- cameraPitch: cameraTarget.y
- }, null, getRandomPos(), 10.5, Expo.easeInOut),
- 1.0) ,
- BetweenAS3.serial(
- BetweenAS3.to(camera, {
- fov: 60
- }, 4, Sine.easeInOut),
- BetweenAS3.to(camera, {
- fov: 50
- }, 8, Sine.easeInOut)
- )
- ).play();
- }
- private var preRenderedTests:Array = [];
- private function preRenderText(itemIndex:int):void {
- preRenderedTests[itemIndex] = [];
- var text:TextField = new TextField();
- text.multiline = true;
- text.autoSize = "left";
- text.htmlText = "<font face='Arial' size='24'>WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW</font>";
- trace(data[itemIndex].comment);
- var size:int = 24;
- while(text.textWidth * text.textHeight > MAX_PARTICLES){
- text.htmlText = "<font face='Arial' size='" + size +"'>" + data[itemIndex].comment + "</font>"
- // +"<br><font face='Arial' size='" + size / 2 + "'>" + String(data[itemIndex].name).toUpperCase() + "</font>";
- size--;
- }
- var cap:BitmapData = new BitmapData(text.textWidth + 10, text.textHeight, true, 0xFFFFFFFF);
- cap.lock();
- cap.draw(text);
- // particle motion
- var cnt:int = 0;
- for (var i:int = 0; i < text.textWidth + 10; i++) {
- for (var j:int = 0; j < text.textHeight; j++) {
- if (cap.getPixel(i, j) == 0xFFFFFF)
- continue;
- if(preRenderedTests[itemIndex].length >= MAX_PARTICLES) break;
- preRenderedTests[itemIndex].push({x: i, y: j, textWidth: text.textWidth, textHeight: text.textHeight});
- }
- }
- cap.unlock();
- cap.dispose();
- }
- /**
- * テキストをBitmapData化してトゥイーンとして作成
- * @param itemIndex
- */
- private function createText(itemIndex:int):void {
- var t:DisplayObject3D = dmyObjs[itemIndex];
- // particle motion
- var cnt:int = 0;
- var arr:Array = [];
- for (var i:int = 0; i < preRenderedTests[itemIndex].length; i++) {
- var pix:Object = preRenderedTests[itemIndex][i];
- var p:Pixel3D = textPixels.pixels[i];
- var vec:DisplayObject3D = new DisplayObject3D();
- vec.x = (pix.x - pix.textWidth / 2) * PIXCEL_MARGIN;
- vec.y = (pix.textHeight / 2 - pix.y) * PIXCEL_MARGIN;
- vec.z = 0;
- vec.transform.calculateMultiply(t.transform, vec.transform);
- arr[i] = BetweenAS3.bezier(p, {
- x: vec.x,
- y: vec.y,
- z: vec.z
- }, null, getRandomPos(), 1.2 + Math.random() * 0.25 + i * 0.002, Expo.easeOut);
- }
- tweens.push(arr);
- }
- private function motionText():void {
- var tw:ITween = BetweenAS3.parallelTweens(tweens[index]);
- // トゥイーンのデュレーションを調整
- tw = BetweenAS3.scale(tw, 3.5 / tw.duration);
- tw.play();
- }
- /**
- * エンターフレームイベント
- */
- private function loop(e:Event = null):void {
- // カメラ
- camera.x = cameraDistance * Math.sin(cameraYaw);
- camera.y = cameraPitch;
- camera.z = cameraDistance * Math.cos(cameraYaw);
- // レンダリング
- renderer.renderScene(scene, camera, viewport);
- // キラキラ
- canvas.fillRect(canvas.rect, 0x000000);
- canvas.draw(viewport, mtx);
- }
- private function getRandomPos():Object {
- return {
- x: MAX_RADIUS * (Math.random() - 0.5),
- y: MAX_RADIUS * (Math.random() - 0.5),
- z: MAX_RADIUS * (Math.random() - 0.5)
- };
- }
- /**
- * 木を作る再帰関数
- * http://wonderfl.net/code/00cbe3ecbf0db2e865bc410a8ea54677c19ba4c6
- * @param x
- * @param y
- * @param z
- * @param length
- * @param angle
- * @param cf
- *
- */
- private function drawTree(x:Number, y:Number, z:Number, length:Number, angle:Number, cf:int):void {
- level += 1;
- var destx:Number = x + length * Math.cos(angle * (Math.PI / 180));
- var desty:Number = y + length * Math.sin(angle * (Math.PI / 180));
- var destz:Number = z + length * (Math.random() - 0.5) * 2;
- if (Math.random() < 0.5)
- cf = COLORS[COLORS.length * Math.random() | 0];
- var max:int = 10 - level / 1.5;
- for (var i:int = 0; i < max; i++) {
- treePixels.addPixel3D(new Pixel3D(cf,
- destx * i / max + x * (max - i) / max,
- desty * i / max + y * (max - i) / max,
- destz * i / max + z * (max - i) / max
- ));
- }
- if (level < 6) {
- drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
- drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
- drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
- drawTree(destx, desty, destz, length * (1 + 3 * Math.random()) * 0.25, angle + 60 * (Math.random() - Math.random()), cf);
- }
- level -= 1;
- }
- /**
- * 1行でArrayをシャッフルする by nemu90kWw
- * http://wonderfl.net/code/8cfa39c9e91a268791142fe605c010dc30338588
- */
- public function shuffle(array:Array):Array{
- return array.sort(function():int{return int(Math.random()*3)-1});
- }
- /**
- * @see http://takumakei.blogspot.com/2009/05/actionscriptrubystringscan.html
- */
- //package com.blogspot.takumakei.utils
- //{
- //public
- public function scan(str:String, re:RegExp):Array
- {
- if(!re.global){
- var flags:String = 'g';
- if(re.dotall)
- flags += 's';
- if(re.multiline)
- flags += 'm';
- if(re.ignoreCase)
- flags += 'i';
- if(re.extended)
- flags += 'x';
- re = new RegExp(re.source, flags);
- }
- var r:Array = [];
- var m:Array = re.exec(str);
- while(null != m){
- if(1 == m.length)
- r.push(m[0]);
- else
- r.push(m.slice(1, m.length));
- m = re.exec(str);
- }
- return r;
- }
- //}
- }
- }
- import flash.display.*;
- class ProgressBar extends Sprite {
- private var edge:Sprite = new Sprite;
- private var cont:Sprite = new Sprite;
- private var _value:Number = 0;
- public function set value(v:Number):void {
- _value = v;
- cont.scaleX = _value;
- }
- public function get value():Number {
- return _value;
- }
- public function ProgressBar() {
- edge.graphics.lineStyle(1, 0xFFFFFF);
- edge.graphics.drawRect(0.5, 0.5, 100, 10);
- cont.graphics.beginFill(0x555555);
- cont.graphics.drawRect(0, 0, 100, 10);
- addChild(cont);
- addChild(edge);
- value = 0;
- }
- }
Checkmate vol4 Massmedian forked from: Checkmate vol4 Massmedian
- // forked from checkmate's Checkmate vol4 Massmedian
- package {
- import flash.display.*;
- import flash.events.*;
- import flash.net.*;
- import flash.geom.*;
- import flash.system.LoaderContext;
- [SWF(backgroundColor=0x00,width="465", height="465", frameRate=60)]
- public class FlashTest extends Sprite {
- /*
- * [Checkmate Vol4 by MASSMEDIAN]
- * Please produce the illumination freely with a color palette.
- *
- * usage of Palette class
- * A single value is used.
- * var white:uint = Palette.WHITE;
- * var green:uint = Palette.GREEN;
- * var red:uint = Palette.RED;
- * var gold:uint = Palette.GOLD;
- * var silver:uint = Palette.SILVER;
- * var black:uint = Palette.BLACK;
- * All the values are used.
- * var colors:Array = Palette.getColors();
- */
- private function init( e:Event = null ):void {
- resize();
- drawXmasTree()
- }
- public var rect:Rectangle = new Rectangle();
- public var center:Point = new Point();
- public var bmd1:BitmapData;
- public var bmd2:BitmapData;
- public var bmp:Bitmap;
- public var loader :Loader;
- private const SLOW_LENGTH:int = 8000;
- private var _snow:Vector.<Snow> = new Vector.<Snow>();
- private var _twincles:BitmapData;
- private var _canvas:BitmapData;
- private var _matrix:Matrix;
- private var _ctf:ColorTransform = new ColorTransform( 0.75, 0.8, 0.8, 0.95 );
- private function createSnow():void {
- // The value used for generation is prepared.
- const RADIAN:Number = Math.PI*2;
- const COLORS:Array = Palette.getColors();
- // The canvas to draw in illumination.
- var snow:Snow, speed:Number, angle:Number;
- for( var i :int = 0; i<SLOW_LENGTH; ++i ) {
- snow = new Snow();
- snow.x = (Math.random()-0.5)*rect.width + center.x;
- snow.y = Math.random()*rect.height;
- snow.vx = (Math.random()-0.5) * 4;
- snow.vy = Math.random()*-2;
- snow.color = COLORS[int(COLORS.length*Math.random())];
- _snow.push( snow );
- }
- // The canvas to draw in illumination.
- _canvas = new BitmapData( rect.width, rect.height, true, 0 );
- var cbm :Bitmap = addChild( new Bitmap( _canvas ) ) as Bitmap;
- cbm.smoothing = true;
- // The canvas to draw in twincles.
- _twincles = new BitmapData( rect.width/4>>0, rect.height/4>>0, true, 0 );
- var tbm:Bitmap = addChild( new Bitmap( _twincles ) ) as Bitmap;
- tbm.scaleX = tbm.scaleY = 4;
- tbm.smoothing = true;
- tbm.blendMode = BlendMode.ADD;
- // Matrix to draw by size of 1/4
- _matrix = new Matrix(0.25, 0, 0, 0.25);
- addEventListener( Event.ENTER_FRAME, updateSnow );
- }
- private function updateSnow(e:Event):void {
- _canvas.lock();
- for each( var snow:Snow in _snow ) {
- // The Brownian motion is added.
- snow.vx += (Math.random()-0.5)*0.04;
- snow.vy += (Math.random()-0.5)*0.04;
- // Gravity is added.
- snow.vy += 0.015;
- // The wind drag is added.
- snow.vx *= 0.987;
- snow.vy *= 0.987;
- // The speed is added to the position.
- snow.x += snow.vx;
- snow.y += snow.vy;
- // draw to canvas in position.
- _canvas.setPixel32( snow.x, snow.y, snow.color | 0xFF<<24 );
- // It resets it when going out of the area.
- if( snow.x < rect.x -50 || snow.y < rect.y -50 || snow.x > rect.width +50 || snow.y > rect.height + 50 ) {
- snow.x = center.y + (Math.random() -0.5) * rect.width;
- snow.y = Math.random() *-30;
- snow.vx = (Math.random() -0.5) * 3;
- snow.vy = Math.random() *-3;
- }
- if (bmd2.getPixel(snow.x, snow.y) != 0) {
- snow.vx = 0;
- snow.vy = 0;
- snow.x += snow.vx;
- snow.y += snow.vy;
- }
- }
- // ColorTransform(effect that dose blackout) is made to adjust.
- _canvas.colorTransform( _canvas.rect, _ctf );
- _canvas.unlock();
- // draw to canvas in twincles by using Matrix.
- _twincles.draw( _canvas, _matrix );
- }
- private function resize( e:Event = null ):void {
- rect.width = stage.stageWidth;
- rect.height= stage.stageHeight;
- center.x = rect.width /2>>0;
- center.y = rect.height /2>>0;
- }
- private function drawXmasTree():void {
- var context:LoaderContext = new LoaderContext(true);
- loader = new Loader();
- loader.load( new URLRequest("http://swf-dev.wonderfl.net/static/assets/checkmate04/tree.jpg"), context );
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete);
- }
- private function complete(e:Event):void {
- bmd1 = new BitmapData(loader.width, loader.height, true);
- bmd1.draw(loader);
- bmd2 = bmd1.clone();
- bmp = new Bitmap(bmd2);
- addChild(bmp);
- createSnow();
- }
- private function showPaletteMap():void {
- var colors:Array = Palette.getColors();
- var palette:Sprite = addChild( new ColorMap( colors ) ) as Sprite;
- palette.x = ( rect.width - palette.width ) /2 >>0;
- palette.y = ( rect.height- palette.height ) /2 >>0;
- }
- public function FlashTest() {
- if( stage ) init();
- else addEventListener( Event.ADDED_TO_STAGE, init );
- }
- }
- }
- /* for Checkmate */
- class Palette {
- public static const WHITE:uint = 0xF0F0F0;
- public static const GREEN:uint = 0x008800;
- public static const RED:uint = 0xCC0000;
- public static const GOLD:uint = 0xFFCC66;
- public static const SILVER:uint = 0xCCCCCC;
- public static const BLACK:uint = 0x101010;
- public static const COLORS:Array = [ WHITE, GREEN, RED, GOLD, SILVER, BLACK ];
- public static function getColors():Array { return COLORS.slice(); }
- }
- /* for Example. */
- class Snow {
- public var x:Number = 0;
- public var y:Number = 0;
- public var vx:Number = 0;
- public var vy:Number = 0;
- public var color:uint = 0x00;
- }
- /* for debug. */
- import flash.display.*;
- class ColorMap extends Sprite {
- public function ColorMap(colors:Array) {
- var l:int = colors.length;
- var rect:Sprite;
- for( var i:int=0; i<l; ++i ) {
- addChild( rect = new ColorRect( colors[ i ] ) );
- rect.x =i * ColorRect.WIDTH;
- rect.y =0;
- }
- }
- }
- /* for debug. */
- class ColorRect extends Sprite {
- public static const WIDTH:int = 40;
- public static const HEIGHT:int = 40;
- public function ColorRect( color:uint ) {
- super();
- graphics.beginFill( color, 1 );
- graphics.drawRect( 0, 0, WIDTH, HEIGHT );
- graphics.endFill();
- }
- }



notice: 







