Home Tutorials Forums Articles Blogs Movies Library Employment Press
Prev Previous Post   Next Post Next
Old 08-06-2006, 09:50 PM   #1
pet-theory
Registered User
 
Join Date: May 2006
Posts: 25
Default dynamic-gradient mask acts like rectangle

Hi:

I'm trying to:

1) draw a gradient with code
2) use it as a mask on a bitmap

the masked bitmap is embedded and instantiated: new EmbeddedClass()
the mask is created via a new Shape()
that Shape uses the graphics object methods to draw it: beginGradientFill, draw Rect, etc.
the gradient has an alphas array like this: [0, 255], so it goes from visible to invisible (I've checked this)
the actual masking: maskedBitmap.mask=maskShape;

the result is a solid mask, not a gradient mask...how can I apply a dynamic gradient mask?

the code is not pretty but here it goes:

Code:
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.display.DisplayObject;
	import flash.display.InterpolationMethod;
	import flash.display.Shape;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.DisplacementMapFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;

	public class TestIt extends Sprite
	{
		[Embed(source="images/desert.jpg")] internal var Desert:Class;
		internal var picture:Bitmap;
		internal var rippleMap:BitmapData
		internal var rippleFilter:DisplacementMapFilter;
		internal var offset:Point;
		internal var bandMask:Shape;
		internal var bgPicture:Bitmap;
		public function TestIt()
		{
		//put embedded picture in a bitmap
		picture= new Desert();
		//clone a background for when the foreground picture is partly masked
		bgPicture=new Bitmap(picture.bitmapData.clone());
		addChild(bgPicture);
		addChild(picture);
		//create a displacement map based on blue, with a lot of noise along y
		rippleMap=new BitmapData(picture.width, picture.height/2);
		rippleFilter=new DisplacementMapFilter(rippleMap, new Point(0,50), 100, BitmapDataChannel.BLUE, 0, 55, "clamp", 0, 0);
		//listen to enterframe and animate the filter by continously offsetting the filter's displacement map's perlin noise
		addEventListener(Event.ENTER_FRAME, makeRipple) 
		offset=new Point(0,0);
		//create a gradient to use as a mask
		bandMask=new Shape();
		var colors:Array=[0xffffff, 0x0000FF];
        var alphas:Array=[100,0];
        var ratios:Array=[0, 255];
        var spread:String=SpreadMethod.PAD;
        var inter:String=InterpolationMethod.LINEAR_RGB;
        var focal:int=0
        var mat:Matrix=new Matrix();
        mat.createGradientBox(640, 200, -Math.PI/2);
  	    bandMask.graphics.beginGradientFill("linear",colors,alphas,ratios,mat, spread, inter, focal);
		bandMask.graphics.drawRect(0, 50, 640,200)
		bandMask.graphics.endFill();
		bandMask.blendMode="layer"
		//put the mask on the display list and mask the picture
		addChild (bandMask);
		picture.mask=bandMask;
		}
		
		internal function makeRipple(evt:Event):void {
			//move the first octave of the perlin noise
			offset.x+=.2;
			offset.y+=.6;
			rippleMap.perlinNoise(150,20, 5, 89, true, true, BitmapDataChannel.BLUE, false, [offset]);
			picture.filters=[rippleFilter];
		}
		}
	
	}
basically, I'm using the DisplacementMapFilter to make heat rise from the horizon in the desert, but I'd like the ripples to fade out gradually into the sky by using a gradient mask

I'm considering alternatives, like merging the gradient right onto the displacement map (to fade the perlin noise gradually wherever I want)

that would probably be easier on the processer, less alphaing, but still, I'd like to know how to get a dynamic gradient mask working
pet-theory is offline   Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is mask work for dynamic text field ? tiru ActionScript 1.0 (and below) 16 02-05-2007 03:08 PM
dynamic changes in the mask (movie clip does not duplicate itself in the mask layer) enfant2soleil ActionScript 2.0 5 08-12-2005 04:50 PM
Dynamic text under dynamic mask w/ MS+ scroller....... G-Rard B Other Flash General Questions 0 12-22-2004 11:13 PM
Gradient Mask Away Dynamic Text with Scroll c2kman ActionScript 1.0 (and below) 4 03-29-2004 08:39 AM
gradient mask?? Trinidad Animation and Effects 1 07-28-2002 10:46 PM


All times are GMT. The time now is 06:19 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.