package { import flash.display.BitmapData; import flash.utils.ByteArray; public class Shadow { public var width:int = 200; public var height:int = 150; public var white:uint = 0xFFFFFF90; // 光の色 黄 public var black:uint = 0x00000000; // 影の色 protected var bytes:ByteArray; protected var bmd:BitmapData; public function Shadow() { bytes = new ByteArray(); bytes.length = width*height/8; bmd = new BitmapData(width, height, true, 0xFF000000); trace("Construct: Shadow"); } public function setPixel(x:int, y:int, pix:Boolean):void{ var i:int = x+y*width; if(pix) bytes[Math.floor(i/8)] &= ~(1<<(i%8)); else bytes[Math.floor(i/8)] |= (1<<(i%8)); } public function getPixel(x:int, y:int):Boolean{ var i:int = x+y*width; if( bytes[ Math.floor(i/8) ]&(1<<(i%8)) ) return false; else return true; } public function getBitmapData():BitmapData{ return bmd; } public function updateBitmapData():void{ bmd.lock(); for(var y:int = 0; y < height; y++){ for(var x:int = 0; x < width; x++){ if(getPixel(x, y)) bmd.setPixel(x, y, black); else bmd.setPixel(x, y, white); } } bmd.unlock(); } public function getByteArray():ByteArray{ return bytes; } public function setByteArray(bytes:ByteArray):void{ this.bytes = bytes; } } }