NAVIGATION:

 

SUPPORTERS:

FlashComponents
  Flash Templates
  Flash Gallery
  Flash Slideshow
  Flash Menu
  Flash Design
  Flash Video
  User Interface

 

FOLLOW:

RSS it down! Twitter it up! Facebook it like a fiend!

 

 

 

 

 
Chaotic Fractal Tree
      
by ilyas usal

The following animation is a chaotic fractal tree that is different from the previous example in the fractal tree tutorial. Keep clicking in the animation, and you will find various randomly generated branches:

[ a fractal tree...that changes with every click ]

Here, I just threw in as many Math.random() statements as I could: a random number of sub-branches, a random angle, and a random shrinking ratio. Click the scene to regenerate :)

/*** Constants ***/
max_sub_branch = 4 ;
max_sub_angle = 3*Math.PI/4 ;
max_size = 8 ;
branch_length = 50 ;

/*** Function ***/
function makeBranch ( start_x, start_y, length, angle, size ) {
if ( size > 0 ) {
this.lineStyle ( size, 0x333333, 100 ) ;
this.moveTo ( start_x, start_y ) ;
var end_x = start_x + length * Math.cos ( angle ) ;
var end_y = start_y + length * Math.sin ( angle ) ;
this.lineTo ( end_x, end_y ) ;

var sub_branch = random (max_sub_branch - 1) + 2 ;
var branch_length_dimin = .5 + Math.random()/2 ;

for ( var i=0; i < sub_branch; i ++ ) {
var newLength = length * branch_length_dimin ;
var newAngle = angle + Math.random() * max_sub_angle - max_sub_angle / 2 ;
var newSize = size - 1 ;
makeBranch ( end_x, end_y, newLength, newAngle, newSize ) ;
}
}
}

/*** Function call ***/
makeBranch ( 200, 300, branch_length, -Math.PI/2, max_size ) ;

Here, this tutorial is over! I hope you enjoyed it. And remember that fractal trees are just one aspect of what you can do with recursion. I hope that this tutorial will encourage you to discover the others.

Ilyas Usal
{Pictures 1 | 2}

 
SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components Flash effects. Art without coding.
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Citrus Engine: Flash platformer and sidescrolling game engine
Learn how to advertise on kirupa.com

cdn
content delivery network (cdn)