Computer Science Canada

Fractal Tree

Author:  BenLi [ Tue Dec 12, 2006 8:57 pm ]
Post subject:  Fractal Tree

And now, for no reason at all...fractal tree

code:

%this creates a regular fractal tree, the angles are controlled by mouse's y position
setscreen ("graphics:max,max")
var cnt := 0
proc frac (x, y, ang, leng, n, ang2 : real)
    if n > 0 then
        Draw.ThickLine (round (x), round (y), round (((cosd (ang)) * leng) + x), round (((sind (ang)) * leng) + y), n div 3, 255)

        frac (round (((cosd (ang)) * leng) + x), round (((sind (ang)) * leng) + y), ang + ang2, leng - 10, n - 1, ang2)
        frac (round (((cosd (ang)) * leng) + x), round (((sind (ang)) * leng) + y), ang - ang2, leng - 10, n - 1, ang2)
    end if
end frac

var mx, my, mb : int
setscreen ("offscreenonly")
loop
    mousewhere (mx, my, mb)
    frac (maxx div 2, 0, 90, 100, 7, (maxy - my) div 20)
    View.Update
    cls
end loop


this is the one that has been randomized. I think it looks decent.
code:

setscreen ("graphics:max,max")
var cnt := 0
proc frac (x, y, ang, leng, n : real)
    if n > 8 then
        Draw.ThickLine (round (x), round (y), round (((cosd (ang)) * leng) + x), round (((sind (ang)) * leng) + y), n div 2, RGB.AddColor (.3, .3, 0))
    else
        Draw.ThickLine (round (x), round (y), round (((cosd (ang)) * leng) + x), round (((sind (ang)) * leng) + y), n div 2, RGB.AddColor (0, Rand.Real, 0))
    end if
    if n > 0 then
        frac (round (((cosd (ang)) * leng) + x), round (((sind (ang)) * leng) + y), ang + Rand.Int (5, 15), leng - Rand.Int (1, 5), n - 1)
        frac (round (((cosd (ang)) * leng) + x), round (((sind (ang)) * leng) + y), ang - Rand.Int (5, 15), leng - Rand.Int (1, 5), n - 1)
    end if
end frac
frac (maxx div 2, 0, 90, 50, 16)

Author:  ericfourfour [ Tue Dec 12, 2006 10:20 pm ]
Post subject: 

I like the last one, but the first runs a bit slow. What was the cnt variable for?

Author:  BenLi [ Wed Dec 13, 2006 8:43 am ]
Post subject: 

the cnt variable wasn't used

Author:  iamcow [ Thu Dec 14, 2006 9:21 am ]
Post subject: 

not bad, I liked the second one. However, the brown branches look kinda bare

Author:  kshorting [ Sun Aug 19, 2007 9:07 pm ]
Post subject:  Re: Fractal Tree

BenLi,

Thank you. Fun stuff. I'll be having some fun playing with this. Razz

Thanks,

KS

Author:  UraniumLobster [ Wed Sep 12, 2007 10:11 am ]
Post subject:  RE:Fractal Tree

Thats pretty sweet, it kept me busy for about 5 mins =P. Thats good considering its not even a game, pretty cool idea!

Author:  Clayton [ Wed Sep 12, 2007 3:43 pm ]
Post subject:  Re: RE:Fractal Tree

UraniumLobster @ Wed Sep 12, 2007 10:11 am wrote:
Thats pretty sweet, it kept me busy for about 5 mins =P. Thats good considering its not even a game, pretty cool idea!


Things don't have to be games to be cool...

Author:  cpu_hacker4.0 [ Fri Sep 21, 2007 7:06 pm ]
Post subject:  RE:Fractal Tree

man how do you figure that stuff out?

Author:  Clayton [ Fri Sep 21, 2007 7:12 pm ]
Post subject:  RE:Fractal Tree

Wikipedia is a fantastic resources for algorithms for fractals and such.

Author:  cpu_hacker4.0 [ Tue Oct 09, 2007 7:49 pm ]
Post subject:  Re: Fractal Tree

Thanks, I'll be sure to check it out.

Author:  CodeMonkey2000 [ Tue Oct 09, 2007 7:52 pm ]
Post subject:  RE:Fractal Tree

Also look up recursion in the Turing Walkthrough.

Author:  cpu_hacker4.0 [ Tue Oct 09, 2007 8:03 pm ]
Post subject:  Re: Fractal Tree

ok thanks


: