Checkmate

Saqoosha

Amateur
簡単にグラデーションが作成できる Gradation クラスを使って、あなたなりの"虹"を表現してください。
ヒント:この Gradation クラスは PennerEasing を使って色補完することができます。複数の色をつなぐ場合にCubic.easeInOut など使うと滑らかになります。
Amateur
Create your original "rainbow" expression with "Gradation" class that enables you to draw gradation pattern easily.
Hint: By using "PennerEasing," the color gap can be filled in Gradation class; "Cubic.easeInOut" also creates smooth link with more than two colors.
Checkmateの遊び方
CHECKMATEはKingの称号をもつActionScript Masterたちの、問題にFORKする(プログラムを書き換える)ことで、回答していくFlash詰め将棋です。
下記にあるKingの書いたActionScriptにForkボタンをクリックして、プログラムを改造して、Kingをうならせてください。
優秀者上位3名には、wonderflユーザーページで表示される王冠を贈呈させて頂きます。 ※お題を直接FORKしたコードのみを審査対象とさせていただきます
How to participate CHECKMATE
CHECKMATE is chess like quiz solving contest by FORKing, meaning re-writing programs, to the quiz statement given by Kings, masters of ActionScript. Click "Fork" button and re-write scripts written by King, and impress him. Three best subscribers will be prize crown sign shown at their wonderfl user page. Meanwhile, only codes that are FORKed directly from question are regarded as contest participation.
Checkmate Challengers
Schedule
Fork acceptance period: 2009-09-07/24T00:00+9:00 | Judging period: 2009-09-24/30T00:00+9:00 | Result presentation: 2009-09-30T00:00+9:00
結果発表 Result presentation
saqoosha.amateur

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

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

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


FORKED
  1. // forked from checkmate's Saqoosha challenge for amateurs
  2. package {
  3.     
  4.     import flash.display.Sprite;
  5.     
  6.     [SWF(width=465, height=465, backgroundColor=0xffffff, frameRate=120)]
  7.     public class GradationTest1 extends Sprite {
  8.         
  9.         public function GradationTest1() {
  10.             // Gradationクラスを作る。任意の数のカラー値を渡すことができる。
  11.             var grad:Gradation = new Gradation(0xff0000, 0x00ff00, 0x0000ff);
  12.             for (var y:int = 0; y < 465; y++) {
  13.                 // getColorでグラデーションを構成する中間色を取り出す。渡す値は0〜1。滑らかにこの値を変化させることでグラデーションを作り出す。
  14.                 graphics.beginFill(grad.getColor(y / 464));
  15.                 graphics.drawRect(0, y, 4651);
  16.                 graphics.endFill();
  17.             }
  18.         }
  19.     }
  20. }
  21. import frocessing.color.ColorLerp;
  22. import org.libspark.betweenas3.core.easing.IEasing;
  23. import org.libspark.betweenas3.easing.Linear;
  24. class Gradation {
  25.     
  26.     private var _colors:Array;
  27.     private var _easing:IEasing;
  28.     
  29.     public function Gradation(...args) {
  30.         _colors = args.concat();
  31.         _easing = Linear.linear;
  32.     }
  33.     
  34.     public function setEasing(easing:IEasing):void {
  35.         _easing = easing;
  36.     }
  37.     
  38.     public function getColor(position:Number):uint {
  39.         position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
  40.         var idx:int = position;
  41.         var alpha:Number = _easing.calculate(position - idx, 011);
  42.         if (alpha == 0) {
  43.             return _colors[idx];
  44.         } else {
  45.             return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
  46.         }
  47.     }
  48. }
noswf
  1. // forked from checkmate's Saqoosha challenge for amateurs
  2. package {
  3.     
  4.     import flash.display.Sprite;
  5.     
  6.     [SWF(width=465, height=465, backgroundColor=0xffffff, frameRate=120)]
  7.     public class GradationTest1 extends Sprite {
  8.         
  9.         public function GradationTest1() {
  10.             // Gradationクラスを作る。任意の数のカラー値を渡すことができる。
  11.             var grad:Gradation = new Gradation();
  12.             for (var y:int = 0; y < 465; y++) {
  13.                 // getColorでグラデーションを構成する中間色を取り出す。渡す値は0〜1。滑らかにこの値を変化させることでグラデーションを作り出す。
  14.                 graphics.beginFill(grad.getColor(y / 464));
  15.                 graphics.drawRect(0, y, 4651);
  16.                 graphics.endFill();
  17.             }
  18.         }
  19.     }
  20. }
  21. import frocessing.color.ColorLerp;
  22. import org.libspark.betweenas3.core.easing.IEasing;
  23. import org.libspark.betweenas3.easing.Linear;
  24. class Gradation {
  25.     
  26.     private var _colors:Array;
  27.     private var _easing:IEasing;
  28.     
  29.     public function Gradation(...args) {
  30.         _colors = args.concat();
  31.         _easing = Linear.linear;
  32.     }
  33.     
  34.     public function setEasing(easing:IEasing):void {
  35.         _easing = easing;
  36.     }
  37.     
  38.     public function getColor(position:Number):uint {
  39.         position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
  40.         var idx:int = position;
  41.         var alpha:Number = _easing.calculate(position - idx, 011);
  42.         if (alpha == 0) {
  43.             return _colors[idx];
  44.         } else {
  45.             return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
  46.         }
  47.     }
  48. }
noswf
  1. package {
  2.     
  3.     import flash.display.BitmapData;
  4.     import flash.display.BitmapDataChannel;
  5.     import flash.display.Shape;
  6.     import flash.display.Sprite;
  7.     import flash.events.TimerEvent;
  8.     import flash.filters.DisplacementMapFilter;
  9.     import flash.filters.DisplacementMapFilterMode;
  10.     import flash.geom.Point;
  11.     import flash.media.Camera;
  12.     import flash.media.Video;
  13.     import flash.utils.Timer;
  14.     import net.hires.debug.Stats;
  15.     
  16.     [SWF(width=465, height=465, backgroundColor=0xffffff, frameRate=30)]
  17.     public class GradationTest1 extends Sprite {
  18.         private var _video:Video;
  19.         private var _bd:BitmapData;
  20.         private var _grad:Gradation;
  21.         private var _shp:Shape;
  22.         private var _dmf:DisplacementMapFilter;
  23.         
  24.         public function GradationTest1() {
  25.             var camera:Camera = Camera.getCamera();
  26.             var timer:Timer = new Timer(100);
  27.             timer.addEventListener(TimerEvent.TIMER, onTimer);
  28.             _shp = new Shape();
  29.             addChild(_shp);
  30.             
  31.             if (camera != null) {
  32.                 _video = new Video(465465);
  33.                 _video.attachCamera(camera);
  34.                 _video.alpha = 0.9;
  35.                 addChild(_video);
  36.             }
  37.             // Gradationクラスを作る。任意の数のカラー値を渡すことができる。
  38.             _grad = new Gradation(0xff0000, 0x00ff00, 0x0000ff);
  39.             _bd = new BitmapData(465465);
  40.            timer.start();
  41.             _dmf = new DisplacementMapFilter(_bd, new Point(), BitmapDataChannel.BLUE, BitmapDataChannel.RED, 5050, DisplacementMapFilterMode.IGNORE);
  42.            
  43.             if (_video) {
  44.                 //removeChild(_shp);
  45.                 _video.filters = [_dmf];
  46.             }
  47.             addChild(new Stats());
  48.         }
  49.         
  50.         private function onTimer(e:TimerEvent):void 
  51.         {
  52.             _bd.lock();
  53.             var n:int = Timer(e.target).currentCount % 49;
  54.             n = (n > 25) ? 48 - n : n;
  55.             n += 10;
  56.             n = 12000 / n;
  57.             trace("onTimer", n);
  58.             _shp.graphics.clear();
  59.             var vy:int = 300;
  60.             var vx:int = 0;
  61.             var v:Number;
  62.             for (var y:int = 0; y < 465; y++) {
  63.                 // getColorでグラデーションを構成する中間色を取り出す。渡す値は0〜1。滑らかにこの値を変化させることでグラデーションを作り出す。
  64.                 vy -= vx * 0.02;
  65.                 vx += vy * 0.02;
  66.                 v = (y * 12 / n) % 2;
  67.                 v = (v > 1) ? 2 - v : v;
  68.                 _shp.graphics.beginFill(_grad.getColor(v));
  69.                 _shp.graphics.drawCircle(mouseX + vx, mouseY + vy, (465 - y) * 1.2);
  70.                 _shp.graphics.endFill();
  71.             }
  72.             _bd.draw(_shp);
  73.             _bd.unlock();
  74.             _dmf.mapBitmap = _bd;
  75.         }
  76.     }
  77. }
  78. import frocessing.color.ColorLerp;
  79. import org.libspark.betweenas3.core.easing.IEasing;
  80. import org.libspark.betweenas3.easing.Linear;
  81. class Gradation {
  82.     
  83.     private var _colors:Array;
  84.     private var _easing:IEasing;
  85.     
  86.     public function Gradation(...args) {
  87.         _colors = args.concat();
  88.         _easing = Linear.linear;
  89.     }
  90.     
  91.     public function setEasing(easing:IEasing):void {
  92.         _easing = easing;
  93.     }
  94.     
  95.     public function getColor(position:Number):uint {
  96.         position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
  97.         var idx:int = position;
  98.         var alpha:Number = _easing.calculate(position - idx, 011);
  99.         if (alpha == 0) {
  100.             return _colors[idx];
  101.         } else {
  102.             return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
  103.         }
  104.     }
  105. }
noswf

Saqoosha challenge for amateurs BRE ver0.1 [diff(251)]

  1. // forked from checkmate's Saqoosha challenge for amateurs
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.geom.*;
  7.     import flash.media.Sound;
  8.     import flash.net.URLRequest;
  9.     import flash.utils.getTimer;
  10.     import com.bit101.components.Label;
  11.     /**
  12.      * 
  13.      * @author k3lab
  14.      */
  15.     [SWF(width="465", height="465", frameRate="60")] 
  16.     public class Main extends Sprite {
  17.         private static const PARTICLE_NUM:int = 500;
  18.         private static const SPRING:Number = 0.18;
  19.         private static const FRICTION:Number = 0.75;
  20.         
  21.         private var canvas:BitmapData; 
  22.         private var clones:BitmapData;
  23.         
  24.         private var pArr:Array = [];
  25.         private var volArr:Array = []
  26.         private var colorArr:Array = []
  27.         
  28.         private var clt:ColorTransform = new ColorTransform(11110, -10, -10, -10);
  29.         private var sp:Sprite;
  30.         private var trail:Sprite;
  31.         
  32.         private var vx:Number = 0;
  33.         private var vy:Number = 0;
  34.         private var ratio:Number = 0;
  35.         
  36.         private var grad:Gradation;
  37.         
  38.         public function Main():void {
  39.             if (stage) init();
  40.             else addEventListener(Event.ADDED_TO_STAGE, init);
  41.         }
  42.         private function init(e:Event = null):void {
  43.             removeEventListener(Event.ADDED_TO_STAGE, init);
  44.             //BGM
  45.             var sound:Sound = new Sound (new URLRequest ("http://www.k3lab.com/wonderfl/Euphoria/bgm.mp3"));  
  46.             sound.play (0int.MAX_VALUE); 
  47.             
  48.             canvas = new BitmapData(465465false, 0x00000000);    
  49.             clones = canvas.clone(); 
  50.             addChild(new Bitmap(clones)) as Bitmap; 
  51.             grad = new Gradation(0xff0000, 0x00ff00, 0x0000ff);
  52.             var a:Number = 0;
  53.             sp = addChild(new Sprite()) as Sprite;
  54.             sp.blendMode = "screen";
  55.             for (var i:int = 0; i < PARTICLE_NUM; i++) {
  56.                 a += 0.2
  57.                 var p:Particle =sp.addChild(new Particle()) as Particle;
  58.                 p._x = 240 * Math.sin(a);
  59.                 p._y  = 240 * Math.cos(a);
  60.                 p._z = 0;
  61.                 pArr[i] = p
  62.                 p.draw(grad.getColor(i / PARTICLE_NUM), 0.6,  Math.random() * 0.6);
  63.             }
  64.             //******************************************
  65.             //付属品
  66.             mouseTrail();
  67.             createBg();
  68.             createHeader();
  69.             createBar();
  70.             createVolume();
  71.             //******************************************
  72.             addEventListener(Event.ENTER_FRAME, loop);
  73.         }
  74.         //************************************************************
  75.         //マウストレイル
  76.         private function mouseTrail():void {
  77.             trail = addChild(new Sprite()) as Sprite;
  78.             trail.graphics.beginFill(0xFFFFFF);
  79.             trail.graphics.drawRect( -100201);
  80.             trail.graphics.drawRect(0 , -10120);
  81.             trail.graphics.endFill();
  82.             var circles:Sprite=trail.addChild(new Sprite()) as Sprite;
  83.             circles.graphics.beginFill(0xFFFFFF);
  84.             circles.graphics.drawRect( -465010301);
  85.             circles.graphics.drawRect( 0, -46511030);
  86.             circles.graphics.endFill();
  87.             circles.alpha = 0.2;    
  88.         }
  89.         //全体のBG
  90.         private function createBg():void {
  91.             var pattern:BitmapData = background()
  92.             var bg:Sprite = addChild(new Sprite()) as Sprite;
  93.             bg.graphics.beginBitmapFill(pattern);
  94.             bg.graphics.drawRect(00465465)
  95.             bg.graphics.endFill();
  96.             bg.alpha = 0.3;
  97.         }
  98.         //上のTitle&BG
  99.         private function createHeader():void {
  100.             var tbg:Sprite = addChild(new Sprite()) as Sprite;
  101.             tbg.graphics.beginFill(0);
  102.             tbg.graphics.drawRect( 0046518);
  103.             tbg.graphics.endFill();
  104.             var title:Label = new Label(this1470"Barrage of Rainbow Exploration ver.0.1"); 
  105.             title.blendMode = "invert"
  106.         }
  107.         //左上のColor Bar
  108.         private function createBar():void {
  109.             var cl:Array = [0xff0000, 0x00ff00, 0x0000ff]
  110.             var clsp:Sprite = addChild(new Sprite()) as Sprite;
  111.             for (var i:int = 0; i < 3; i++) {
  112.                 var colors:Sprite = clsp.addChild(new Sprite()) as Sprite;
  113.                 colors.graphics.beginFill(cl[i]);
  114.                 colors.graphics.drawRect( 0010,10);
  115.                 colors.graphics.endFill();
  116.                 colors.x = 11 * i;
  117.             }
  118.             clsp.x = 4;
  119.             clsp.y = 4;
  120.         }
  121.         //右上のvoloume
  122.         private function createVolume():void {
  123.             var volsp:Sprite = addChild(new Sprite()) as Sprite;
  124.             for (var i:int = 0; i < 7; i++) {
  125.                 var vol:Sprite = volsp.addChild(new Sprite()) as Sprite;
  126.                 vol.graphics.beginFill(0xFFFFFF);
  127.                 vol.graphics.drawRect( 001, -10);
  128.                 vol.graphics.endFill();
  129.                 vol.x=2*i
  130.                 volArr[i] = vol;
  131.             }
  132.             volsp.x = stage.stageWidth - volsp.width - 5;
  133.             volsp.y = 15;
  134.         }
  135.         private function voloop():void {
  136.             for each(var v:Sprite in volArr) {
  137.                 v.height = Math.sin(getTimer() / 500 * Math.random() * 5) * 10;
  138.             }    
  139.         }
  140.         private function trailoop():void {
  141.             vx += (mouseX - trail.x) * SPRING;
  142.             vy += (mouseY - trail.y) * SPRING;
  143.             vx *= FRICTION;
  144.             vy *= FRICTION;
  145.             trail.x += int(vx);
  146.             trail.y += int(vy);
  147.         }
  148.         //************************************************************
  149.         private function loop(e:Event):void {
  150.             voloop();
  151.             trailoop();
  152.             var zp:Number = 0;
  153.             var i:int;
  154.             for each(var p:Particle in pArr) {
  155.                 var xa:Number = Math.sin(Math.PI * (getTimer()+i*100) % 30000 / 30000 * 360 / 180) / 20;
  156.                 var ya:Number = Math.sin(Math.PI * (getTimer()+i*100) % 1500 / 1500 * 360 / 180) / 20;
  157.                 var yp:Number = p._y * Math.cos(ya) -p._z * Math.sin(ya);
  158.                 zp =p._y * Math.sin(ya) + p._z * Math.cos(ya);
  159.                 var xp:Number = p._x * Math.cos(xa) + zp * Math.sin(xa);
  160.                 zp = ( -p._x) * Math.sin(xa) + zp * Math.cos(xa);
  161.                 p._x = xp;
  162.                 p._y = yp;
  163.                 p._z = zp;
  164.                 p.alpha = Math.random() * 1;
  165.                 (p._z < -95)?p.visible = false:p.visible = true;
  166.                 ratio = 1 / (p._z /100 + 1)
  167.                 var num:Number = 0;
  168.                 p.scaleY = num = ratio * 7;
  169.                 p.scaleX = num;
  170.                 p.x += (p._x * ratio + (mouseX) - p.x) / 10;
  171.                 p.y += (p._y * ratio +( mouseY) - p.y) / 10;
  172.                 canvas.setPixel(p.x, p.y, grad.getColor(i /PARTICLE_NUM)); 
  173.                 i++;
  174.             }
  175.             clones.lock(); 
  176.             canvas.lock();
  177.             canvas.draw(sp)
  178.             clones.merge(canvas, canvas.rect, new Point(),zp/10,zp/100, zp*10,0.5);
  179.             clones.draw(canvas, nullnew ColorTransform(100 * zp, 1010), "add");
  180.             canvas.applyFilter(canvas, canvas.rect, new Point(00), new BlurFilter(20201)); 
  181.             clones.scroll(01);
  182.             clones.colorTransform(clones.rect, clt); 
  183.             canvas.colorTransform(canvas.rect, clt);
  184.             clones.unlock(); 
  185.             canvas.unlock();            
  186.         }
  187.         public function background():BitmapData{ 
  188.             return BitmapPatternBuilder.build( 
  189.                 [[100], 
  190.                 [010],
  191.                 [001]],
  192.                 [0xFF000000, 0xffffffff] 
  193.             ); 
  194.         } 
  195.     }
  196. }
  197. import flash.display.Graphics;
  198. import flash.display.Sprite;
  199. class Particle extends Sprite {
  200.     public var _x:Number=0;
  201.     public var _y:Number=0;
  202.     public var _z:Number=0;
  203.     public function draw(color:int, alpha:Number, size:Number):void {
  204.         graphics.beginFill(color, alpha);
  205.         graphics.drawCircle(00, size);
  206.         graphics.endFill();
  207.     }
  208. }
  209. import frocessing.color.ColorLerp;
  210. import org.libspark.betweenas3.core.easing.IEasing;
  211. import org.libspark.betweenas3.easing.Linear;
  212. class Gradation {
  213.     
  214.     private var _colors:Array;
  215.     private var _easing:IEasing;
  216.     
  217.     public function Gradation(...args) {
  218.         _colors = args.concat();
  219.         _easing = Linear.linear
  220.     }
  221.     
  222.     public function setEasing(easing:IEasing):void {
  223.         _easing = easing;
  224.     }
  225.     
  226.     public function getColor(position:Number):uint {
  227.         position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
  228.         var idx:int = position;
  229.         var alpha:Number = _easing.calculate(position - idx, 011);
  230.         if (alpha == 0) {
  231.             return _colors[idx];
  232.         } else {
  233.             return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
  234.         }
  235.     }
  236. }
  237. /**-----------------------------------------------------
  238.  * @see http://wonderfl.net/code/5f88476bd21cac4d45ad2086af2333782a5d3cb8
  239.  * ----------------------------------------------------- 
  240. */ 
  241. import flash.display.Bitmap; 
  242. import flash.display.BitmapData; 
  243. import flash.display.Graphics; 
  244.      
  245. class BitmapPatternBuilder{ 
  246.     /** 
  247.      * creates BitmapData filled with dot pattern. 
  248.      * First parameter is 2d array that contains color index for each pixels; 
  249.      * Second parameter contains color reference table. 
  250.      * 
  251.      * @parameter pattern:Array 2d array that contains color index for each pixel. 
  252.      * @parameter colors:Array 1d array that contains color table. 
  253.      * @returns BitmapData 
  254.      */ 
  255.     public static function build(pattern:Array, colors:Array):BitmapData{ 
  256.         var bitmapW:int = pattern[0].length; 
  257.         var bitmapH:int = pattern.length; 
  258.         var bmd:BitmapData = new BitmapData(bitmapW,bitmapH,true,0x000000); 
  259.         for(var yy:int=0; yy<bitmapH; yy++){ 
  260.             for(var xx:int=0; xx<bitmapW; xx++){ 
  261.                 var color:int = colors[pattern[yy][xx]]; 
  262.                 bmd.setPixel32(xx, yy, color); 
  263.             } 
  264.         } 
  265.         return bmd; 
  266.     } 
  267.      
  268.     /** 
  269.      * short cut function for Graphics.beginBitmapFill with pattern. 
  270.      */ 
  271.     public static function beginBitmapFill(pattern:Array, colors:Array, graphics:Graphics):void
  272.         var bmd:BitmapData = build(pattern, colors); 
  273.         graphics.beginBitmapFill(bmd); 
  274.         bmd.dispose();         
  275.     } 
noswf
  1. // forked from checkmate's Saqoosha challenge for amateurs
  2. package {
  3.     import flash.display.Bitmap;
  4.     import flash.display.BitmapData;
  5.     import flash.display.Sprite;
  6.     import flash.display.BlendMode;
  7.     import flash.display.StageQuality;
  8.     import flash.events.Event;
  9.     import flash.filters.BlurFilter;
  10.     import flash.geom.ColorTransform;
  11.     import flash.geom.Point;
  12.     import flash.geom.Rectangle;
  13.     
  14.     [SWF(width=465, height=465, backgroundColor=0x000000, frameRate=60)]
  15.     public class RainbowStarPainter extends Sprite { 
  16.         private const BLUR_FILTER:BlurFilter = new BlurFilter(12121);
  17.         private const BLUR_FILTER2:BlurFilter = new BlurFilter(30301);
  18.         private const ZERO_POINT:Point = new Point(00);
  19.         private const DIM_COLOR:ColorTransform = new ColorTransform(0.20.20.20.2);    
  20.         
  21.         private const rainbow:Gradation = new Gradation(0xff0000, 0xffff00, 0x00ff00, 0x00ffff, 0x0000ff, 0xff00ff, 0xff0000);
  22.         private var color:Number;
  23.         private var trend:Number;
  24.         private var yCount:int;
  25.         
  26.         private var canvasCache:Bitmap;
  27.         private var canvasBrush:Rectangle;
  28.         private var canvas:Bitmap;
  29.         private var tmpCache:Sprite;
  30.         private var myMask:Sprite;
  31.         private var stars:Array;
  32.         
  33.         public function RainbowStarPainter() {
  34.             stage.quality = StageQuality.LOW;
  35.             stars = new Array;
  36.             color = Math.random();
  37.             trend = Math.random()*0.005;
  38.             yCount = 0;
  39.             
  40.             canvas = addChild(new Bitmap(new BitmapData(465465true))) as Bitmap;
  41.             tmpCache = new Sprite;
  42.             canvasCache = tmpCache.addChild(new Bitmap(new BitmapData(465465false))) as Bitmap;
  43.             myMask = tmpCache.addChild(new Sprite) as Sprite;
  44.             canvasCache.mask = myMask;
  45.             canvasBrush = new Rectangle(003030);
  46.             canvasCache.bitmapData.fillRect(canvas.bitmapData.rect, rainbow.getColor(color));
  47.             addEventListener(Event.ENTER_FRAME, _updateScreen);
  48.         }
  49.         
  50.         private function _updateScreen(e:Event):void {
  51.             var y:int;
  52.             color += trend;
  53.             trend += (Math.random() * 0.001)-0.0005;
  54.             trend = Math.max(0.001, Math.min(0.005, trend));
  55.             if (color > 1) {
  56.                 color = 0;
  57.             }
  58.             for (var x:int = 0; x < 465; x += 30) {
  59.                 y = yCount - x;
  60.                 if (yCount - x > 465) {
  61.                     y = 930 - y;
  62.                 } else if (y < 0) {
  63.                     y = -y;
  64.                 }
  65.                 canvasBrush.x = x;
  66.                 canvasBrush.y = y;
  67.                 canvasCache.bitmapData.fillRect(canvasBrush, rainbow.getColor(color));
  68.             }
  69.             yCount += 5;
  70.             yCount %= 930;
  71.             canvasCache.bitmapData.applyFilter(canvasCache.bitmapData, canvasCache.bitmapData.rect, ZERO_POINT, BLUR_FILTER2);
  72.             
  73.             //update stars
  74.             var i:int = stars.length;
  75.             if (i<180) {
  76.                 stars.push(myMask.addChild(new Star()));
  77.             }
  78.             
  79.             while (i--) {
  80.                 stars[i].x += stars[i].speedX;
  81.                 stars[i].y += stars[i].speedY;
  82.                 stars[i].rotation += stars[i].rotationSpeed;
  83.                 if (stars[i].y < -100) {
  84.                     stars[i].resetStar();
  85.                 }
  86.             }
  87.             
  88.             canvas.bitmapData.applyFilter(canvas.bitmapData, canvas.bitmapData.rect, ZERO_POINT, BLUR_FILTER);
  89.             canvas.bitmapData.draw(canvas.bitmapData, null, DIM_COLOR, BlendMode.ADD);
  90.             canvas.bitmapData.draw(tmpCache);
  91.         }
  92.     }
  93. }
  94. import flash.display.Sprite;
  95. import flash.display.Bitmap;
  96. import flash.display.BitmapData;
  97. import flash.geom.Matrix;
  98. import flash.geom.Rectangle;
  99. class Star extends Sprite {
  100.     public var speedX:Number;
  101.     public var speedY:Number;
  102.     public var rotationSpeed:Number;
  103.     public function Star() {
  104.         graphics.beginFill(0xFF0000);
  105.         graphics.moveTo( -90.5, -207.5);
  106.         graphics.lineTo(29.5, -126.1);
  107.         graphics.lineTo(171.9, -153.1);
  108.         graphics.lineTo(131.6, -13.9);
  109.         graphics.lineTo(201.3113.3);
  110.         graphics.lineTo(56.4118.0);
  111.         graphics.lineTo( -43.0223.5);
  112.         graphics.lineTo( -92.387.2);
  113.         graphics.lineTo( -223.325.3);
  114.         graphics.lineTo( -108.8, -63.7);
  115.         graphics.lineTo( -90.5, -207.5);
  116.         graphics.endFill();
  117.         var tmpRect:Rectangle = getRect(this);
  118.         x = -tmpRect.left;
  119.         y = -tmpRect.top;
  120.         resetStar();
  121.        
  122.     }
  123.     
  124.     public function resetStar():void {
  125.          scaleX = scaleY = Math.random() * 0.125;
  126.         speedX = Math.random()*2 - 1;
  127.         speedY = (-Math.random() * 4)-2;
  128.         rotationSpeed = Math.random() * 14 - 7;
  129.         rotationSpeed += rotationSpeed > 0?1: -1;
  130.         y = 465;
  131.         x = Math.random() * 465;
  132.     }
  133. }
  134. import frocessing.color.ColorLerp;
  135. import org.libspark.betweenas3.core.easing.IEasing;
  136. import org.libspark.betweenas3.easing.Linear;
  137. class Gradation {
  138.     
  139.     private var _colors:Array;
  140.     private var _easing:IEasing;
  141.     
  142.     public function Gradation(...args) {
  143.         _colors = args.concat();
  144.         _easing = Linear.linear;
  145.     }
  146.     
  147.     public function setEasing(easing:IEasing):void {
  148.         _easing = easing;
  149.     }
  150.     
  151.     public function getColor(position:Number):uint {
  152.         position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
  153.         var idx:int = position;
  154.         var alpha:Number = _easing.calculate(position - idx, 011);
  155.         if (alpha == 0) {
  156.             return _colors[idx];
  157.         } else {
  158.             return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
  159.         }
  160.     }
  161. }
noswf

ad ad

Get Adobe Flash Player