Thursday, November 12, 2009

ActionScript Surf Library: FlashSurf

Currently I'm experimenting with FlashSurf library, an alchemy port of popular Surf algorithm which is widely used in machine vision problems like object recognition, 3d reconstruction and augmented reality.

The author, Eugene, does a good job in combining multiple c/c++/java libraries (OpenCV, OpenSurf, libmv SURF, Dlib and JavaSurf) to make Surf algorithm work in AVM.

Check out Eugene Blog for the details. 

He uses TDSI tool written by Joa for further optimization. I check FlashSurf lib with and without TDSI. It boost the speed a lot. I think anyone experimenting with Actionscript/Alchemy should use it.

Keep ActionScript'ing...

Tuesday, November 10, 2009

Snow effect with actionscript 3

Recently, I need some snow effect with actionscript. I search the net for samples, and found one. http://www.tutorio.com/tutorial/flash-snow It was written on ActionScript 2 but the idea was simple.
  • Create several copies of snow Sprite
  • Let the y-velocity of these snow sprites random
  • Let the x-positions of these sprites swing by using sine (or cosine) function. 
With the randomization, the output looks realistic. (It was a 10 minute coding, sorry for the quality).




Just create a movie clip with linkage class name Snow in Flash Proffesional. Put any graphics you want in it (just a small white circle will be fine). Create anothor movie clip on the stage with linkage class name Snowing. Just play with the randomization parameters for different effects.

package 
{
 import flash.display.Sprite;
 import flash.events.Event;

 public class Snow extends Sprite
 {
  private var yVelocity:Number;
  private var xRadius:Number;
  private var xIncrement:Number;
  private var xAngle:Number;
  private var xOrig:Number;
  public function Snow()
  {
   yVelocity = 2 + Math.random() * 5;
   xRadius = 10 + Math.random() * 100;
   xIncrement = 0.001 + Math.random() * 0.05;
   xOrig = Math.random() * 1000;
   xAngle = 2*Math.random()*Math.PI;
   x = xOrig;
   y = Math.random() * 600;
   alpha = 0.2+0.8*Math.random();
   scaleX = scaleY = 0.2+0.8*Math.random();
   addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }
  private function onEnterFrame(e:Event)
  {
   this.y += yVelocity;
   this.x = xOrig + xRadius*Math.sin(xAngle);
   xAngle += xIncrement;
   if (this.y >= 600)
    this.y = 0;
  }
 }
 
}

package 
{
 import flash.display.Sprite;
 
 public class Snowing extends Sprite
 {
  private var numSnow:int = 1000;
  public function Snowing() 
  {
   for (var i = 0; i < numSnow; i++)
   {
    var snow:Snow = new Snow();
    addChild(snow);
   }
  }
  
 }
 
}

Happy snowing...

Wednesday, November 4, 2009

Flash Player 10 - Context Menu not working on Embedded Video

A simple problem: Place an embedded video on stage. Customize context menu using ContextMenu class (flash.ui.ContextMenu). ContextMenuEvent.MENU_ITEM_SELECT event won't fire when you right click on embedded video. Just click on anywhere without video, it will work. If you place a rectangle over the video with 0% alpha fill , it will start working even on the video. This happens with Gaia framework, but i think this is a flash player bug.

I didn't google if someone else having the same problem or not. Just an unimportant experience.