静岡理工科大学 | 菅沼ホーム | ActionScript 目次 | 索引 |
新しい赤 = ( sourceBitmapData の赤 × redMultiplier + 元の赤 × ( 256 - redMultiplier )) ÷ 256
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.filters.BlurFilter; import flash.geom.Point; import flash.geom.Rectangle; [SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="20")] public class BitmapData_filter extends Sprite { public function BitmapData_filter() { init(); } private function init():void { var x1 : int, y1 : int; var bmd1 : BitmapData = new BitmapData(stage.stageWidth/2, stage.stageHeight, true, 0x00000000); var bmd2 : BitmapData = new BitmapData(stage.stageWidth/2, stage.stageHeight, true, 0x00000000); for(x1 = 25; x1 <= 125; x1++) { for(y1 = 50; y1 <= 150; y1++) bmd1.setPixel32(x1, y1, 0xff00ff00); } var bm1 : Bitmap = new Bitmap(bmd1); var bm2 : Bitmap = new Bitmap(bmd2); bm2.x = 150; addChild(bm1); addChild(bm2); var rect : Rectangle = bmd1.generateFilterRect(new Rectangle(0,0,75,200), new BlurFilter(5,5,3)); bmd2.applyFilter(bmd1, rect, new Point(-5,-5), new BlurFilter(5,5,3)); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Rectangle; import flash.geom.Point; import flash.geom.ColorTransform; [SWF(backgroundColor="0xeeffee", width="400", height="200", frameRate="20")] public class BitmapData_colorTrans extends Sprite { public function BitmapData_colorTrans() { init(); } private function init():void { // オリジナル var bmd1 : BitmapData = new BitmapData(50, 100, true, 0xffffff00); var bm1 : Bitmap = new Bitmap(bmd1); bm1.x = 25; bm1.y = 50; addChild(bm1); // colorTransform var bmd2 : BitmapData = bmd1.clone(); bmd2.colorTransform(new Rectangle(0, 0, 50, 100), new ColorTransform(1, 0, 0, 1, 0, 0, 255, 0)); var bm2 : Bitmap = new Bitmap(bmd2); bm2.x = 100; bm2.y = 50; addChild(bm2); // merge var bmd3 : BitmapData = new BitmapData(50, 100, true, 0xff0000ff); bmd3.merge(bmd1, new Rectangle(0, 0, 50, 50), new Point(0, 0), 0, 256, 0, 0); var bm3 : Bitmap = new Bitmap(bmd3); bm3.x = 175; bm3.y = 50; addChild(bm3); // threshold var bmd4 : BitmapData = bmd3.clone(); bmd4.threshold(bmd4, new Rectangle(0, 0, 50, 100), new Point(0, 0), "==", 0xff00ff00, 0xffffff00, 0xff00ff00); var bm4 : Bitmap = new Bitmap(bmd4); bm4.x = 250; bm4.y = 50; addChild(bm4); // paletteMap var bmd5 : BitmapData = bmd4.clone(); var R : Array = new Array(); var G : Array = new Array(); var B : Array = new Array(); for (var i1 : int = 0; i1 < 256; i1++) { R[i1] = 0 << 16; if (i1 == 255) G[i1] = 255 << 8; else G[i1] = 0 << 8; B[i1] = 0; } bmd5.paletteMap(bmd5, new Rectangle(0, 0, 50, 100), new Point(0, 0), R, G, B, null); var bm5 : Bitmap = new Bitmap(bmd5); bm5.x = 325; bm5.y = 50; addChild(bm5); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; [SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="20")] public class BitmapData_compare extends Sprite { public function BitmapData_compare() { init(); } private function init():void { var bmd1 : BitmapData = new BitmapData(50, 100, true, 0xffffff00); var bmd2 : BitmapData = new BitmapData(50, 100, true, 0xff00ff00); var bmd3 : BitmapData = bmd1.compare(bmd2) as BitmapData; var bm1 : Bitmap = new Bitmap(bmd1); var bm2 : Bitmap = new Bitmap(bmd2); var bm3 : Bitmap = new Bitmap(bmd3); bm1.x = 50; bm1.y = 50; bm2.x = 125; bm2.y = 50; bm3.x = 200; bm3.y = 50; addChild(bm1); addChild(bm2); addChild(bm3); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BitmapDataChannel; import flash.geom.Rectangle; import flash.geom.Point; [SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="20")] public class BitmapData_copyC extends Sprite { public function BitmapData_copyC() { init(); } private function init():void { var bmd1 : BitmapData = new BitmapData(75, 100, true, 0xff0000ff); var bmd2 : BitmapData = new BitmapData(75, 100, true, 0xff00ff00); bmd2.copyChannel(bmd1, new Rectangle(0, 0, 75, 50), new Point(0, 50), BitmapDataChannel.BLUE, BitmapDataChannel.RED); var bm1 : Bitmap = new Bitmap(bmd1); var bm2 : Bitmap = new Bitmap(bmd2); bm1.x = 50; bm1.y = 50; bm2.x = 175; bm2.y = 50; addChild(bm1); addChild(bm2); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Rectangle; import flash.geom.Point; [SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="20")] public class BitmapData_copyP extends Sprite { public function BitmapData_copyP() { init(); } private function init():void { var bmd1 : BitmapData = new BitmapData(75, 100, true, 0xffffff00); var bmd2 : BitmapData = new BitmapData(75, 100, true, 0xff00ff00); var bmd3 : BitmapData = new BitmapData(75, 25, true, 0x000000ff); for(var x1:int = 25; x1 <= 50; x1++) { for(var y1:int = 0; y1 <= 25; y1++) bmd3.setPixel32(x1, y1, 0xff0000ff); } bmd2.copyPixels(bmd1, new Rectangle(0, 0, 75, 25), new Point(0, 50), bmd3, new Point(0, 0), true); bmd2.copyPixels(bmd1, new Rectangle(0, 0, 75, 25), new Point(0, 75), bmd3, new Point(0, 0), false); var bm1 : Bitmap = new Bitmap(bmd1); var bm2 : Bitmap = new Bitmap(bmd2); bm1.x = 50; bm1.y = 50; bm2.x = 175; bm2.y = 50; addChild(bm1); addChild(bm2); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Matrix; [SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="20")] public class BitmapData_draw extends Sprite { public function BitmapData_draw() { init(); } private function init():void { var bmd1 : BitmapData = new BitmapData(200, 100, true, 0xffffff00); var bmd2 : BitmapData = new BitmapData(100, 50, true, 0xff00ff00); var ang : Number = 30.0 * Math.PI / 180.0; var mtx : Matrix = new Matrix(Math.cos(ang), Math.sin(ang), -Math.sin(ang), Math.cos(ang), 75, 5); bmd1.draw(bmd2, mtx); var bm1 : Bitmap = new Bitmap(bmd1); bm1.x = 50; bm1.y = 50; addChild(bm1); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Rectangle; [SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="20")] public class BitmapData_fill extends Sprite { public function BitmapData_fill() { init(); } private function init():void { var x1 : int, y1 : int; var bmd1 : BitmapData = new BitmapData(80, 100, true, 0xffffff00); // 左 bmd1.fillRect(new Rectangle(20,20,3,3), 0xffff0000); bmd1.fillRect(new Rectangle(30,40,3,3), 0xffff0000); bmd1.fillRect(new Rectangle(40,70,3,3), 0xffff0000); bmd1.fillRect(new Rectangle(58,78,3,3), 0xffff0000); var bm1 : Bitmap = new Bitmap(bmd1); bm1.x = 15; bm1.y = 50; addChild(bm1); // 中央 var bmd2 : BitmapData = bmd1.clone(); bmd2.fillRect(bmd2.getColorBoundsRect(0xffffffff, 0xffff0000, true), 0xff00ff00); var bm2 : Bitmap = new Bitmap(bmd2); bm2.x = 110; bm2.y = 50; addChild(bm2); // 右 var bmd3 : BitmapData = bmd2.clone(); bmd3.floodFill(40, 50, 0xff0000ff); var bm3 : Bitmap = new Bitmap(bmd3); bm3.x = 205; bm3.y = 50; addChild(bm3); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Point; [SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="20")] public class BitmapData_hit extends Sprite { public function BitmapData_hit() { init(); } private function init():void { var bmd1 : BitmapData = new BitmapData(80, 50, true, 0xffffff00); var bmd2 : BitmapData = new BitmapData(80, 50, true, 0xff00ff00); var bmd3 : BitmapData = bmd1.clone(); var bmd4 : BitmapData = bmd2.clone(); // 接触 var bm1 : Bitmap = new Bitmap(bmd1); var bm2 : Bitmap = new Bitmap(bmd2); bm1.x = 50; bm1.y = 50; bm2.x = 60; bm2.y = 90; addChild(bm1); addChild(bm2); trace(bmd1.hitTest(new Point(50, 50), 0x00, bmd2, new Point(60, 90), 0x00)); // 非接触 var bm3 : Bitmap = new Bitmap(bmd3); var bm4 : Bitmap = new Bitmap(bmd4); bm3.x = 160; bm3.y = 50; bm4.x = 170; bm4.y = 100; addChild(bm3); addChild(bm4); trace(bmd3.hitTest(new Point(160, 50), 0x00, bmd4, new Point(170, 100), 0x00)); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Rectangle; [SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="20")] public class BitmapData_scroll extends Sprite { public function BitmapData_scroll() { init(); } private function init():void { // スクロール前 var bmd1 : BitmapData = new BitmapData(75, 100, true, 0xff00ff00); bmd1.fillRect(new Rectangle(17,25,40,50), 0xffffff00); var bm1 : Bitmap = new Bitmap(bmd1); bm1.x = 50; bm1.y = 50; addChild(bm1); // スクロール後 var bmd2 : BitmapData = bmd1.clone(); var bm2 : Bitmap = new Bitmap(bmd2); bm2.x = 175; bm2.y = 50; addChild(bm2); bmd2.scroll(40, 30); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Point; import flash.geom.Rectangle; import flash.events.Event; [SWF(backgroundColor="0xeeffee", width="500", height="200", frameRate="5")] public class BitmapData_noise extends Sprite { private var bmd1 : BitmapData; private var bmd2 : BitmapData; private var bmd3 : BitmapData; private var seed : int = 123; public function BitmapData_noise() { init(); } private function init():void { bmd1 = new BitmapData(100, 100, true, 0xffffffff); var bm1 : Bitmap = new Bitmap(bmd1); bm1.x = 50; bm1.y = 50; addChild(bm1); bmd2 = bmd1.clone(); var bm2 : Bitmap = new Bitmap(bmd2); bm2.x = 200; bm2.y = 50; addChild(bm2); bmd3 = bmd1.clone(); var bm3 : Bitmap = new Bitmap(bmd3); bm3.x = 350; bm3.y = 50; addChild(bm3); addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame(event:Event):void { bmd1.noise(1000 * Math.random()); seed = bmd2.pixelDissolve(bmd2, new Rectangle(0, 0, 100,100), new Point(0, 0), seed, 100, 0xffff0000); bmd3.perlinNoise(100, 50, 3, seed, true, true); } } }
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.events.Event; [SWF(backgroundColor="0x000000", width="300", height="200", frameRate="20")] public class BitmapData_color extends Sprite { private var bmd : BitmapData; private var color : uint; private var c_x : int, c_y : int; private var count : int = 0; private var r : int = 0; public function BitmapData_color() { init(); } private function init():void { bmd = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000); var bm : Bitmap = new Bitmap(bmd); addChild(bm); addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame(event:Event):void { var r1 : int; var x1 : int; var x2 : Number; var y1 : int; var y2 : Number; if (count == 0) { color = Math.random() * 0xffffff + 0xff000000; c_x = Math.random() * stage.stageWidth; c_y = Math.random() * stage.stageHeight; } for(x1 = c_x-25; x1 <= c_x+25; x1++) { for(y1 = c_y-25; y1 <= c_y+25; y1++) { x2 = c_x - x1; y2 = c_y - y1; r1 = Math.round(Math.sqrt(x2 * x2 + y2 * y2)); if (r1 == r) bmd.setPixel32(x1, y1, color); } } r += 5; count++; if (count > 5) { count = 0; r = 0; } } } }
静岡理工科大学 | 菅沼ホーム | ActionScript 目次 | 索引 |