Here is code:
package {
//
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
//
public class RePainting4 extends Sprite {
//
private var _img:Bitmap;
private var _bmp:BitmapData;
private var _bmp2:BitmapData;
private var _point:Point;
private var _rect:Rectangle;
private var _con:MovieClip;
private var _cf:ColorTransform;
private var _dot:Dot;
private var _xc:int;
private var _yc:int;
private var _tw:Number;
private var _th:Number;
private var _press:Boolean;
//
public function RePainting4():void {
//
_init();
}
//
private function _init():void {
_bmp = new BitmapData(img_mc.width, img_mc.height);
_bmp2 = new BitmapData(300, 300);
_con = new MovieClip();
_cf = new ColorTransform();
_point = new Point(0, 0);
_rect = new Rectangle(91, 48, 391, 348);
_xc = 0;
_yc = 0;
_tw = img_mc.width;
_th = img_mc.height;
_press = true;
//
this.addChild(_con);
_bmp.draw(img_mc);
_bmp2.copyPixels(_bmp, _rect, _point);
_img = new Bitmap(_bmp2);
_con.addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
//
private function _onEnterFrame(event:Event):void {
//
if(_press) {
//
_dot = new Dot();
var mc:MovieClip = event.target as MovieClip;
var nx:Number = Math.round(Math.random()*300);
var ny:Number = Math.round(Math.random()*300);
//
_cf = _dot.transform.colorTransform;
_cf.color = _bmp2.getPixel(nx, ny);
_dot.transform.colorTransform = _cf;
mc.addChild(_dot);
//
_dot.scaleX = _dot.scaleY = Math.random()*(0.5-0.1)+0.1;
_dot.rotation = Math.random()*90;
_dot.x = nx;
_dot.y = ny;
}
}
}
}
- Sep 20 Thu 2007 01:20
BitmapData practice2
close
全站熱搜
留言列表