Actionscript 3 | Speedcoding video – session #1: Black Branches

actionscript 3, algorithms, BitmapData, classes, fun, Math, perlinNoise

Yesterday night I wanted to have some “no-purpose coding session” and thought it was a nice idea to record the session and do a speedcoding video. The original video has been collapsed from 45 minutes to 3 minutes circa.

The main concept is once again based on perlinNoise which (I am sure you already guessed) is something I do like very much. So please start call me “The PerlinNoise Guy” or “Perlinator”. :-D

So this is my first speedcoding video (be sure to look at it in high quality):

Here’s the interactive demo:

400
Click to launch. Move mouse (x position) to change smoothness (my favourite values are around 100)

The code consist on a Branch.as class file (click to download) and some timeline code to assemble the demo:

import com.oaxoa.fx.Branch;

const w:uint=stage.stageWidth;
const h:uint=stage.stageHeight;

var ct:ColorTransform=new ColorTransform(1,1,1,1,1,1,1);
var renderView:BitmapData=new BitmapData(w, h, true);
var bmp:Bitmap=new Bitmap(renderView);
addChild(bmp);

var tf:TextFormat=new TextFormat("_sans", 16, 0, true);
var label:TextField=new TextField();
label.width=400;
label.defaultTextFormat=tf;
addChild(label);

var timer:Timer=new Timer(10);
timer.addEventListener(TimerEvent.TIMER, ontimer);
timer.start();

function ontimer(event:TimerEvent):void {
	addNew();
}
function addNew():void {
	label.text="Smoothness: "+String(mouseX-w/2);
	var tt:Branch=new Branch(mouseX-w/2);
	tt.x=stage.stageWidth/2;
	tt.y=stage.stageHeight/2;
	tt.addEventListener(Event.COMPLETE, oncomplete);
	addChild(tt);
	renderView.colorTransform(renderView.rect, ct);
}
function oncomplete(event:Event):void {
	var t:Branch=event.currentTarget as Branch;
	var matrix:Matrix=new Matrix();
	matrix.translate(t.x, t.y);
	renderView.draw(t, matrix);
	removeChild(t);
	t.removeEventListener(Event.COMPLETE, oncomplete);
	t=null;
}

I didn’t forget about the lightning class part 3 that I will publish soon :)

As usual if you liked this drop a line in the comments.
Ciao

11 Comments

11 Comments

  1. Lawrie  •  May 6, 2009 @11:24 am

    Great effect!
    I like the idea of a “no-purpose coding session”, I might have to give that a try soon.

  2. Andy  •  May 9, 2009 @6:17 pm

    Absolutely Beautiful! If you are the Perlinator, us readers are starting to become little Perlinies :)

  3. Pierluigi Pesenti  •  May 9, 2009 @10:55 pm

    LOL!

  4. batchass  •  May 12, 2009 @6:18 pm

    great work, as you did before, you’re a master!

  5. batchass  •  May 12, 2009 @6:26 pm

    would you be kind enough to let me adapt it to a onyx-vj plug-in?
    you will be credited of course…
    I try to adapt some plug-ins, you can check on http://www.batchass.fr/code.html for this open-source flash-based vj software
    Thanks

  6. Pierluigi Pesenti  •  May 12, 2009 @6:54 pm

    I’ve been to your site and onyx-vj seems very interesting.
    It would be a pleasure if you’ll adapt it to become a plugin.

    p.s.: that little box in homepage at http://www.batchass.fr/ looks like a similar effect. Is it a modified version of my class?

    Bye

  7. Scott Rockers  •  Jun 16, 2009 @10:08 pm

    Awesome File, very inspirational.

  8. antonio brandao  •  Jun 19, 2009 @12:14 pm

    Great indeed I loved it. BTW I thought you write unnecessary code there. You’d have a mush faster speedcoding session if you used some other interface for coding. Using eg. Flashdevelop doing imports and declaring vars is done using CTRL-SHIFT-1, then you’ll speedcode at ridiculous speeds.

  9. Pierluigi Pesenti  •  Jun 19, 2009 @2:11 pm

    Good advice. I usually use Flex Builder for as3 projects. Not evolved as FTD but a good IDE.
    However when I just want let random ideas flow, I often use Flash as it lets you just write down some raw/sketch frame code and draw some vector shape. :)

  10. batchass  •  Jun 20, 2009 @2:43 am

    No, it is from Lucas Swick and Don Relyea, called HairParticle.
    Sorry for the late reply…

  11. Naama Ton  •  Oct 7, 2009 @7:06 pm

    This is deffiently nice. Thanks for sharing all this talent with us. ^^

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>