Tag Archive for 'source'

Steering Behaviors AS3 lib

Steering Behaviors in 3D

Last week I was working on project where I needed one of my not very old experiment as base. It was about creating a game using steering behaviors logic. I was playing with this stuff some time ago and now I’ve to re-factor it. So why not to create a public lib for simple usage. The main goal of re-factoring was to make usage as simple as possible, also giving users an ability to add their own behaviors easy. The second point is performance (all iterations done using Linked Lists). This lib doesn’t have all possible behaviors and may be you wont find smth you are looking for but as for me I think that it simple enough to add new ideas in minutes!
I’ve included examples in the sources to show the basic usage. One of the examples is using Away3DLite library for 3D rendering. (you have to download lib yourself)

You can get the sources here

Old examples from my blog:

Steering Behaviors in 3D | Flocking
Steering Behaviors in 3D

FlashSURF Lib [initial release]

Flash SURF

Finally I finished all needed preparations for the first initial release of FlashSURF Lib. You’ve already seen some videos posted in twitter. Now I’m publishing all the sources to my google repo. I think this project has a lot of opportunities and I’m really waiting for the response from Flash Community with the advices, ideas, etc on how to improve or what to add and so on…
Currently it supports basic features extraction, matching them to provided reference image and estimating projection matrix between correspondences (Homography). This is the start point to try implement marker-less Augmented Reality or panorama building application or images searching etc. As you see there are tons of ideas in what direction to extend it and I hope you will share yours with me and others as I did. In this case we can end up with smth interesting and useful for everyone!

P.S.: This project is using Joa’s TDSI Tool!

Here you will find all the sources and small test application where I tried to describe the main features of the library.

And here is some videos and another reconstructed panorama:
Talking about FlashSURF at Flash2000 Event
My first tests of the library

Flash SURF

Adaptive Thresholding using Integral Image [source]

Adaptive Thresholding

I have to admit that built in Flash methods is really fast in processing time and I cant beat the speed of blurred adaptive thresholding versions provided by Mario and Saqoosha. I still think it could perform faster… ;) Talking about thresholding result I cant say which one is more accurate – try it yourself.
Continue reading ‘Adaptive Thresholding using Integral Image [source]‘

Canny Edge Detector [AS3 + PixelBender]

Canny Edge Detector

The Canny edge detection operator was developed by John F. Canny in 1986 and uses a multi-stage algorithm to detect a wide range of edges in images.
While researching motion tracking questions I’ve faced Canny Detector and thought it would be great to run it in Flash. My first approach was to code it in pure AS3, ofcourse I failed. It uses lots of computations in 2D loops so Flash version was running at 12 FPS from 33 required. That time Mario Klingemann released his files from old presentation about image processing and BitmapData thresholding in general. I’ve noticed it was using PixelBender to threshold BitmapData objects. That was an idea!
I’ve never used pixelbender before so it was a little pain to learn whats going on there, also no traces available is terrible. It’s a long story to tell ya ;) finally we have 6 pixelbender filters and one flash class to handle detection. It runs pretty fast but I guess someone can do it even faster cause it was my first try and I dont know all bender possibilities.

See demo application (you will need web camera and Flash 10 installed)
Sources can be accessed in my Google repo
And here is some demo videos from developing timeline and more screenshots:
First version in pure AS3
First attemp in pixelbender

Canny Edge Detector
Canny Edge Detector
Canny Edge Detector
Canny Edge Detector

Multipart URLLoader Class updated

I’ve received some requests to update my Multipart URLLoader Class with additional features and to make it more customizable. So here we go! Complete source code and test usage example with small PHP script available in my Google Code repository.

UPDATES:
version 1.3
- Added Async property. Now you can prepare data asynchronous before sending it.
- It will prevent flash player from freezing while constructing request data.
- You can specify the amount of bytes to write per iteration through BLOCK_SIZE static property.
- Added events for asynchronous method.
- Added dataFormat property for returned server data.
- Removed ‘Cache-Control’ from headers and added custom requestHeaders array property.
- Added getter for the URLLoader instance used to send data.

Multipart form data in as3 [Class version 1.2]

During my last project I faced a problem to upload multipart/form-data to server using Flash. I need to do it using ActionScript only. The idea was to send to server an image generated in flash and several variables but all this data had to be POST.
I found several projects that were using Flash Socket to send multipart requests to server but the problem was that sockets required custom server configuration to work. As you understand we cant ask remote service to reconfigure their system only because we need it.
So the only way was to build your own custom URLLoader class (not socket) to send multipart form data. Ok, no more words (I hate all this typings) here is simple but usefull (as I think) MultipartURLLoader class. You will find source and small samples with php script inside.
Unfortunately there is a problem getting progress event. We cant show any progress during sending data to server because flash doesnt support it. (the same problem with sockets)

LATEST VERSION UPLOADED TO GOOGLE CODE

UPDATES:
version 1.1
- Added options for MIME-types (default is application/octet-stream)
version 1.2
- Added clearVariables and clearFiles methods
- Small code refactoring
- Public methods documentaion

in short we can add variables and files to loader class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import flash.utils.ByteArray;
import ru.inspirit.net.MultipartURLLoader;
 
var data1:ByteArray = new ByteArray();
data1.writeUTFBytes("This is a test 1");
data1.position = 0;
 
var data2:ByteArray = new ByteArray();
data2.writeUTFBytes("This is a test 2");
data2.position = 0;
 
var ml:MultipartURLLoader = new MultipartURLLoader();
ml.addEventListener(Event.COMPLETE, onReady);
 
function onReady(e:Event):void
{
	// Upload Complete
}
 
// simple string data
ml.addVariable('test', 'test variable');
 
// file data: ByteArray, File name, Name of the file field, content MIME type (default application/octet-stream)
// use [] if you need identical file field name
// specify MIME type for your file part
ml.addFile(data1, 'test1.txt', 'Filedata[]');
ml.addFile(data2, 'test2.txt', 'Filedata[]', 'text/plain');
 
ml.load('test.php');

Generative art: Voronoi Fractal

I found some posts about Voronoi diagrams [Convex Hull and Things to learn by KP, Delaunay Class by Nicoptere, Voronoi tessels by Frank Reitberger]
But all of the representations not what I wanted it to be. Nicoptere’s port of Delaunay class is great and really fast but it doesn’t give you an ability to draw Voronoi diagrams with fill and stroke controls.
Then Frank’s method is pretty fast and with fills BUT it is using BitmapData flood fill to make color cells, as you guess this is not good at all.

After some research I decided to use Fortunes algorithm with Sweep Point method for my Voronoi diagrams. The bad thing is that Flash is still very slow in Math :( We need lots of calculations recursive checks and that can completely hangs Flash Player, especially with moving points… Some times it can take up to 10 seconds to generate Fractals so be patient ;)

[SOURCES]

Enough words lets see what we can produce in Flash (use controls at the top of the movie):

Voronoi Fractal
Voronoi Fractal with strokes
Voronoi Moving points
Voronoi with circle borders