topical media & game development

talk show tell print

shader-vortex.mx

shader-vortex.mx [swf] [flash] flex


  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
  xmlns:ae="*"
  layout="absolute"
  backgroundColor="#000000"
  applicationComplete="complete()">
  
          <mx:Script>
                  <![CDATA[
                          import flash.filters.*;
                          import flash.utils.ByteArray;        
                          import flash.utils.getTimer;  
                          
                          //[SWF(width="512",height="512",frameRate="60",backgroundColor="#000000")]        
  
                          //the file that contains the binary bytes of the PixelBender filter
                          [Embed("shader-vortex.pbj", mimeType="application/octet-stream")]
                          private var CustomFilter:Class;        
              private function click ( event:MouseEvent ):void
              {
                  myLabel.text = "hello world";
              }
                          
  

camera -- as usual


              import flash.media.Camera;
              private var camera:Camera; 
    
              private function attach() : void {
              //stack.selectedIndex = state; // activate before attach
              camera = Camera.getCamera();
              ca.attachCamera(camera);
              //stack.selectedIndex = state; // delay until ready
              }
  
  

next / display(s)


  
                          private var state:Number = 0;
                          private var max:Number = 4;
                          
                          private function next():void {
                          state+=1;
                          if (state >= max) state = 0;
                          stack.selectedIndex = state;
                          //if (state == 2) attach();
                          }
  
                      private var offsetU : Number = 0;
                  private var offsetV : Number = 0;
              private var easeX : Number = 0;
              private var easeY : Number = 0;                        
                          
  
  

loop / effect(s)


              private function loop(e : Event) : void {
                            offsetU = getTimer() * 0.0001;
                            offsetV = getTimer() * 0.0002;
                           
                            easeX += (stage.mouseX - easeX) * .1;
                            easeY += (stage.mouseY - easeY) * .1;
                           
                         
                            shader.data.center.value = [easeX,easeY];
                            shader.data.offset.value = [offsetU,offsetV]
                            stack.filters = [filter];       
              }
  
  

on completion


              private var shader:Shader;
              private var filter:ShaderFilter;
                
                          private function complete():void
                          {
                                  //Pass the loaded filter to the Shader as a ByteArray
                                  shader = new Shader(new CustomFilter() as ByteArray);
                                  
                                  if (0) {
                                  shader.data.size.value = [20.0];
                                  } else if (1) {
                                  shader.data.imgSize.value = [512,512];
                  shader.data.center.value = [200.0,200.0];
                  shader.data.offset.value = [0,0];
                  }        
                      
                                  filter = new ShaderFilter(shader);
  
                                  //add the filter to the image
                                  stack.filters = [filter];
                                  stage.addEventListener(Event.ENTER_FRAME, loop);
                          }
                  ]]>
          </mx:Script>
          
  

component(s)


  
      <ae:component_screen id="display"/>
      <mx:ViewStack id="stack" width="100%" height="100%">
          <mx:Canvas>
          <mx:Image id="im" click="next();" right="0" left="0" top="0" bottom="0" maintainAspectRatio="false" source="@Embed(source='soutine.jpg')"/>
          </mx:Canvas>
          <mx:Canvas>
          <mx:Image id="vd"  click="next();"  right="0" left="0" top="0" bottom="0" maintainAspectRatio="false" source="@walk.png"/>
          </mx:Canvas><mx:Canvas>
          <mx:VideoDisplay id="ca"  click="next();" right="0" left="0" top="0" bottom="0" maintainAspectRatio="false" source="../assets/clips/tube/balloon.flv"/>
      </mx:Canvas>
      <mx:Panel title="hello world" horizontalAlign="center" click="click(event);"
          paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
          <mx:Label id="myLabel" width="180" fontWeight="bold" fontSize="24"/>
          <mx:Button id="myButton" label="click me!" click="click(event);" />
      </mx:Panel>
      </mx:ViewStack>
      <mx:HBox right="5" top="10">
      <mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="camera" click="attach();"/>
      </mx:HBox>
      <mx:HBox left="5" bottom="10">
      <mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="next" click="next();"/>
      <mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="click" click="next();"/>
      </mx:HBox>
      <mx:HBox right="5" bottom="10">
      <mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="stop" click="ca.stop();"/>
      <mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="play" click="ca.play();"/>
      <mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="fullscreen" click="display.toggle();"/>
      </mx:HBox>
  </mx:Application>
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.