Growing Plant generation in As3

I’ve been working on this game and i thought of adding some growing plants in it for some reason. I’ve seen the effects of growing plants (eg. pixeljunk Eden), and would love to do it in As3 graphics. I thought of doing it with Sine Wave and adding some randomness to it. Something like the graph below, in the vertical direction.

350px-DampedSine

Decaying Sine Wave – [source-wikipedia]

Enough theory. So i started coding, end up with this.

flower

Click to view the Flower Demo

Checkout the Flower Test

The basic working is simple. Each plant has a step Angle and continuous y-axis increment. For each stepangle the line moves to the Sine of the step Angle to the X direction (multiplied by the amplitude). And after the angle is reached the maximum Angle (Growth), i drew 4 circles around to create Flowers. In between i just drew some lines to the sideways (with low probability) to create the branches. The width as we move up is decided by the decaying x deviation. If any of this doesn’t make sense, don’t worry. You can come up with your own logic, and with a couple of trigonometry & mathematical stuff, you can do it too.

Here’s the complete Source Code of the whole thing
[expand title=”Show Code” swaptitle=”Hide Code”]
[snippet id=”400″]
[/expand]
I’m sorry its not commented properly. But if your’e looking for something and got confused with something in the code feel free to contact me (or comment). And do share if you’ve come up with something interesting like this.

557 Total Views 2 Views Today

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *