root/as3/Astro/RadialBlur/src/Main.mxml

リビジョン 1540, 3.5 kB (コミッタ: muta, コミット時期: 3 年 前)

PixelBender? のサンプル.

Line 
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
3     width="340" height="400" backgroundGradientAlphas="[1.0, 1.0]"
4     backgroundGradientColors="[#FFFFFF, #DDDDDD]" applicationComplete="init()">
5
6     <mx:Script>
7         <![CDATA[
8        
9         import flash.display.Bitmap;
10         import flash.display.Sprite;
11         import flash.events.MouseEvent;
12        
13         [Embed (source="sunflower.jpg")]
14         private var _imageClass:Class;
15        
16         private var _bitmap:Bitmap;
17         private var _anchor:Sprite;
18         private var _filter:RadialBlurFilter;
19        
20         private function init():void
21         {
22             _bitmap = image.addChild(new _imageClass()) as Bitmap;
23            
24             _anchor = image.addChild(new Sprite()) as Sprite;
25             _anchor.x = _bitmap.width / 2;
26             _anchor.y = _bitmap.height / 2;
27             _anchor.graphics.lineStyle(1, 0xFF0000);
28             _anchor.graphics.beginFill(0xFF0000, 0.3);
29             _anchor.graphics.drawCircle(0, 0, 7);
30             _anchor.graphics.endFill();
31             _anchor.buttonMode = true;
32            
33             _anchor.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
34            
35             _filter = new RadialBlurFilter(_bitmap.width / 2, _bitmap.height / 2);
36            
37             _bitmap.filters = [_filter];
38            
39             image.addEventListener(MouseEvent.MOUSE_MOVE, applyFilter);
40         }
41        
42         private function mouseDown(e:MouseEvent):void
43         {
44             _anchor.startDrag(true, _bitmap.getBounds(image));
45             _anchor.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
46             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
47         }
48        
49         private function mouseUp(e:MouseEvent):void
50         {
51             _anchor.stopDrag();
52             _anchor.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);
53             stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);
54         }
55        
56         private function applyFilter(e:MouseEvent = null):void
57         {
58             try
59             {
60                 _filter.centerX = _anchor.x;
61                 _filter.centerY = _anchor.y;
62                 _filter.amount = amountSlider.value;
63                 _filter.rotation = rotationSlider.value;
64                
65                 _bitmap.filters = [_filter];
66             }
67             catch (e:Error)
68             {
69                
70             }
71         }
72        
73         ]]>
74     </mx:Script>
75
76     <mx:Image x="10" y="10" width="320" height="320" id="image"/>
77
78     <mx:Label x="10" y="370" text="角度" width="41" fontSize="12" textAlign="right"/>
79     <mx:Label x="10" y="341" text="適用量" width="41" fontSize="12" textAlign="right"/>
80
81     <mx:HSlider x="55" y="338" height="20" width="228" maximum="100" minimum="1"
82         id="amountSlider" value="{Number(amountInput.text)}"
83         change="applyFilter()"/>
84     <mx:TextInput x="290" y="341" width="40" height="20" textAlign="right"
85         id="amountInput" text="{amountSlider.value}"
86         change="applyFilter()"/>
87
88     <mx:HSlider x="55" y="367" height="20" width="228" minimum="-90" maximum="90"
89         id="rotationSlider" value="{Number(rotationInput.text)}"
90         change="applyFilter()"/>
91     <mx:TextInput x="290" y="370" width="40" height="20" textAlign="right"
92         id="rotationInput" text="{rotationSlider.value}"
93         change="applyFilter()"/>
94
95 </mx:Application>
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。