Brian Chia
       
 
categories
actionscript
actionscript 1.0
actionscript 2.0
misc
 
processing
 
links
brian chia
kelvin zhao
ronald leong
 
 
Pixel Stretch v01
 
Same as the Bitmaps HitTest v01 sample, i use BitmapData.loadBitmap() to load a bitmap from the library. This is more direct rather then creating a new BitmapData instance and using the BitmapData.draw() to create the bitmap.

var bm:BitmapData=BitmapData.loadBitmap("pixelStretch");

Here i use Robert Penner Easing Class to animate the stretching from left to right.
Speed can be adjust through the slidebar.

photography by ronald leong

import flash.display.BitmapData;
import flash.geom.*;
import com.robertpenner.easing.*;

// variables needed for robert penner easing
// set the inital distance

var b:Number=0;
// set the destination distance
var e:Number=500;
// find the diff in distance
var c:Number=e-b;
// set the duration for the tween
var d:Number=200;
// set timer to 0
var t:Number=0;

// create 2 BitmapData instance to load the bitmap
var bm:BitmapData=BitmapData.loadBitmap("pixelStretch");
var bmf:BitmapData=bm.clone();

// create a movieclip to perform the pixel stretch
var mc:MovieClip=createEmptyMovieClip("mc",getNextHighestDepth());
mc._y=15;

this.onEnterFrame=function(){

pixel();

}

function pixel():Void{

// perform easing and return the value into a variable
with(this){

var n:Number=Linear.easeInOut(t++,b,c,d);
if(t>d) delete this.onEnterFrame;

}

var w=bm.width;
var h=bm.height;

// copypixels to ensure a sharp image is created
bmf.copyPixels(bm,new Rectangle(0,0,w,h),new Point(0,0));

while(h--){

// return new rectangle of height 1
var r:Rectangle=new Rectangle(n,h,w,1);
// return an ARGB value that conatin alpha channel and RGB data
// getPixel only return RGB, without the alpha data)

var c:Number=bm.getPixel32(n,h);
// fills a rectangular area of pixels with a specified ARGB color
bmf.fillRect(r,c);

}

// attach bitmap to movieclip
mc.attachBitmap(bmf,1);

}



suggestion

 
 
 
         
  © copyright 2007 THINKLUNATIC.    
Brian Chia Jonathan Ng