As I was working around at my next blog entry I started to play around a bit in pixel bender, I can’t use the result for the next post so here it is seperatly.
This pixel bender project just paints a check pattern inside transparent areas of a bitmap. Its not very stylish or sophisticated but it might still be useful. Feel free to use!
Example:
package
{
import flash.net.*;
import flash.display.*;
import flash.events.Event;
import flash.filters.ShaderFilter;
public class Main extends Sprite
{
private var _loader: URLLoader;
private var _image: Bitmap;
public function Main()
{
_image = new Bitmap( new SampleImage( 0, 0 ) );
_loader = new URLLoader();
_loader.dataFormat = URLLoaderDataFormat.BINARY;
_loader.addEventListener( Event.COMPLETE, handleComplete );
_loader.load( new URLRequest( "http://www.leichtgewicht.at/wp-content/uploads/2009/04/PB-CheckPattern.v1.pbj" ) );
}
private function handleComplete( event: Event ): void
{
var shader: Shader = new Shader( _loader.data );
shader.data.size.value = [ 3 ]; // Size of the pattern
shader.data.foreground.value = [ 0.7, 0.7, 0.7, 1.0 ]; // Foreground color (r,g,b,a)
shader.data.background.value = [ 0.9, 0.9, 0.9, 1.0 ]; // Background color (r,g,b,a)
shader.data.offset = [ 2, 2 ]; // Offset of the first corner
_image.filters = [ new ShaderFilter( shader ) ];
addChild( _image );
}
}
}
Tags: ActionScript 3, Flash, Open Source, Pixel Bender