
-----------------------------------
fishtastic
Fri Feb 15, 2008 3:58 pm

Moving Fractal Tree
-----------------------------------
Not as good as i expected. but I wanted to do this :mrgreen: 

var tree : collection of
    record
        l : int
        a : real
        c : int
        t : int
        b : int
        son : array 1 .. 6 of pointer to tree
    end record

const d := 5 % mess around with this var
const t := Rand.Int (2, 3) % and this var
var s := -0.2
var acc := 0.01
var col : array 1 .. d of int
var roots : array 1 .. t of pointer to tree
var x : array 1 .. t of int

proc initialize (var t : pointer to tree, c, depth : int)
    new tree, t
    if c  l := floor ((1.6 ** (depth - c) * Rand.Int (15, 30)))
        t -> a := Rand.Int (-60, 60) + 90
        if c = 1 then
            t -> a := 90
        end if
        t -> c := c
        t -> t := (depth - c) * 3
        t -> b := Rand.Int (depth - c, 6)
        for i : 1 .. t -> b
            initialize (t -> son (i), c + 1, depth)
        end for
    end if
end initialize

proc draw (t : pointer to tree, c, depth, x, y : int)
    if c  c))
        else
            var dx := round (cosd (t -> a) * t -> l)
            var dy := round (sind (t -> a) * t -> l)
            Draw.ThickLine (x, y, x + dx, y + dy, ceil (1.25 ** t -> t), col (t -> c))
            for i : 1 .. t -> b
                draw (t -> son (i), c + 1, depth, x + dx, y + dy)
            end for
        end if
    end if
end draw

proc move (t : pointer to tree, c, depth, a : real)
    if c  a += a
        for i : 1 .. t -> b
            move (t -> son (i), c + 1, depth, a * 2)
        end for
    end if
end move

View.Set ("offscreenonly")
colorback (102)
for i : 1 .. d div 2
    col (i) := RGB.AddColour (0.2 + 0.1 * i, 0.1 + 0.1 * i, 0)
end for
for i : d div 2 .. d
    col (i) := RGB.AddColour (0.0, 0.1 * i, 0)
end for
for i : 1 .. t
    initialize (roots (i), 1, d)
    x (i) := Rand.Int (50, maxx - 50)
end for

loop
    cls
    for i : 1 .. t
        draw (roots (i), 1, d, x (i), 0)
        move (roots (i), 1, d, s)
    end for
    s += acc
    if s > 0.2 or s < -0.2 then
        acc := -acc
    end if
    View.Update
end loop



-----------------------------------
Mackie
Fri Feb 15, 2008 4:29 pm

RE:Moving Fractal Tree
-----------------------------------
O wow, that's awesome. I'm adding this to my lst of things to research/create.

-----------------------------------
SIXAXIS
Fri Feb 22, 2008 8:33 am

Re: Moving Fractal Tree
-----------------------------------
Looks great. Reminds me a bit of the trees in Far Cry 2; they move in the wind and they can regenerate after a while.

-----------------------------------
DanielG
Sun Feb 24, 2008 5:28 pm

RE:Moving Fractal Tree
-----------------------------------
Its not bad, but I think it is a little too slow

-----------------------------------
McKenzie
Sun Feb 24, 2008 7:51 pm

Re: Moving Fractal Tree
-----------------------------------
The key is you're on the right track, now all that's left is to play with it until it looks the way you want it to. Trust me, I've drawn many, many fractal trees in Turing. Keep playing, you'll get it.

-----------------------------------
DaveAngus
Tue Mar 18, 2008 9:16 am

RE:Moving Fractal Tree
-----------------------------------
This is pretty cool. I like it.

-----------------------------------
Loading
Thu Nov 21, 2019 10:45 pm

RE:Moving Fractal Tree
-----------------------------------
How do i make a plain tree? Not moving
