1 0 Archive | processing RSS feed for this section

Pixel Based Operations in Flash and Processing

Recently, I have been working on many pixel level projects with Flash. My experience with these projects was somewhat disappointing when it came to Flash’s rendering of pixel based effects. A normal pixel based operation in Processing would not take more than 10% of your CPU, where Flash would take up to 50% of your CPU. Some functions such as ‘set vertex/point/pixel(position)’ (available in many graphic APIs these days) seem to be missing in Flash and are only available for a specific class called the BitmapData class. Performing pixel manipulations on this class can render things fast but still not fast enough. I hope Flash CS4 brings its attention towards this.

Overall, Processing is very efficient than Flash regarding pixel based operations. I have gone through many article systems made for Flash and their performance stays best to heavy CPU usage even with the use of AS3. For example, Flint, is a very good particle system but suffers with the same problems. Although, it is fairly obvious from the way Flash was designed that pixel level operations were not given a priority but I feel this takes a big chunk of users right out of Flash’s community.

Take the following example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import flash.display.Bitmap;
import flash.display.BitmapData;
 
var myBitmapData:BitmapData = new BitmapData(500,500, true, 0xffffff);
 
var myBitmapImage:Bitmap = new Bitmap(myBitmapData);
myBitmapImage.cacheAsBitmap = true;
myBitmapImage.smoothing = true;
addChild(myBitmapImage);
 
function DrawNoise(e:Event):void
{
for (var i:int = 0; i < 10000; i++)
{
var pcolor:uint = 0x50000000;
myBitmapData.setPixel32(Math.random() * 500,Math.random() * 500,pcolor);
}
}
this.addEventListener(Event.ENTER_FRAME,DrawNoise);

Run this program in Flash AS3 and you’ll notice how much CPU is used running such a simple example. Creating sprites would take that meter to 75% at times. Run the same example in Processing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void setup()
{
size(500,500,P3D);
}
 
void draw()
{
stroke(0,5);
 
beginShape(POINTS);
 
for (int i = 0; i < 10000; i++)
{
vertex(random(500),random(500));
}
endShape();
}

The difference should be very obvious. If you have seen Flash CS4 features and the Quake Demo running on AS4, you might feel happy to think that Flash CS4 would pay much attention to the rendering engine currently used by Flash. Mostly in all cases, I give Processing an edge over many aspects of graphics routines that Flash lacks for the time being. If you’re into Particle based systems, Flash is not the tool for you.

M.H.A.Q.S.

Read full story »