Computer Science Canada

[source] fractal tree

Author:  zylum [ Sun Mar 14, 2004 12:14 am ]
Post subject:  [source] fractal tree

here's a simple example of a fractal tree....

code:
setscreen ("graphics:500;600")
proc fractal (x, y, depth, maxDepth, angle, maxLength : int)
    var endx, endy, ang : int
    for i : 1 .. depth
        ang := angle + Rand.Int (-15 * depth, 15 * depth)
        endx := round (cosd (ang) * maxLength) + x
        endy := round (sind (ang) * maxLength) + y
        Draw.ThickLine (x, y, endx, endy, (maxDepth - depth + 1) * 2, 115)
        %delay (10)
        if depth <= maxDepth then
            fractal (endx, endy, depth + 1, maxDepth, ang, round (maxLength * 0.75))
        else
            drawfilloval (endx, endy, 3, 3, green)
        end if
    end for
end fractal

fractal (maxx div 2, 30, 1, 5, 90, 150)


here's one with a back ground:

code:
setscreen ("graphics:500;600")
proc fractal (x, y, depth, maxDepth, angle, maxLength : int)
    var endx, endy, ang : int
    for i : 1 .. depth
        ang := angle + Rand.Int (-15 * depth, 15 * depth)
        endx := round (cosd (ang) * maxLength) + x
        endy := round (sind (ang) * maxLength) + y
        Draw.ThickLine (x, y, endx, endy, (maxDepth - depth + 1) * 2, 115)
        %delay (10)
        if depth <= maxDepth then
            fractal (endx, endy, depth + 1, maxDepth, ang, round (maxLength * 0.75))
        else
            drawfilloval (endx, endy, 3, 3, green)
        end if
    end for
end fractal

var clr : int
for i : 0 .. maxy
    clr := RGB.AddColor (i / (maxy + 250), i / (maxy + 250), 1)
    drawline (0, maxy - i, maxx, maxy - i, clr)
    %delay (10)
end for

for i : 0 .. 100
    drawfillbox (0, i, maxx, i, green)
    %delay (10)
end for
var x, y : int
for i : 1 .. 10000
    clr := RGB.AddColor (100 / Rand.Int (300, 1500), Rand.Real * 0.5 + 0.5, 100 / Rand.Int (300, 2500))
    x := Rand.Int (0, maxx)
    y := Rand.Int (0, 100)
    drawline (x, y, x, y + Rand.Int (4, 9), clr)
end for

fractal (maxx div 2, 30, 1, 5, 90, 150)


-zylum

Author:  guruguru [ Sun Mar 14, 2004 12:47 am ]
Post subject: 

Wow! Dam thats good! Even looking at ure code I can barely figure out how you did that...

+ Bits indeed

Author:  Catalyst [ Sun Mar 14, 2004 12:49 am ]
Post subject: 

I like it
Especially the grass

Keep up the good work!

have... 45 bits

Author:  recneps [ Sun Mar 14, 2004 10:48 am ]
Post subject: 

*absolutely no idea how that works.....* have some bits Very Happy

Author:  AsianSensation [ Sun Mar 14, 2004 1:13 pm ]
Post subject: 

+50 bits

Author:  shorthair [ Sun Mar 14, 2004 2:09 pm ]
Post subject: 

+ 35 BITS ( you cant have to many now ,,,....... )

great program , i ca nsee you really know your math , its a rocking program ,im really impresed , keep up this excellent roll your on

Author:  zylum [ Sun Mar 14, 2004 6:12 pm ]
Post subject: 

wow, lots of bits for that one Smile

here's an new and improved version, it's a forest and the trees actually grow Razz

code:
setscreen ("graphics:1000;680,nobuttonbar")
const d := 5
process fractal (x, y, depth, maxDepth, angle, maxLength : int)
    var endx, endy, ang : int
    for i : 1 .. depth
        ang := angle + Rand.Int (-15 * depth, 15 * depth)
        for l : 1 .. maxLength
            endx := round (cosd (ang) * l) + x
            endy := round (sind (ang) * l) + y
            Draw.ThickLine (x, y, endx, endy, (maxDepth - depth + 1) * 2, 115)
            delay (round (((maxDepth - depth) * 5 + 10) * d))
        end for
        delay (round (300 * d))
        if depth <= maxDepth then
            fork fractal (endx, endy, depth + 1, maxDepth, ang, round (maxLength * 0.75))
        else
            for l : 1 .. Rand.Int (2, 5)
                drawfilloval (endx, endy, l, l, green)
                delay (round (50 * d))
            end for
        end if
    end for
end fractal

var clr : int


for i : 0 .. maxy
    clr := RGB.AddColor (i / (maxy + 250), i / (maxy + 250), 1)
    drawline (0, maxy - i, maxx, maxy - i, clr)
    %delay (10)
end for

for i : 0 .. 100
    drawfillbox (0, i, maxx, i, green)
    %delay (10)
end for
var x, y : int
for i : 1 .. 20000
    clr := RGB.AddColor (100 / Rand.Int (300, 1500), Rand.Real * 0.5 + 0.5, 100 / Rand.Int (300, 2500))
    x := Rand.Int (0, maxx)
    y := Rand.Int (0, 100)
    drawline (x, y, x, y + Rand.Int (4, 9), clr)
end for

for i : 1 .. Rand.Int (10, 30)
    fork fractal (Rand.Int (100, maxx - 100), Rand.Int (0, 100), 1, Rand.Int (3, 4), 90, Rand.Int (50, 200))
    delay (Rand.Int (100, 2000))
end for


-zylum

Author:  the_short1 [ Sun Mar 14, 2004 6:36 pm ]
Post subject: 

what grade math u in... also waht is ur mark... cuz DAM ur good... .if i was a MOD i would give you 100 BITS.. ur deserv it... cuz all this drawing deal with advanced math functions in turing... just WOW... lookz soo COOL

OMG i just loked at the forest one... i REALY dont know how u can make sh!t THAT good in only 50 lines of code... and like no time.... god... U are PRO... i think everyone shall bow down to ur greatness......

im amazed... the only program i have seen that compared to this.. is taht tree taht catalyst made... but i cant run that no more... and it didn;t grow from GRASSS... DAM...

Author:  Tony [ Sun Mar 14, 2004 7:05 pm ]
Post subject: 

nice, all you need to do now is give different colors to the trees so that trees that are further behind are darker then those up front Smile

Author:  Cervantes [ Sun Mar 14, 2004 7:29 pm ]
Post subject: 

*whistles*
slick!

+40 BITS

Author:  jonos [ Sun Mar 14, 2004 11:37 pm ]
Post subject: 

id give bits, but im not a mod like all you other people, but its still awesome none-the-less. makes me want to know more math......

Author:  the_short1 [ Mon Mar 15, 2004 12:27 pm ]
Post subject: 

... welll jonos yu can be lkike me... and donate to get to the nearest 5 bits...like right now i have ,,.,644 BITS... so i donate 4... to get to 640...

there... Zylum... 4+ BITS... u deserve them.i think u deserve a Newbe God Status or something.... bugpodder got a leet ranking with his minor ammounts of post....u should be able to get that...np... once he gets back

Author:  AsianSensation [ Mon Mar 15, 2004 7:29 pm ]
Post subject: 

the_short1 wrote:
bugpodder got a leet ranking with his minor ammounts of post....


bugzpodder is also one of the smartest guy you will meet. So yeah...


: