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

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

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


forked from : Saqoosha's Snow [diff(111)]

FAVORITE BY
:
:
:
:
儚い感じがステキ
:
斜めに削れていくのが良い味出してる
:
すごく綺麗で感動しました!!
FORKED
  1. // forked from nitoyon's Hello Snow!!!
  2. // Hellow Snow!!!
  3. // forked from Saqoosha's Snow
  4. package {
  5.     import flash.display.Bitmap;
  6.     import flash.display.BitmapData;
  7.     import flash.display.BlendMode;
  8.     import flash.display.PixelSnapping;
  9.     import flash.display.Sprite;
  10.     import flash.events.Event;
  11.     import flash.filters.BlurFilter;
  12.     import flash.geom.Matrix;
  13.     import flash.geom.Point;
  14.     import flash.geom.Rectangle;
  15.     import flash.text.TextField;
  16.     import flash.text.TextFieldAutoSize;
  17.     import flash.text.TextFormat;
  18.     [SWF(width=465, height=465, backgroundColor=0x0, frameRate=120)]
  19.     public class Snow extends Sprite {
  20.         private static const WIND_X:Number = 40;
  21.         private static const WIND_Y:Number = -15;
  22.         private static const GRAVITY:Number = 10;
  23.         private static const START_Y:Number = 200;
  24.         
  25.         private var _canvas:BitmapData;
  26.         private var _textBmp:BitmapData;
  27.         private var _glow:BitmapData;
  28.         private var _glowMtx:Matrix;
  29.         private var _snow:Array;
  30.         private var _snow_prepare:Array;
  31.         private var _text:TextField;
  32.         private var _log:TextField;
  33.         
  34.         public function Snow() {
  35.             stage.scaleMode = "noScale";
  36.             _text = new TextField();
  37.             _text.defaultTextFormat = new TextFormat('Verdana'48, 0xffffff, true); 
  38.             _text.text = "心语难诉,但求一醉!";
  39.             _text.autoSize = "left";
  40.             _textBmp = new BitmapData(465465false, 0x000000);
  41.             this._canvas = new BitmapData(465465false, 0x000000);
  42.             //this.addChild(new Bitmap(_textBmp));
  43.             this.addChild(new Bitmap(this._canvas));
  44.             this._snow = [];
  45.             this._snow_prepare = [];
  46.             this._glow = new BitmapData(465 / 4465 / 4false, 0x0); // キラキラを描く用のん。カンバスの 4 分の 1 のサイズ
  47.             var bm:Bitmap = this.addChild(new Bitmap(this._glow, PixelSnapping.NEVER, true)) as Bitmap; // smoothing を true にして配置
  48.             bm.scaleX = bm.scaleY = 4// 4 倍にする。
  49.             bm.blendMode = BlendMode.ADD; // 加算モードで合成
  50.             this._glowMtx = new Matrix(0.25000.25);
  51.             // init _snow_prepare
  52.             this.addEventListener(Event.ENTER_FRAME, function(event:Event):void{
  53.                 for(var i:int = 0; i < 3; i++){
  54.                     if(_snow_prepare.length){
  55.                         var index:int = Math.random() * Math.min(30, _snow_prepare.length);
  56.                         var particle:SnowParticle = _snow_prepare[index];
  57.                         _snow_prepare.splice(index, 1);
  58.                         _textBmp.setPixel(particle.x, particle.y, 0x000000);
  59.                         _snow.push(particle);
  60.                     }
  61.                 }
  62.                 if(_snow_prepare.length || _snow.length){
  63.                     update(null);
  64.                 }else{
  65.                     init();
  66.                 }
  67.             });
  68.             init();
  69.         }
  70.         public function init():void{
  71.             var mtx:Matrix = new Matrix();
  72.             mtx.ty = START_Y;
  73.             _textBmp.draw(_text, mtx);
  74.             var rect:Rectangle = _textBmp.getColorBoundsRect(00false);
  75.             for(var x:int = rect.left; x <= rect.right; x++){
  76.                 for(var y:int = rect.top; y <= rect.bottom; y++){
  77.                     var col:uint = _textBmp.getPixel(x, y);
  78.                     if(col != 0x000000){
  79.                         _snow_prepare.push(new SnowParticle(x, y, col, Math.random(), -Math.random()));
  80.                     }
  81.                 }
  82.             }
  83.             _snow_prepare.sort(function(a:SnowParticle, b:SnowParticle):int{
  84.                 var _a:int = a.x + a.y * 3;
  85.                 var _b:int = b.x + b.y * 3;
  86.                 return _a > _b ? 1 : _a == _b ? 0 : -1;
  87.             });
  88.         }
  89.         // 雪を動かすよーー
  90.         public function update(e:Event):void {
  91.             this._canvas.lock(); // いっぱい setPixel するときは必ず lock しよう
  92.             this._canvas.fillRect(this._canvas.rect, 0x0); // カンバスをクリア
  93.             this._canvas.copyPixels(_textBmp, _textBmp.rect, new Point(00));
  94.             var n:int = this._snow.length;
  95.             var d:Number = 1.0;
  96.             var wind_x:Number = (Math.random() > .4 ? WIND_X : 0) / 1000;
  97.             var wind_y:Number = (GRAVITY + (Math.random() > .6 ? WIND_Y : WIND_Y / 2)) / 1000;
  98.             while (n--) {
  99.                 var p:SnowParticle = this._snow[n];
  100.                 p.vx += wind_x * p.s;
  101.                 p.vy += wind_y * p.s;
  102.                 p.vx *= 0.99// 空気抵抗
  103.                 p.vy *= 0.99// y 方向にも
  104.                 p.x += p.vx; // 動かす
  105.                 p.y += p.vy;
  106.                 this._canvas.setPixel(p.x, p.y, p.c); // 雪 1 粒描く
  107.                 if (p.y < 0 || p.y > this.stage.stageHeight || p.x > this.stage.stageWidth) { // もし画面外にでちゃったら
  108.                     this._snow.splice(n, 1); // とりのぞく
  109.                 }
  110.             }
  111.             this._canvas.unlock(); // lock したやつは必ず unlock
  112.             this._glow.draw(this._canvas, this._glowMtx); // キラキラを描く
  113.         }
  114.     }
  115. }
  116. class SnowParticle {
  117.     
  118.     public var x:Number;
  119.     public var y:Number;
  120.     public var vx:Number;
  121.     public var vy:Number;
  122.     public var s:Number;
  123.     public var c:int;
  124.     
  125.     public function SnowParticle(x:Number, y:Number, color:uint, vx:Number, vy:Number) {
  126.         this.x = x;
  127.         this.y = y;
  128.         this.vx = vx;
  129.         this.vy = vy;
  130.         this.s = 1;
  131.         this.c = color;
  132.     }
  133. }
noswf
  1. // forked from nitoyon's Hello Snow!!!
  2. // Hellow Snow!!!
  3. // forked from Saqoosha's Snow
  4. package {
  5.     import flash.display.Bitmap;
  6.     import flash.display.BitmapData;
  7.     import flash.display.BlendMode;
  8.     import flash.display.PixelSnapping;
  9.     import flash.display.Sprite;
  10.     import flash.events.Event;
  11.     import flash.filters.BlurFilter;
  12.     import flash.geom.Matrix;
  13.     import flash.geom.Point;
  14.     import flash.geom.Rectangle;
  15.     import flash.text.TextField;
  16.     import flash.text.TextFieldAutoSize;
  17.     import flash.text.TextFormat;
  18.     [SWF(width=465, height=465, backgroundColor=0x0, frameRate=120)]
  19.     public class Snow extends Sprite {
  20.         private static const WIND_X:Number = 40;
  21.         private static const WIND_Y:Number = -15;
  22.         private static const GRAVITY:Number = 10;
  23.         private static const START_Y:Number = 200;
  24.         
  25.         private var _canvas:BitmapData;
  26.         private var _textBmp:BitmapData;
  27.         private var _glow:BitmapData;
  28.         private var _glowMtx:Matrix;
  29.         private var _snow:Array;
  30.         private var _snow_prepare:Array;
  31.         private var _text:TextField;
  32.         private var _log:TextField;
  33.         
  34.         public function Snow() {
  35.             stage.scaleMode = "noScale";
  36.             _text = new TextField();
  37.             _text.defaultTextFormat = new TextFormat('Verdana'48, 0xffffff, true); 
  38.             _text.text = "Hello Snow!!!";
  39.             _text.autoSize = "left";
  40.             _textBmp = new BitmapData(465465false, 0x000000);
  41.             this._canvas = new BitmapData(465465false, 0x000000);
  42.             //this.addChild(new Bitmap(_textBmp));
  43.             this.addChild(new Bitmap(this._canvas));
  44.             this._snow = [];
  45.             this._snow_prepare = [];
  46.             this._glow = new BitmapData(465 / 4465 / 4false, 0x0); // キラキラを描く用のん。カンバスの 4 分の 1 のサイズ
  47.             var bm:Bitmap = this.addChild(new Bitmap(this._glow, PixelSnapping.NEVER, true)) as Bitmap; // smoothing を true にして配置
  48.             bm.scaleX = bm.scaleY = 4// 4 倍にする。
  49.             bm.blendMode = BlendMode.ADD; // 加算モードで合成
  50.             this._glowMtx = new Matrix(0.25000.25);
  51.             // init _snow_prepare
  52.             this.addEventListener(Event.ENTER_FRAME, function(event:Event):void{
  53.                 for(var i:int = 0; i < 3; i++){
  54.                     if(_snow_prepare.length){
  55.                         var index:int = Math.random() * Math.min(30, _snow_prepare.length);
  56.                         var particle:SnowParticle = _snow_prepare[index];
  57.                         _snow_prepare.splice(index, 1);
  58.                         _textBmp.setPixel(particle.x, particle.y, 0x000000);
  59.                         _snow.push(particle);
  60.                     }
  61.                 }
  62.                 if(_snow_prepare.length || _snow.length){
  63.                     update(null);
  64.                 }else{
  65.                     init();
  66.                 }
  67.             });
  68.             init();
  69.         }
  70.         public function init():void{
  71.             var mtx:Matrix = new Matrix();
  72.             mtx.ty = START_Y;
  73.             _textBmp.draw(_text, mtx);
  74.             var rect:Rectangle = _textBmp.getColorBoundsRect(00false);
  75.             for(var x:int = rect.left; x <= rect.right; x++){
  76.                 for(var y:int = rect.top; y <= rect.bottom; y++){
  77.                     var col:uint = _textBmp.getPixel(x, y);
  78.                     if(col != 0x000000){
  79.                         _snow_prepare.push(new SnowParticle(x, y, col, Math.random(), -Math.random()));
  80.                     }
  81.                 }
  82.             }
  83.             _snow_prepare.sort(function(a:SnowParticle, b:SnowParticle):int{
  84.                 var _a:int = a.x + a.y * 3;
  85.                 var _b:int = b.x + b.y * 3;
  86.                 return _a > _b ? 1 : _a == _b ? 0 : -1;
  87.             });
  88.         }
  89.         // 雪を動かすよーー
  90.         public function update(e:Event):void {
  91.             this._canvas.lock(); // いっぱい setPixel するときは必ず lock しよう
  92.             this._canvas.fillRect(this._canvas.rect, 0x0); // カンバスをクリア
  93.             this._canvas.copyPixels(_textBmp, _textBmp.rect, new Point(00));
  94.             var n:int = this._snow.length;
  95.             var d:Number = 1.0;
  96.             var wind_x:Number = (Math.random() > .4 ? WIND_X : 0) / 1000;
  97.             var wind_y:Number = (GRAVITY + (Math.random() > .6 ? WIND_Y : WIND_Y / 2)) / 1000;
  98.             while (n--) {
  99.                 var p:SnowParticle = this._snow[n];
  100.                 p.vx += wind_x * p.s;
  101.                 p.vy += wind_y * p.s;
  102.                 p.vx *= 0.99// 空気抵抗
  103.                 p.vy *= 0.99// y 方向にも
  104.                 p.x += p.vx; // 動かす
  105.                 p.y += p.vy;
  106.                 this._canvas.setPixel(p.x, p.y, p.c); // 雪 1 粒描く
  107.                 if (p.y < 0 || p.y > this.stage.stageHeight || p.x > this.stage.stageWidth) { // もし画面外にでちゃったら
  108.                     this._snow.splice(n, 1); // とりのぞく
  109.                 }
  110.             }
  111.             this._canvas.unlock(); // lock したやつは必ず unlock
  112.             this._glow.draw(this._canvas, this._glowMtx); // キラキラを描く
  113.         }
  114.     }
  115. }
  116. class SnowParticle {
  117.     
  118.     public var x:Number;
  119.     public var y:Number;
  120.     public var vx:Number;
  121.     public var vy:Number;
  122.     public var s:Number;
  123.     public var c:int;
  124.     
  125.     public function SnowParticle(x:Number, y:Number, color:uint, vx:Number, vy:Number) {
  126.         this.x = x;
  127.         this.y = y;
  128.         this.vx = vx;
  129.         this.vy = vy;
  130.         this.s = 1;
  131.         this.c = color;
  132.     }
  133. }
noswf
  1. // forked from nitoyon's Hello Snow!!!
  2. // Hellow Snow!!!
  3. // forked from Saqoosha's Snow
  4. package {
  5.     import flash.display.Bitmap;
  6.     import flash.display.BitmapData;
  7.     import flash.display.BlendMode;
  8.     import flash.display.PixelSnapping;
  9.     import flash.display.Sprite;
  10.     import flash.events.Event;
  11.     import flash.filters.BlurFilter;
  12.     import flash.geom.Matrix;
  13.     import flash.geom.Point;
  14.     import flash.geom.Rectangle;
  15.     import flash.text.TextField;
  16.     import flash.text.TextFieldAutoSize;
  17.     import flash.text.TextFormat;
  18.     [SWF(width=465, height=465, backgroundColor=0x0, frameRate=120)]
  19.     public class Snow extends Sprite {
  20.         private static const WIND_X:Number = 40;
  21.         private static const WIND_Y:Number = -15;
  22.         private static const GRAVITY:Number = 10;
  23.         private static const START_Y:Number = 200;
  24.         
  25.         private var _canvas:BitmapData;
  26.         private var _textBmp:BitmapData;
  27.         private var _glow:BitmapData;
  28.         private var _glowMtx:Matrix;
  29.         private var _snow:Array;
  30.         private var _snow_prepare:Array;
  31.         private var _text:TextField;
  32.         private var _log:TextField;
  33.         
  34.         public function Snow() {
  35.             stage.scaleMode = "noScale";
  36.             _text = new TextField();
  37.             _text.defaultTextFormat = new TextFormat('Verdana'48, 0xffffff, true); 
  38.             _text.text = "    (’・ω・‘)";
  39.             _text.autoSize = "left";
  40.             _textBmp = new BitmapData(465465false, 0x000000);
  41.             this._canvas = new BitmapData(465465false, 0x000000);
  42.             //this.addChild(new Bitmap(_textBmp));
  43.             this.addChild(new Bitmap(this._canvas));
  44.             this._snow = [];
  45.             this._snow_prepare = [];
  46.             this._glow = new BitmapData(465 / 4465 / 4false, 0x0); // キラキラを描く用のん。カンバスの 4 分の 1 のサイズ
  47.             var bm:Bitmap = this.addChild(new Bitmap(this._glow, PixelSnapping.NEVER, true)) as Bitmap; // smoothing を true にして配置
  48.             bm.scaleX = bm.scaleY = 4// 4 倍にする。
  49.             bm.blendMode = BlendMode.ADD; // 加算モードで合成
  50.             this._glowMtx = new Matrix(0.25000.25);
  51.             // init _snow_prepare
  52.             this.addEventListener(Event.ENTER_FRAME, function(event:Event):void{
  53.                 for(var i:int = 0; i < 3; i++){
  54.                     if(_snow_prepare.length){
  55.                         var index:int = Math.random() * Math.min(30, _snow_prepare.length);
  56.                         var particle:SnowParticle = _snow_prepare[index];
  57.                         _snow_prepare.splice(index, 1);
  58.                         _textBmp.setPixel(particle.x, particle.y, 0x000000);
  59.                         _snow.push(particle);
  60.                     }
  61.                 }
  62.                 if(_snow_prepare.length || _snow.length){
  63.                     update(null);
  64.                 }else{
  65.                     init();
  66.                 }
  67.             });
  68.             init();
  69.         }
  70.         public function init():void{
  71.             var mtx:Matrix = new Matrix();
  72.             mtx.ty = START_Y;
  73.             _textBmp.draw(_text, mtx);
  74.             var rect:Rectangle = _textBmp.getColorBoundsRect(00false);
  75.             for(var x:int = rect.left; x <= rect.right; x++){
  76.                 for(var y:int = rect.top; y <= rect.bottom; y++){
  77.                     var col:uint = _textBmp.getPixel(x, y);
  78.                     if(col != 0x000000){
  79.                         _snow_prepare.push(new SnowParticle(x, y, col, Math.random(), -Math.random()));
  80.                     }
  81.                 }
  82.             }
  83.             _snow_prepare.sort(function(a:SnowParticle, b:SnowParticle):int{
  84.                 var _a:int = a.x + a.y * 3;
  85.                 var _b:int = b.x + b.y * 3;
  86.                 return _a > _b ? -1 : _a == _b ? 0 : 1;
  87.             });
  88.         }
  89.         // 雪を動かすよーー
  90.         public function update(e:Event):void {
  91.             this._canvas.lock(); // いっぱい setPixel するときは必ず lock しよう
  92.             this._canvas.fillRect(this._canvas.rect, 0x0); // カンバスをクリア
  93.             this._canvas.copyPixels(_textBmp, _textBmp.rect, new Point(00));
  94.             var n:int = this._snow.length;
  95.             var d:Number = 1.0;
  96.             var wind_x:Number = (Math.random() > .4 ? WIND_X : 0) / 1000;
  97.             var wind_y:Number = (GRAVITY + (Math.random() > .6 ? WIND_Y : WIND_Y / 2)) / 1000;
  98.             while (n--) {
  99.                 var p:SnowParticle = this._snow[n];
  100.                 p.vx += wind_x * p.s;
  101.                 p.vy += wind_y * p.s;
  102.                 p.vx *= 0.99// 空気抵抗
  103.                 p.vy *= 0.99// y 方向にも
  104.                 p.x += p.vx; // 動かす
  105.                 p.y += p.vy;
  106.                 this._canvas.setPixel(p.x, p.y, p.c); // 雪 1 粒描く
  107.                 if (p.y < 0 || p.y > this.stage.stageHeight || p.x > this.stage.stageWidth) { // もし画面外にでちゃったら
  108.                     this._snow.splice(n, 1); // とりのぞく
  109.                 }
  110.             }
  111.             this._canvas.unlock(); // lock したやつは必ず unlock
  112.             this._glow.draw(this._canvas, this._glowMtx); // キラキラを描く
  113.         }
  114.     }
  115. }
  116. class SnowParticle {
  117.     
  118.     public var x:Number;
  119.     public var y:Number;
  120.     public var vx:Number;
  121.     public var vy:Number;
  122.     public var s:Number;
  123.     public var c:int;
  124.     
  125.     public function SnowParticle(x:Number, y:Number, color:uint, vx:Number, vy:Number) {
  126.         this.x = x;
  127.         this.y = y;
  128.         this.vx = vx;
  129.         this.vy = vy;
  130.         this.s = 1;
  131.         this.c = color;
  132.     }
  133. }
noswf
  1. // forked from nitoyon's Hello Snow!!!
  2. // Hellow Snow!!!
  3. // forked from Saqoosha's Snow
  4. package {
  5.     import flash.display.Bitmap;
  6.     import flash.display.BitmapData;
  7.     import flash.display.BlendMode;
  8.     import flash.display.PixelSnapping;
  9.     import flash.display.Sprite;
  10.     import flash.events.Event;
  11.     import flash.filters.BlurFilter;
  12.     import flash.geom.Matrix;
  13.     import flash.geom.Point;
  14.     import flash.geom.Rectangle;
  15.     import flash.text.TextField;
  16.     import flash.text.TextFieldAutoSize;
  17.     import flash.text.TextFormat;
  18.     [SWF(width=465, height=465, backgroundColor=0x0, frameRate=120)]
  19.     public class Snow extends Sprite {
  20.         private static const WIND_X:Number = 40;
  21.         private static const WIND_Y:Number = -15;
  22.         private static const GRAVITY:Number = 10;
  23.         private static const START_Y:Number = 200;
  24.         
  25.         private var _canvas:BitmapData;
  26.         private var _textBmp:BitmapData;
  27.         private var _glow:BitmapData;
  28.         private var _glowMtx:Matrix;
  29.         private var _snow:Array;
  30.         private var _snow_prepare:Array;
  31.         private var _text:TextField;
  32.         private var _log:TextField;
  33.         
  34.         public function Snow() {
  35.             stage.scaleMode = "noScale";
  36.             _text = new TextField();
  37.             _text.defaultTextFormat = new TextFormat('Verdana'48, 0xffffff, true); 
  38.             _text.text = "Hello Snow!!!";
  39.             _text.autoSize = "left";
  40.             _textBmp = new BitmapData(465465false, 0x000000);
  41.             this._canvas = new BitmapData(465465false, 0x000000);
  42.             //this.addChild(new Bitmap(_textBmp));
  43.             this.addChild(new Bitmap(this._canvas));
  44.             this._snow = [];
  45.             this._snow_prepare = [];
  46.             this._glow = new BitmapData(465 / 4465 / 4false, 0x0); // キラキラを描く用のん。カンバスの 4 分の 1 のサイズ
  47.             var bm:Bitmap = this.addChild(new Bitmap(this._glow, PixelSnapping.NEVER, true)) as Bitmap; // smoothing を true にして配置
  48.             bm.scaleX = bm.scaleY = 4// 4 倍にする。
  49.             bm.blendMode = BlendMode.ADD; // 加算モードで合成
  50.             this._glowMtx = new Matrix(0.25000.25);
  51.             // init _snow_prepare
  52.             this.addEventListener(Event.ENTER_FRAME, function(event:Event):void{
  53.                 for(var i:int = 0; i < 3; i++){
  54.                     if(_snow_prepare.length){
  55.                         var index:int = Math.random() * Math.min(30, _snow_prepare.length);
  56.                         var particle:SnowParticle = _snow_prepare[index];
  57.                         _snow_prepare.splice(index, 1);
  58.                         _textBmp.setPixel(particle.x, particle.y, 0x000000);
  59.                         _snow.push(particle);
  60.                     }
  61.                 }
  62.                 if(_snow_prepare.length || _snow.length){
  63.                     update(null);
  64.                 }else{
  65.                     init();
  66.                 }
  67.             });
  68.             init();
  69.         }
  70.         public function init():void{
  71.             var mtx:Matrix = new Matrix();
  72.             mtx.ty = START_Y;
  73.             _textBmp.draw(_text, mtx);
  74.             var rect:Rectangle = _textBmp.getColorBoundsRect(00false);
  75.             for(var x:int = rect.left; x <= rect.right; x++){
  76.                 for(var y:int = rect.top; y <= rect.bottom; y++){
  77.                     var col:uint = _textBmp.getPixel(x, y);
  78.                     if(col != 0x000000){
  79.                         _snow_prepare.push(new SnowParticle(x, y, col, Math.random(), -Math.random()));
  80.                     }
  81.                 }
  82.             }
  83.             _snow_prepare.sort(function(a:SnowParticle, b:SnowParticle):int{
  84.                 var _a:int = a.x + a.y * 3;
  85.                 var _b:int = b.x + b.y * 3;
  86.                 return _a > _b ? 1 : _a == _b ? 0 : -1;
  87.             });
  88.         }
  89.         // 雪を動かすよーー
  90.         public function update(e:Event):void {
  91.             this._canvas.lock(); // いっぱい setPixel するときは必ず lock しよう
  92.             this._canvas.fillRect(this._canvas.rect, 0x0); // カンバスをクリア
  93.             this._canvas.copyPixels(_textBmp, _textBmp.rect, new Point(00));
  94.             var n:int = this._snow.length;
  95.             var d:Number = 1.0;
  96.             var wind_x:Number = (Math.random() > .4 ? WIND_X : 0) / 1000;
  97.             var wind_y:Number = (GRAVITY + (Math.random() > .6 ? WIND_Y : WIND_Y / 2)) / 1000;
  98.             while (n--) {
  99.                 var p:SnowParticle = this._snow[n];
  100.                 p.vx += wind_x * p.s;
  101.                 p.vy += wind_y * p.s;
  102.                 p.vx *= 0.99// 空気抵抗
  103.                 p.vy *= 0.99// y 方向にも
  104.                 p.x += p.vx; // 動かす
  105.                 p.y += p.vy;
  106.                 this._canvas.setPixel(p.x, p.y, p.c); // 雪 1 粒描く
  107.                 if (p.y < 0 || p.y > this.stage.stageHeight || p.x > this.stage.stageWidth) { // もし画面外にでちゃったら
  108.                     this._snow.splice(n, 1); // とりのぞく
  109.                 }
  110.             }
  111.             this._canvas.unlock(); // lock したやつは必ず unlock
  112.             this._glow.draw(this._canvas, this._glowMtx); // キラキラを描く
  113.         }
  114.     }
  115. }
  116. class SnowParticle {
  117.     
  118.     public var x:Number;
  119.     public var y:Number;
  120.     public var vx:Number;
  121.     public var vy:Number;
  122.     public var s:Number;
  123.     public var c:int;
  124.     
  125.     public function SnowParticle(x:Number, y:Number, color:uint, vx:Number, vy:Number) {
  126.         this.x = x;
  127.         this.y = y;
  128.         this.vx = vx;
  129.         this.vy = vy;
  130.         this.s = 1;
  131.         this.c = color;
  132.     }
  133. }
noswf
  1. // forked from nitoyon's Hello Snow!!!
  2. // Hellow Snow!!!
  3. // forked from Saqoosha's Snow
  4. package {
  5.     import flash.display.Bitmap;
  6.     import flash.display.BitmapData;
  7.     import flash.display.BlendMode;
  8.     import flash.display.PixelSnapping;
  9.     import flash.display.Sprite;
  10.     import flash.events.Event;
  11.     import flash.events.MouseEvent;
  12.     import flash.filters.BlurFilter;
  13.     import flash.geom.Matrix;
  14.     import flash.geom.Point;
  15.     import flash.geom.Rectangle;
  16.     import flash.text.TextField;
  17.     import flash.text.TextFieldAutoSize;
  18.     import flash.text.TextFormat;
  19.     [SWF(width=465, height=465, backgroundColor=0x0, frameRate=120)]
  20.     public class HelloSnow extends Sprite {
  21.         private static const WIND_X:Number = 40;
  22.         private static const WIND_Y:Number = -15;
  23.         private static const GRAVITY:Number = 10;
  24.         private static const START_Y:Number = 200;
  25.         
  26.         private var _canvas:BitmapData;
  27.         private var _textBmp:BitmapData;
  28.         private var _glow:BitmapData;
  29.         private var _glowMtx:Matrix;
  30.         private var _snow:Array;
  31.         private var _snow_prepare:Array;
  32.         private var _text:TextField;
  33.         private var _log:TextField;
  34.         
  35.         public function HelloSnow() {
  36.             stage.scaleMode = "noScale";
  37.             _text = new TextField();
  38.             _text.defaultTextFormat = new TextFormat('Verdana'48, 0xffffffff, true); 
  39.             _text.autoSize = "left";
  40.             _text.text = "Wonderfl!!!";
  41.             _text.x = (465 - _text.width) / 2;
  42.             _text.y = (465 - _text.height) /2;
  43.             _textBmp = new BitmapData(465465false, 0x000000);
  44.             this._canvas = new BitmapData(465465false, 0x000000);
  45.             this.addChild(new Bitmap(this._canvas));
  46.             this._snow = [];
  47.             this._snow_prepare = [];
  48.             this._glow = new BitmapData(465 / 4465 / 4false, 0x0); // キラキラを描く用のん。カンバスの 4 分の 1 のサイズ
  49.             var bm:Bitmap = this.addChild(new Bitmap(this._glow, PixelSnapping.NEVER, true)) as Bitmap; // smoothing を true にして配置
  50.             bm.scaleX = bm.scaleY = 4// 4 倍にする。
  51.             bm.blendMode = BlendMode.ADD; // 加算モードで合成
  52.             this._glowMtx = new Matrix(0.25000.25);
  53.             this.addEventListener(Event.ENTER_FRAME, this.update);
  54.             
  55.             this.init();
  56.             
  57.             
  58.             this._log = this.addChild(new TextField()) as TextField;
  59.             this._log.defaultTextFormat = new TextFormat('Verdana'12, 0xffffff, true);
  60.             this._log.width = 100;
  61.         }
  62.         public function init():void {
  63.             _textBmp.draw(_text, _text.transform.matrix);
  64.             var rect:Rectangle = _textBmp.getColorBoundsRect(0xffffff, 0x0, false);
  65.             for(var x:int = rect.left; x <= rect.right; x++){
  66.                 for(var y:int = rect.top; y <= rect.bottom; y++){
  67.                     var col:uint = _textBmp.getPixel(x, y);
  68.                     if(col != 0x000000){
  69.                         var p:SnowParticle = new SnowParticle(x, y, col, 00);
  70.                         _snow_prepare.push(p);
  71.                         _snow.push(p);
  72.                     }
  73.                 }
  74.             }
  75.             this.stage.addEventListener(MouseEvent.CLICK, this._onClick);
  76.         }
  77.         
  78.         public function _onClick(e:MouseEvent):void {
  79.             // emit
  80.             var n:int = this._snow_prepare.length;//Math.min(20, _snow_prepare.length);
  81.             var mx:int = this.stage.mouseX;
  82.             var my:int = this.stage.mouseY;
  83.             for(var i:int = 0; i < n; i++){
  84. //                var index:int = Math.random() * Math.min(30, _snow_prepare.length);
  85. //                var particle:SnowParticle = _snow_prepare[index];
  86.                 var p:SnowParticle = this._snow_prepare[i];
  87.                 var dx:Number = p.x - mx + Math.random() * 5;
  88.                 var dy:Number = p.y - my + Math.random() * 5;
  89.                 var d:Number = dx * dx + dy * dy;
  90.                 var sqd:Number = Math.sqrt(d);
  91.                 var r:Number = Math.random() * 1 + 0.2;
  92.                 p.ax = dx / sqd * r;
  93.                 p.ay = dy / sqd * r;
  94.                 r = Math.random() * 2;
  95.                 p.vx = p.ax * r;
  96.                 p.vy = p.ay * r;
  97. //                _textBmp.setPixel(p.x, p.y, 0x000000);
  98.             }
  99.             this._snow_prepare = [];
  100.         }
  101.         
  102.         // 雪を動かすよーー
  103.         public function update(e:Event):void {
  104.             this._canvas.lock(); // いっぱい setPixel するときは必ず lock しよう
  105.             this._canvas.fillRect(this._canvas.rect, 0x0); // カンバスをクリア
  106. //            this._canvas.copyPixels(_textBmp, _textBmp.rect, new Point(0, 0));
  107.             var n:int = this._snow.length;
  108.             var d:Number = 1.0;
  109. //            var wind_x:Number = (Math.random() > .4 ? WIND_X : 0) / 1000;
  110. //            var wind_y:Number = (GRAVITY + (Math.random() > .6 ? WIND_Y : WIND_Y / 2)) / 1000;
  111.             while (n--) {
  112.                 var p:SnowParticle = this._snow[n];
  113.                 p.vx += p.ax;
  114.                 p.vy += p.ay;
  115.                 p.vx *= 0.99// 空気抵抗
  116.                 p.vy *= 0.99// y 方向にも
  117.                 p.x += p.vx; // 動かす
  118.                 p.y += p.vy;
  119.                 this._canvas.setPixel(p.x, p.y, p.c); // 雪 1 粒描く
  120.                 if (p.y < 0 || this.stage.stageHeight < p.y ||  p.x < 0 || this.stage.stageWidth < p.x) { // もし画面外にでちゃったら
  121.                     this._snow.splice(n, 1); // とりのぞく
  122.                 }
  123.             }
  124.             this._canvas.unlock(); // lock したやつは必ず unlock
  125.             this._glow.draw(this._canvas, this._glowMtx); // キラキラを描く
  126.             
  127.             //
  128.             this._log.text = String(this._snow.length);
  129.             if(_snow.length == 0){
  130.                 this.init();
  131.             }
  132.         }
  133.     }
  134. }
  135. class SnowParticle {
  136.     
  137.     public var x:Number;
  138.     public var y:Number;
  139.     public var vx:Number;
  140.     public var vy:Number;
  141.     public var ax:Number;
  142.     public var ay:Number;
  143.     public var c:int;
  144.     
  145.     public function SnowParticle(x:Number, y:Number, color:uint, vx:Number, vy:Number) {
  146.         this.x = x;
  147.         this.y = y;
  148.         this.vx = vx;
  149.         this.vy = vy;
  150.         this.ax = 0;
  151.         this.ay = 0;
  152.         this.c = color;
  153.     }
  154. }
noswf
Get Adobe Flash Player