In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

beginGradientFillを使用したグラデーションの作成 on 2010-1-29

Get Adobe Flash player
by komatsu 28 Jan 2010
/**
 * Copyright komatsu ( http://wonderfl.net/user/komatsu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hf5Y
 */

package {
    import flash.display.*;
    import flash.geom.*;
    [SWF(backgroundColor="#000000", frameRate=30)]
    public class RainbowGradetion extends Sprite {
    		private var w:uint = stage.stageWidth-100;
    		private var h:uint = stage.stageHeight-100;
    		
        public function RainbowGradetion() {
        		//グラデーションの種類  GradientType.LINEAR だと線状、GradientType.RADIALだと放射状
			var fillType:String = GradientType.LINEAR;
			//各グラデーションコントロールの色
  			var colors:Array = [0xFF0000,0xFFFF00,0x00FF00,0x00FFFF,0x0000FF,0xFF00FF,0xFF0000];
  			//各グラデーションコントロールの不透明度
  			var alphas:Array = [1,1,1,1,1,1,1];
  			//0~255段階での割合
  			var ratios:Array = [0,39,91,125,168,210,255];
  			var matr:Matrix = new Matrix();
  			//Matrixを使用したグラデーションの設定 createGradientBox(横幅,縦幅,角度,Xのオフセット値,Yのオフセット値);
  			matr.createGradientBox(w,h,0,0,0);
  			var spreadMethod:String = SpreadMethod.PAD;
  			
  			var sp:Sprite = new Sprite();
  			sp.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
  			sp.graphics.drawRect(0,0,w,h);
  			addChild(sp);
  			
  			//ここまでが虹のグラデーション//////////////////////////////////////////////////
  			
  			//上部白グラデーション  白(アルファ100%)~白(アルファ0%)
			fillType = GradientType.LINEAR;
  			colors = [0xFFFFFF,0xFFFFFF,0xFFFFFF];
  			alphas = [1,0.5,0];
  			ratios = [0,90,255];
  			matr = new Matrix();
  			matr.createGradientBox(w,h/2,90*Math.PI/180,0,0);
  			spreadMethod = SpreadMethod.PAD;
  			sp = new Sprite();
  			sp.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
  			sp.graphics.drawRect(0,0,w,h);
  			addChild(sp);
  			
  			//下部黒グラデーション  黒(アルファ0%)~黒(アルファ100%)
			fillType = GradientType.LINEAR;
  			colors = [0x000000,0x000000,0x000000];
  			alphas = [0,0.5,1];
  			ratios = [0,90,255];
  			matr = new Matrix();
  			matr.createGradientBox(w,h/2,90*Math.PI/180,0,0);
  			spreadMethod = SpreadMethod.PAD;
  			sp = new Sprite();
  			sp.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
  			sp.graphics.drawRect(0,0,w,h/2);
  			sp.y = h/2;
  			addChild(sp);
        }
    }
}