|
| 1 | +package { |
| 2 | + import flash.display.Sprite; |
| 3 | + import flash.display.Bitmap; |
| 4 | + import flash.display.BitmapData; |
| 5 | + import flash.filters.BevelFilter; |
| 6 | + import flash.filters.BitmapFilter; |
| 7 | + import flash.filters.BlurFilter; |
| 8 | + import flash.filters.ColorMatrixFilter; |
| 9 | + import flash.filters.ConvolutionFilter; |
| 10 | + import flash.filters.DropShadowFilter; |
| 11 | + import flash.filters.GlowFilter; |
| 12 | + import flash.filters.GradientBevelFilter; |
| 13 | + import flash.filters.GradientGlowFilter; |
| 14 | + import flash.geom.Point; |
| 15 | + import flash.geom.Rectangle; |
| 16 | + |
| 17 | + [SWF(width="600", height="500")] |
| 18 | + public class Test extends Sprite { |
| 19 | + private static var BG_CELL_SIZE:uint = 9; |
| 20 | + private static var IMAGE_SIZE:uint = 100; |
| 21 | + |
| 22 | + public function Test():void { |
| 23 | + var bg:BitmapData = createCheckeredBackground( |
| 24 | + stage.stageWidth, |
| 25 | + stage.stageHeight |
| 26 | + ); |
| 27 | + addChild(new Bitmap(bg)); |
| 28 | + |
| 29 | + var src:BitmapData = createSource(); |
| 30 | + var count:uint = 0; |
| 31 | + |
| 32 | + addImage(count++, src); |
| 33 | + addImage(count++, testFilter(src, new BlurFilter(), new Point(5, 5))); |
| 34 | + addImage(count++, testFilter(src, new BlurFilter(), new Point(-10, -10))); |
| 35 | + addImage(count++, testFilter(src, new BlurFilter(8, 8, 2), new Point(-20, -5))); |
| 36 | + addImage(count++, testFilter(src, new GlowFilter(), new Point(-15, -15))); |
| 37 | + addImage(count++, testFilter(src, new DropShadowFilter(), new Point(-10, -10))); |
| 38 | + addImage(count++, testFilter(src, new BevelFilter(), new Point(-10, -10))); |
| 39 | + addImage(count++, testFilter(src, new ColorMatrixFilter(), new Point(-10, -10))); |
| 40 | + addImage(count++, testFilter(src, new ConvolutionFilter(3, 3, [0, -1, 0, -1, 5, -1, 0, -1, 0]), new Point(-10, -10))); |
| 41 | + addImage(count++, testFilter(src, new GradientGlowFilter(), new Point(-10, -10))); |
| 42 | + addImage(count++, testFilter(src, new GradientBevelFilter(), new Point(-10, -10))); |
| 43 | + addImage(count++, testFilter(src, new BlurFilter(), new Point(-50, -50))); |
| 44 | + addImage(count++, testFilter(src, new BlurFilter(), new Point(-5, 10))); |
| 45 | + addImage(count++, testFilter(src, new BlurFilter(), new Point(10, -5))); |
| 46 | + addImage(count++, testFilter(src, new BlurFilter(), new Point(-100, -100))); |
| 47 | + addImage(count++, testFilter(src, new BlurFilter(), new Point(-99, -99))); |
| 48 | + addImage(count++, testFilter(src, new GlowFilter(0xFF0000), new Point(-10, -10))); |
| 49 | + addImage(count++, testFilter(src, new DropShadowFilter(4, 45, 0, 1, 4, 4), new Point(-10, -10))); |
| 50 | + } |
| 51 | + |
| 52 | + private function createCheckeredBackground(width:uint, height:uint):BitmapData { |
| 53 | + var bg:BitmapData = new BitmapData(width, height, false, 0xFFFFFFFF); |
| 54 | + for (var x:uint = 0; x < width; x += BG_CELL_SIZE) { |
| 55 | + for (var y:uint = 0; y < height; y += BG_CELL_SIZE) { |
| 56 | + var color:uint = 0xFFEEEEEE; |
| 57 | + if ((x / BG_CELL_SIZE + y / BG_CELL_SIZE) % 2 == 0) { |
| 58 | + color = 0xFFBBBBBB; |
| 59 | + } |
| 60 | + bg.fillRect(new Rectangle(x, y, BG_CELL_SIZE, BG_CELL_SIZE), color); |
| 61 | + } |
| 62 | + } |
| 63 | + return bg; |
| 64 | + } |
| 65 | + |
| 66 | + private function createSource():BitmapData { |
| 67 | + var src:BitmapData = new BitmapData(IMAGE_SIZE, IMAGE_SIZE, true, 0x00000000); |
| 68 | + |
| 69 | + for (var row:uint = 0; row < 10; row++) { |
| 70 | + for (var col:uint = 0; col < 10; col++) { |
| 71 | + var rd:Number = (row + 1) / 10; |
| 72 | + var cd:Number = (col + 1) / 10; |
| 73 | + var a:Number = 0.8; |
| 74 | + var r:Number = 1 - rd; |
| 75 | + var g:Number = rd; |
| 76 | + var b:Number = cd; |
| 77 | + var color:uint = ((int(a * 0xFF) & 0xFF) << 24) | |
| 78 | + ((int(r * 0xFF) & 0xFF) << 16) | |
| 79 | + ((int(g * 0xFF) & 0xFF) << 8) | |
| 80 | + ((int(b * 0xFF) & 0xFF) << 0); |
| 81 | + src.fillRect( |
| 82 | + new Rectangle(col * 10, row * 10, 10, 10), |
| 83 | + color |
| 84 | + ); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + src.fillRect(new Rectangle(IMAGE_SIZE / 2 - 2, 5, 4, IMAGE_SIZE - 10), 0xFF000000); |
| 89 | + src.fillRect(new Rectangle(5, IMAGE_SIZE / 2 - 2, IMAGE_SIZE - 10, 4), 0xFF000000); |
| 90 | + |
| 91 | + return src; |
| 92 | + } |
| 93 | + |
| 94 | + private function addImage(count:uint, img:BitmapData):void { |
| 95 | + var bitmap:Bitmap = new Bitmap(img); |
| 96 | + var cols:uint = Math.floor(stage.stageWidth / IMAGE_SIZE); |
| 97 | + bitmap.x = (count % cols) * IMAGE_SIZE; |
| 98 | + bitmap.y = uint(count / cols) * IMAGE_SIZE; |
| 99 | + addChild(bitmap); |
| 100 | + } |
| 101 | + |
| 102 | + private function testFilter(src:BitmapData, filter:BitmapFilter, destPoint:Point):BitmapData { |
| 103 | + var dst:BitmapData = new BitmapData(IMAGE_SIZE, IMAGE_SIZE, true, 0x00000000); |
| 104 | + var sourceRect:Rectangle = new Rectangle(0, 0, IMAGE_SIZE, IMAGE_SIZE); |
| 105 | + dst.applyFilter(src, sourceRect, destPoint, filter); |
| 106 | + return dst; |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments