Procedurally generated tree(With source)

I was bored one day so I sat down and tried making a random tree generator. Essentially it’s extremely simple, you basically have this:

struct Tree
    {
    int x, y, z;
    float radius;
    Tree[] subTrees;
    }

It’s a root which defines a point in R3, a thickness and branches connected to it. From this structure I can generate a tree by recursively traversing the structure, building cylinders as I go:

AddCylinder(int x1, int  y1, int  z1,
            int  x2, int  y2, int  z2,
            float w1, float w2, 3DModel model)
    {
    //Construct cylinder from (x1,y1,z1) with raidus w1 to (x2,y2,z2) with radius w2
    //Add cylinder to model
    }

BuildTree(Tree node, 3DModel model)
    {
    foreach(Tree subTree in node.subTrees)
        {
        AddCylinder(node.x, node.y, node.z,
                    subTree.x, subTree.y, subTree.z,
                    node.radius, subTree.radius, model);
        BuildTree(subTree, model)
        }
    }

The interesting part of all this is finding an algorithm which generates cool trees. My algorithm was kind of half-assed, I have a much better idea now than I did when I was motivated to implement it. I was thinking of having three cases and then choosing between them: “Stop here”, “Continue growing” or “Branch out”. Then it would be a simple problem of choosing what would be best at any given time. My current algorithm is implemented like “I just want to see if it works”.

treegen

(Note that the “leaves” are icosahedrons stolen from my first post)

As you can see the approach I have to constructing the cylinders is not as great as it could have been. The ends are always on an XY plane, or aligned with the floor. I could’ve rotated them so they were facing the direction they’re growing in and then connected them with an extra cylinder at each node:

TreeGen2

The generator has the potential of building really realistic trees by adding a lot more small branches and adding a lot of small leave sprites instead of big spheres added to the end of each branch.

It’s written in C# using .NET 3.5 and TrueVision3D(DLL included). Here’s the source:

Download Here

File: TreeGen.rar

Contents: C# Solution and TrueVision3D assembly.

Size: ~4.5 MB

 

Clever title here(Site facelift)

So, after about a year(Just paid my yearly bills for the domain name and web hosting) I decided to replace the guts of my site(New design by my beautiful girlfriend).

The site had mainly become my weird obsession with observing spam comments. I coded this anti spam script, which would compare the content of a comment with a list of banned words; if a word in your comment is banned, the comment will not be submitted. I would check in regularly to see if any words had gained traction or if there were new words to ban, but not really much else.

This was what I retrieved from the database before I pulled down my old code, sorted by # times caught(I accidentally the whole table at some point, so the words have been caught more times than stated, especially viagra):

Word # times caught Last catch
chanel 25 14-01-2013 01:33
payday 13 15-01-2013 09:26
viagra 13 17-01-2013 00:36
cialis 7 12-12-2012 15:24
louis vuitton 5 12-01-2013 23:08
levitra 4 12-12-2012 09:32
ex back 3 07-12-2012 12:36
ceftin 3 22-11-2012 22:42
propecia 3 07-11-2012 05:55
northface 2 11-11-2012 08:04
escort 2 06-11-2012 00:13
girlgetsring 1 17-11-2012 10:47
anti wrinkle 1 07-11-2012 15:30
http://ggrsite.com 1 11-11-2012 10:25
amoxil 1 07-01-2013 14:21
nolvadex 1 11-01-2013 02:55
gucci 1 15-01-2013 20:43
zoloft 1 15-01-2013 20:43
http://www.rmtest.com 1 15-01-2013 20:44
http://cufikiro.hotbox.ru 1 02-11-2012 17:36
zithromax 1 01-11-2012 09:36
arthritis 1 29-10-2012 12:17

I wasn’t using the site for anything productive. I wrote the site from scratch in about one week after just one week of having first tried PHP. The admin interface I implemented was rubbish, I didn’t put any effort in to it; it was just a means to an end. Adding new content was a pain in the ass, so I couldn’t force myself to do it.

I like doing things myself, reinventing the wheel, because I believe it’s the best way to learn. But having a site I never update because it’s difficult is just stupid. So I gave up and installed WordPress. I had everything up and running in about 2 hours! Hopefully now I can start writing more.

Here’s some highlights of the old site:

coredumping1

My beautiful, somewhat large, header.

coredumping3

I had a custom game overview site. WordPress is all about blogging, so there’s not really any easy way to add a game portfolio with download links, status, etc. But I can have categories and just pretend that a regular blog post is a game showcase.

coredumping2

This is my own image scroller thing, written in javascript. I really fucking hate writing javascript, but I love the opportunities it opens up for making dynamic content on websites. Here’s a link to the code.

Well that’s about it. I really hope to be posting more about what I do and think in the future. In fact, even though it’s late and fucking dumb, it will be my new year’s resolution!

Subdivision of icosahedrons

In this post I will explain how to build, subdivide and texture an icosahedron. Look at the ending of the post for eye candy.

So I’ve been following the development of Notch’s new game, 0x10^c, which is looking really exciting. When I saw a screenshot(Can’t find it now) I was reminded of something I read about using icosahedrons to make planets in 3D with minimal distortion when mapping to a texture.

I find this way of attacking the problem of spheres fascinating. Basically you start off with a 20 sided die and split the faces by adding new vertices on a sphere encapsulating the icosahedrons, so in each iteration you get closer to a perfect sphere. You split the faces by adding a point in the middle of each edge in a triangle, you then construct four new triangles using these and the original vertices.

Icosahedron Subdivision

Continue reading