This really helped - Thank you !

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Glen Pike
Sent: 30 September 2008 21:27
To: Flash Coders List
Subject: Re: [Flashcoders] Perlin Noise / Displacement

Hi,

    I did a similar thing to generate fake clouds - in a monochrome 
colour...
   
    Just try generating your perlin noise as greyscale - like you are 
doing.  You should not need to do the displacement filter on it, but 
with this you can do "clouds", through to big chunky stuff.  The trick 
is to overlay your perlin noise on a background colour by setting the 
blend mode to screen...

    Then if you want you can adjust the brightness and contrast of your 
bitmap, then finally, apply a threshold to it...
   
    Something like below:

    import flash.display.BitmapData;
import flash.geom.Point;
import flash.filters.*;
Stage.scaleMode="noScale";
// Perlin noise variables
var baseX                  :Number = Stage.width / 4;
var baseY                  :Number = Stage.height / 2;
var nOctaves               :Number = 6;
var randomSeed             :Number = Math.random()*82;
var bStitch             :Boolean = false;
var bFractalNoise          :Boolean = true;
var nChannels              :Number = 1;
var bGreyScale          :Boolean= true;

    // Offset array for perlin function
    var p1 = new Point(45, 34);
    var p2 = new Point(50, 60);
    var fltPt = new Point(0, 0);
    var fltRect = new Rectangle(0, 0, Stage.width, Stage.height);
             
    perlinOffset = new Array(p1, p2);

    var bg:MovieClip = _root.createEmptyMovieClip("bg", 
_root.getNextHighestDepth());
    bg.beginFill(0xFF0000);//Set this to whatever colour you want your 
chrome..
    bg.lineTo(Stage.width, 0);
    bg.lineTo(Stage.width, Stage.height);
    bg.lineTo(0, Stage.height);
    bg.lineTo(0, 0);
    bg.endFill();

    var holder:MovieClip = _root.createEmptyMovieClip("holder", 2);
    //You have a background colour underneath your perlin noise, which 
is white...
    //holder.blendMode = "screen";

    var cloudint = setInterval(animClouds, 1000/24);
   
    function animClouds() {
    //change the values in the perlinOffset to animate each perlin layer
    perlinOffset[0].y+=0.5;
    perlinOffset[0].x+=1;
    perlinOffset[1].x-=0.5;
    perlinOffset[1].y-=0.25;
    //    apply perlin noise to our bitmapdata
    bmp.perlinNoise(baseX, baseY, nOctaves, randomSeed, bStitch, 
bFractalNoise, nChannels, bGreyScale, perlinOffset);
       //
    //    Uncomment the following line to see the generated perlin noise
    _root.holder.attachBitmap(bmp, 1, "auto", true);
   
    //Contrast
    var cont = 3.4;
    var contMtx:Array =  Array(cont,0,0,0,128*(1-cont),
                                0,cont,0,0,128*(1-cont),
                                0,0,cont,0,128*(1-cont),
                               0,0,0,1,0);
   
    //Brightness
    var brght = -20;
    var brghtMtx:Array =  Array(1,0,0,0,brght,
                                0,1,0,0,brght ,
                                0,0,1,0,brght ,
                               0,0,0,1,0 );
    
       
    var contFlt = new ColorMatrixFilter(contMtx);
    var brghtFlt = new ColorMatrixFilter(brghtMtx);
    //bmp.applyFilter(bmp, bmp.rectangle, fltPoint, contFlt);
    //bmp.applyFilter(bmp, bmp.rectangle, fltPoint, brghtFlt);
    //Harsh threshold filtering...
    //bmp.threshold(bmp,bmp.rectangle,new Point(0, 
0),"<",0x006f6f6f,0x00000000,0x00FFFFFF);
   


    function animClouds() {
    //change the values in the perlinOffset to animate each perlin layer
    perlinOffset[0].y+=0.5;
    perlinOffset[0].x+=1;
    perlinOffset[1].x-=0.5;
    perlinOffset[1].y-=0.25;
    //    apply perlin noise to our bitmapdata
    bmp.perlinNoise(baseX, baseY, nOctaves, randomSeed, bStitch, 
bFractalNoise, nChannels, bGreyScale, perlinOffset);
       //
    //    Uncomment the following line to see the generated perlin noise
    _root.holder.attachBitmap(bmp, 1, "auto", true);
   
    //Contrast
    var cont = 3.4;
    var contMtx:Array =  Array(cont,0,0,0,128*(1-cont),
                                0,cont,0,0,128*(1-cont),
                                0,0,cont,0,128*(1-cont),
                               0,0,0,1,0);
   
    //Brightness
    var brght = -20;
    var brghtMtx:Array =  Array(1,0,0,0,brght,
                                0,1,0,0,brght ,
                                0,0,1,0,brght ,
                               0,0,0,1,0 );
    
       
    var contFlt = new ColorMatrixFilter(contMtx);
    var brghtFlt = new ColorMatrixFilter(brghtMtx);
    //bmp.applyFilter(bmp, bmp.rectangle, fltPoint, contFlt);
    //bmp.applyFilter(bmp, bmp.rectangle, fltPoint, brghtFlt);
    //Harsh threshold filtering...
    //bmp.threshold(bmp,bmp.rectangle,new Point(0, 
0),"<",0x006f6f6f,0x00000000,0x00FFFFFF);
}



   

Karim Beyrouti wrote:
> Hello groovy list...
>
> I am trying to generate a chrome effect by applying a displacement map to
> Bitmap.
> The Displacement map is generated from perlin noise, and the target is a
> single colour filled bitmap. 
> However it's not working with the single colour filled bitmap 
> (I think it's because there is nothing to displace).
>
> Maybe I am approaching this all wrong, and would appreciate any thoughts. 
>
> Here is my test code so far:
>
>
> <code>
>
> import flash.filters.DisplacementMapFilter;
> import flash.display.BitmapData;
> import flash.geom.Point;
> import flash.geom.Matrix;
> import flash.geom.ColorTransform;
>
> var mapBitmap:BitmapData = new BitmapData ( Stage.width, Stage.height,
> false, 0x000000 );
>       mapBitmap.perlinNoise(100, 100, 10 , 10 , false, false,1 , true,
> null );
>
> var filter:DisplacementMapFilter = new DisplacementMapFilter(mapBitmap,
new
> Point(0, 0),4|8, 4|8, 100, 100, "wrap", .25, .25);
>
> var dBitmap:BitmapData =  new BitmapData ( Stage.width, Stage.height,
false,
> 0x666666 );
>       attachBitmap( dBitmap, 10 );
>       dBitmap.applyFilter( dBitmap, dBitmap.rectangle,new Point( 0, 0 ),
> filter );
>
> </code>
>
>
> P.s. This targets AS2 / FP8....
>
>
>
> Kind regards
>
>
>
> Karim
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
>
>   

-- 

Glen Pike
01326 218440
www.glenpike.co.uk <http://www.glenpike.co.uk>

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to