Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [source] fractal tree
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zylum




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
guruguru




PostPosted: Sun Mar 14, 2004 12:47 am   Post subject: (No subject)

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

+ Bits indeed
Catalyst




PostPosted: Sun Mar 14, 2004 12:49 am   Post subject: (No subject)

I like it
Especially the grass

Keep up the good work!

have... 45 bits
recneps




PostPosted: Sun Mar 14, 2004 10:48 am   Post subject: (No subject)

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




PostPosted: Sun Mar 14, 2004 1:13 pm   Post subject: (No subject)

+50 bits
shorthair




PostPosted: Sun Mar 14, 2004 2:09 pm   Post subject: (No 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
zylum




PostPosted: Sun Mar 14, 2004 6:12 pm   Post subject: (No 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
the_short1




PostPosted: Sun Mar 14, 2004 6:36 pm   Post subject: (No 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...
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Mar 14, 2004 7:05 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Cervantes




PostPosted: Sun Mar 14, 2004 7:29 pm   Post subject: (No subject)

*whistles*
slick!

+40 BITS
jonos




PostPosted: Sun Mar 14, 2004 11:37 pm   Post subject: (No 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......
the_short1




PostPosted: Mon Mar 15, 2004 12:27 pm   Post subject: (No 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
AsianSensation




PostPosted: Mon Mar 15, 2004 7:29 pm   Post subject: (No 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...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: