Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Turtle Based Fractal Trees

Author
Message
gbark
18
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 1st May 2009 08:29 Edited at: 1st May 2009 08:32
Hey there,

Just a pretty simple demo, I was experimenting with recursive tree drawing fractals using turtle graphics with DBP, and was able to come up with some interesting looking fractal trees.

Here is the demo:



It draws the trees in realtime each frame, allowing them to be animated or changed live. You can move the tree with the mouse, grow/shrink it with clicks, see how the tree "sways in the wind", grow extra branches with CTRL, and view 5 different possible types of trees with SPACE.


And here's the "Lite" version of the code, just generates a basic tree and doesn't have anything fancy like color changing or animation, but it's easier to see just what's going on.



Screenshot attached of a possible tree that can be generated (using the first snippet). Using the LOGO functions it's also pretty simple to program any sort of line-based fractals, like snowflakes, for example.

Just thought it was interesting.

Attachments

Login to view attachments
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 1st May 2009 09:46
Wow, you must be ancient! The next thing you know, we will be seeing Karel the Robot moving around a grid picking up beepers!

Cool tree by the way!

Enjoy your day.
gbark
18
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 1st May 2009 09:57 Edited at: 1st May 2009 09:58
Quote: "Wow, you must be ancient! The next thing you know, we will be seeing Karel the Robot moving around a grid picking up beepers!"


Harhar, funny.

I'm actually toying with the idea of a game completely based on fractals and vector graphics. Not just using fractals for skies or terrain like other games, but every piece of scenery (trees, bushes, grass, items, etc) being composed of fractal generated images, with characters or more advanced stuff being vector-based stick-figure characters.

I dunno, probably not a very realistic approach, that's just what I had in mind anyway.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 1st May 2009 11:29
Do it!

I've got a LOGO book somewhere around here. I remember there were some fractal examples... I may try and dig it up.

I wonder if you could adapt your code to 3 dimensions. The move object, and turn object left, right, pitch, (maybe roll but probably not) are sort of a 3d adaptation of turtle graphics. The pen up and pen down could be used to draw, scale and link plains/triangles. Might be quite interesting.

Enjoy your day.
gbark
18
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 2nd May 2009 04:24 Edited at: 2nd May 2009 04:25
Hey thanks, yeah fractals have always fascinated me, I just never got around to actually trying some out until now.

I think 3D fractals would be incredibly interesting, and with a little work could easily be done in a code snippet. I would need to be able to pitch the turtle, then modify the current turn move command to take multiple angles into account when calculating direction (I already have a 360 degree free-moving mouse-controlled flying camera system, so the math is already done ), and just add in iterations for branching forward/back in Z space in addition to the left/right branching in X space, and it should be good. I'll look into that some more and will post back.


In the meantime, I made a couple more examples.


Your classic Koch Snowflake fractal example,



Parameters include the position, size, sides (3 is the "standard", add more for more complex outlines), and minimum length of each line (lower values = more detail in the edges).




And, a splitting spiral fractal.

Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 5th May 2009 04:46
cool!

laggy but cool!
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 15th May 2009 09:37
yeha, i like the first one, it is on a poster in the classroom where we have maths too!

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!

Login to post a reply

Server time is: 2024-05-03 08:45:04
Your offset time is: 2024-05-03 08:45:04