Newest Articles

MegaCombs
Flash Media Player
XML Driven Pie Chart
Base Defender
Hangman Game
8 Ball Pool


Popular Articles

True Fullscreen Flash Mode
Mp3 Player with XML Playlist
Image Slider
Flash Media Player
3d Rotating Image Cube
FLV Player


Random Articles

Image Slider
Krypto Movie Quotes
Infinitely Zooming Image
onEnterFrame vs setInterval
Base Defender
Glowing Orb


Links

Foundation-Flash
MickM
TutorialQuest
Tutorialsphere.com - Free Online Tutorials
Newgrounds
TWiT
Link to SwfSpot
Swf Spot



rss feed

Growing Tree using Recursion

Growing Tree using Recursion
AddThis Social Bookmark Button
Description: Tree grows and sprouts new branches with leaves
Author: John Bezanis
Added: October 31st 2007
Version: Flash 8


This applet demonstrates how trees can be created by using recursion. Recusion is a technique where a function calls itself. The tree starts out with one branch with a leaf on it and grows each frame. There's a small chance of the branch sprouting a child branch. If a branch sprouts its first child, the leaf disappears and a leaf grows out of the new branch. The leaf color is chosen randomly from 4 colors and scaled to different sizes. The tree is completely cleared and redrawn with the start of each frame.

All of the information about the branches is stored in the array "tree". The function drawSegment is the recursive function, and it starts with 1 trunk branch. The start point is always 0,0. The function calls itself to process each of its children, and the children call their children, until there are no more and the function returns. The childs' starting positions on each frame are based on their parents' end positions. The rotation is based on the parent's rotation, with a 90 degree maximum variance. The resettree function clears all of the tree segments and starts it all over again. The source code is available below:

Download the Source File
Comments
Dude that is totally awesomeness
October 31st 2007 07:10AM   -   Xyber
Hey! That'sgreat! How can we make it grow faster? Has anyone got an hint? Thank you!
November 13th 2007 09:11AM   -   Geek
Nice =)
November 26th 2007 12:11AM   -   AsianSpark
is this done with the help of script or just the animation????
November 26th 2007 01:11AM   -   pamsi
cooool..................
November 28th 2007 05:11AM   -   xanuz
very nice, i have a doubt whether it is done with animation or script? anyway it is very nice.

December 12th 2007 07:12AM   -   Anand
i'm trying to make christmas tree growin branch by branch but canot get the right order. it grows verticaly to the top and then strats branching from the top to the bottom (and that's not the way trees are growing)
December 23rd 2007 05:12PM   -   igregurec
This Coooooooooool.............. man
December 26th 2007 10:12PM   -   Abdul Desuza
awesome
January 21st 2008 12:01PM   -   tom
very nice
January 28th 2008 06:01AM   -   kae
This is new idea...

Good Job..!
April 17th 2008 05:04PM   -   Ranjith
Anyone figure out how to make it grow faster?
May 19th 2008 11:05AM   -   Rob
This is great! But one comment is that, the tree must grow vertically and not diagonally. Well, i think the farmer didn't put some fence on it that's why it grew out sideways.

But hey, great job!
June 3rd 2008 08:06PM   -   Shinobi
Hey, very nice ... It's probabily a very wind landscape..
June 12th 2008 01:06PM   -   mauricio
I want to know the code behind this effect
June 24th 2008 03:06AM   -   beeta
yeah thats fabulous i could'nt have done that on a spot.... very intresting ........
September 25th 2008 06:09AM   -   kolade from nigeria
how can i download the growing tree animation to my power point for my presentation? Is it possible? Its really a fantastic and creative animation.
October 17th 2008 06:10PM   -   joseph te
@Rob - right click and change the quality setting to low, you can change it back when the tree is done growing
October 27th 2008 09:10PM   -   Smitty
it's really awesomeness can anyone tell me is any script for this growingtree
March 27th 2009 10:03AM   -   bhupi
Gr8 work dude............
July 3rd 2009 06:07AM   -   Rishi
that's too good
July 6th 2009 04:07AM   -   priyanka
THERES NO CODE!! SO WIERD HOW DOES IT GROW WITH NO CODE

the comments say to chec the tree for the code i did and there was no code HELP MEH OUT HERE!!
September 14th 2009 09:09PM   -   Contrictor
This is really cool effect. With these codes we can create a lot of thing.
Thanks
September 17th 2009 03:09AM   -   shakir
I like this, very cool :-) How does it know when to stop growing?
September 23rd 2009 10:09AM   -   email marketing
Very nice, but unlike the waving grass example there is no code! Would love to see how this is scripted.
October 13th 2009 08:10AM   -   silver slimming
good job dude... this is awsome !!!
October 22nd 2009 03:10PM   -   mrloopz
The tree must grow vertically and not diagonally. Well, i think the farmer didn't put some fence on it that's why it grew out sideways.
November 12th 2009 11:11AM   -   Adult DVDs
My trees always seem to go to the right, i thought this was a completely random animation, maybe it is just coincidence?
November 25th 2009 09:11AM   -   michael
Wonderful, thanks.
December 6th 2009 01:12AM   -   seo
I showed this to my daughter and she was enthralled by it! It kept her quiet for ages and I can't say that about many things!
December 9th 2009 04:12AM   -   Unlock a blackberry storm
Good job! With these codes we can create a lot of thing.I but I have a question.Can we make the tree grow faster? Does anybody know?
Thanks!
December 23rd 2009 09:12AM   -   Search files
Thanks!
December 24th 2009 12:12PM   -   ladies golf gloves
Great applet. Is the tree an apple tree. ;-) Thanks for the share.
December 29th 2009 11:12PM   -   mario games
Its funny! the main trunk is still the same. No change in it.
December 31st 2009 04:12PM   -   presentation folders
i like
January 4th 2010 01:01AM   -   cheap wedding dresses
It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader.
January 19th 2010 01:01AM   -   Rolex watches
I have introduced a lot of friends look at this article, the content of the articles there will be a lot of attractive people to appreciate, I have to thank you such an article.
January 19th 2010 01:01AM   -   Panerai watches
The growing tree using recursion is cool. That effect is new in this new version, right? I didn't know that could be done.
January 20th 2010 08:01PM   -   Speed Dating Westchester
Thank for infomation.
January 22nd 2010 04:01PM   -    generic zovirax tablets
cool post.
January 23rd 2010 04:01PM   -   Canada drugs side effects
I am happy to find it, thanks for sharing it
January 24th 2010 06:01AM   -   evening dresses
Maybe you need to change your modus operandi. Yes I know.. You will have learned how to do this before the end of this article. I was promoted from that a while ago.

I've had it with won't. When you are finished reading this article, you will see that. First, locate a commonplace alone that is designed to work with regardless.
January 25th 2010 01:01PM   -   Karen
Special thank for good post.
February 5th 2010 08:02AM   -   à¹‚หลดเพลงà
Thank for the information
February 6th 2010 06:02AM   -   à¹‚หลดเพลงm
I am so impressed w/evernote so far. really pro stuff. thx folks
February 9th 2010 12:02AM   -   tim
¡°We didn¡¯t set out to do a Super Bowl ad, or even a TV ad for search,¡± Chief Executive Officer Eric Schmidt said in a blog posting yesterday. ¡°Our goal was simply to create a series of short online videos <a href="http://www.weddingnova.com/category/Mermaid-Wedding-Dresses-811-1.html">Mermaid Wedding Dresses</a>about our products and our users, and how they interact. But we liked this video so much, and it¡¯s had such a positive reaction on YouTube, that we decided to share it with a wider audience.¡±Schmidt signaled that the Super Bowl<a href="http://www.rolexwatch4sale.com/rolexitems/a-true-rolex-jewellery-%E2%80%93-rolex-replica-watches.html">Rolex replica watches</a> commercial was coming last week, saying in a Twitter update that he couldn¡¯t wait to watch the game. ¡°Be sure to watch the ads in the third quarter,¡± he said.The Super Bowl, held at the Sun Life <a href="http://www.weddingnova.com/product/Strapless-Chiffon-Mother-Of-Bride-Dress-21002.html">Strapless Chiffon Mother Of Bride Dress</a>Stadium in Miami, pitted th Indianapolis Colts against the New Orleans Saints for the National Football League championship. The Saints won 31-17.CBS Corp., which broadcast the game, <a href="http://www.weddingnova.com/product/Strapless-Chiffon-Prom-Dress-21203.html">Strapless Chiffon Prom Dress</a>said the cost of some of the Super Bowl ads exceeded $3 million for a 30-second spot. The game drew an estimated 106.5 million viewers, making it the most-watched program in U.S. television history, according to Nielsen Co.Google rose $2.18 to $533.47 at 4 p.m. New York time on the Nasdaq Stock Market. The shares have fallen 14 percent this year.<a href="http://www.weddingnova.com/product/Strapless-Halter-Satin-Prom-Dress-21212.html">Strapless Halter Satin Prom Dress</a>--With assistance from Andy Fixmer in Los Angeles. Editors: Nick Turner, Mark McCord
February 9th 2010 01:02AM   -   wedding dresses
Pennsylvania Democratic Rep. John Murtha, the first veteran of the Vietnam war to enter Congress and one of the House's most powerful lawmakers, died Monday afternoon at Virginia Hospital Center after complications[url=http://www.weddingnova.com/category/A-Line-Wedding-Dresses-807-1.html]A Line Wedding Dresses[/url] from gallbladder surgery. Murtha was 77."Congressman John P. Murtha (PA-12) passed away peacefully this afternoon at 1:18 p.m. at Virginia Hospital Center in Arlington,[url=http://www.weddingnova.com/category/Empire-Wedding-Dresses-808-1.html]Empire Wedding Dresses[/url] Va. At his bedside was his family," read a statement from his office.A native of New Martinsville, W.Va., voters first elected Murtha to Congress in a 1974 special election [url=http://www.rolexwatch4sale.com]A blog about Rolex Watches[/url]that spelled impending doom for President Nixon and congressional Republicans. That fall, Democrats wrestled away 49 House seats from the GOP, reeling from the scourge of Watergate and a presidency in shambles.Murtha rose[url=http://www.weddingnova.com/product/Mermaid-Satin-Chiffon-Wedding-Dress-20795.html]Mermaid Satin Chiffon Wedding Dress[/url]to become the chairman of the House Defense Appropriations Subcommittee, which controls spending for the Pentagon. Chairmen of the appropriations subcommittee panels are viewed with such prestige on Capitol Hill that they're called "cardinals."[url=http://www.weddingnova.com/product/Mermaid-Satin-Lace-Wedding-Dress-20322.html]Mermaid Satin Lace Wedding Dress[/url] That's a nod to Rome because of the eminence these lawmakers hold over spending for their federal fiefdom.Murtha was the endorsed candidate of House Speaker Nancy[url=http://www.weddingnova.com/product/Mermaid-Satin-Organdie-Wedding-Dress-20750.html]Mermaid Satin Organdie Wedding Dress[/url] Pelosi to become majority leader when Democrats won control of Congress in 2006. But current Majority Leader Steny Hoyer overwhelmingly defeated Murtha by secret ballot in a hard-fought leadership contest.
February 9th 2010 01:02AM   -   wedding dresses
Special thank for good post.
February 10th 2010 03:02AM   -   à¹‚หลดเพลงà
Special thank for good post.
February 10th 2010 08:02AM   -   à¹‚หลดเพลงà
Hello everyone. You can go a long way with bad legs and a good head. Help me! I find sites on the topic: Electronic date stamps. I found only this - <a href="http://rifondazione.objectis.net/Members/DateStamp">cheap date rubber stamp with years</a>. Hardened example was dispensed because of the mini's speed code, remaining deliberately a post government and the stress food, date stamp. Farrar wore a deep week type in the growth of geddes, new york, date stamp. :cool: Thanks in advance. Cicily from Ecuador.
February 14th 2010 03:02AM   -   Cicily



[url=http://www.guccipress.com/catalog.asp?date=2010-2-5]guccipress 2-5[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-6]guccipress 2-6[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-7]guccipress 2-7[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-7&page=2]guccipress 2-7&page=2[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-8]guccipress 2-8[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-9]guccipress 2-9[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-10]guccipress 2-10[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-10&page=2]guccipress2[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-11]guccipress3[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-11&page=2]guccipress4[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-12]guccipress5[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-12&page=2]guccipress6[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-14]guccipress7[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-14&page=2]guccipress8[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-14&page=3]guccipress9[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-14&page=4]guccipress0[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-14&page=5]guccipress1[/url]
[url=http://www.guccipress.com/catalog.asp?date=2010-2-14&page=6]guccipress22[/url]
[url=http://www.guccipress.com/catalog.asp?cate=6]guccipress33[/url]
[url=http://www.guccipress.com/catalog.asp?cate=6&page=2]guccipress44[/url]
[url=http://www.guccipress.com/catalog.asp?cate=6&page=3]guccipress55[/url]
[url=http://www.guccipress.com/catalog.asp?cate=6&page=4]guccipress66[/url]
[url=http://www.guccipress.com/catalog.asp?cate=6&page=5]guccipress7a[/url]
[url=http://www.guccipress.com/catalog.asp?cate=6&page=6]guccipress8a[/url]
[url=http://www.guccipress.com/catalog.asp?cate=4]guccipress9a[/url]
[url=http://www.guccipress.com/catalog.asp?cate=4&page=2]guccipress2a[/url]
February 14th 2010 08:02PM   -   adsdas
Add a Comment
name:
website (optional):
captcha type the characters into the box
message (5000 characters or less):