Computer Science Canada

Tree

Author:  Catalyst [ Sun Oct 05, 2003 1:48 am ]
Post subject:  Tree

I was bored in compsci (whole class learning put/get Laughing ) the other day
so i made this

code:

% Tree
proc AddGradient (c1, c2, n : int)
    var clr : int
    var r1, g1, b1, r2, g2, b2, p, p0 : real
    RGB.GetColor (c1, r1, g1, b1)
    RGB.GetColor (c2, r2, g2, b2)
    const a := 50
    for i : 1 .. n
        p := (i / n) * 100
        p0 := 100 - p
        clr := RGB.AddColor ((((r1 * p) + (r2 * p0)) / 2) / a, (((g1 * p) + (g2 * p0)) / 2) / a, (((b1 * p) + (b2 * p0)) / 2) / a)
    end for
end AddGradient

AddGradient (114, 114, 220)
AddGradient (2, 10, 35)

type Point :
    record
        x, y : real
    end record


var holdPoint : Point
holdPoint.x := 0
holdPoint.y := 0

fcn RandReal : real

    result (Rand.Real * 2 - 1) * 10
end RandReal

fcn AngleFrom (X, Y : real, dist, ang : real) : Point

    holdPoint.x := (cosd (ang) * dist) + X
    holdPoint.y := (sind (ang) * dist) + Y

    result holdPoint
end AngleFrom

var md : int := 150

var inc : real := 45
var reduc : real := 2
var numB : int := 3
proc MakeTree (X, Y : real, ang : real, dist : real)


    var test := AngleFrom (X, Y, dist, ang)

    if 511 - round (255 * dist / md) + 1 <= 511 - 36 then
        Draw.ThickLine (round (X), round (Y), round (test.x), round (test.y), round (dist / md * 25), 511 - round (255 * dist / md) + 1)
    else
        Draw.ThickLine (round (X), round (Y), round (test.x), round (test.y), round (dist / md * 10), 511 - round (255 * dist / md) + 1)
    end if

    if dist <= 10 then
        return
    end if

    for i : 0 .. numB
        MakeTree (test.x, test.y, RandReal + ang + (inc * ((i / numB) * 2 - 1)), dist / reduc + (dist / reduc * Rand.Real * Rand.Real))
    end for


end MakeTree



MakeTree (maxx div 2, 0, 90 + Rand.Int (-15, 15), md)

Author:  poly [ Sun Oct 05, 2003 12:31 pm ]
Post subject: 

thats pretty sweet!

Author:  JSBN [ Sun Oct 05, 2003 12:39 pm ]
Post subject: 

damn. that's pretty sweet. wish i could do that.

Author:  PaddyLong [ Sun Oct 05, 2003 1:27 pm ]
Post subject: 

heh cool... what did your teacher and classmates think of that? or were they too busy making cheasy little put/get programs? 8)

Author:  Tony [ Sun Oct 05, 2003 1:35 pm ]
Post subject: 

code:

var answer:string
put "would you like to draw a tree?"
get answer
put "I don't yet know how to use IF statments"
put "so I'll just assume you said yes"
put "I don't yet know how to use graphics in turing"
put "so just open M$ Paint and draw a tree there"


Laughing

Heh. Catalyst - Bring a pillow to class and/or install some C++ compiler & IDE. Just cuz you ended up in a class full of kids who got trouble using put/get, doesn't mean you have to waste your time.

Author:  PaddyLong [ Sun Oct 05, 2003 1:37 pm ]
Post subject: 

does your teacher actually like teach stuff in your compsci class? mine just put some tutorials he wrote into a directory and we would just do those at our own pace with assignments from each chapter along the way.

Author:  Catalyst [ Sun Oct 05, 2003 6:03 pm ]
Post subject: 

my teacher likes to have a powerpoint projector running as he explains the programs(if u could call them that)
tony- ive got devc++ on my account but network restrictions wont let me compie Evil or Very Mad

Author:  rizzix [ Sun Oct 05, 2003 6:25 pm ]
Post subject: 

whats Draw.ThickLine ? never seen that before.

Author:  Catalyst [ Sun Oct 05, 2003 6:42 pm ]
Post subject: 

its one of the newer functions from 4.0
it draws a thick line
the syntax is the same is drawline but there is a thickness parameter b4 the color

Author:  Tony [ Sun Oct 05, 2003 6:56 pm ]
Post subject: 

I wouldn't be surpriced if that Draw.ThickLine is just a Draw.FillPolygon with points calculated from passed values.

Turing is soo cheap - a bunch of build in functions are writen in turing itself and slow the program down.

Author:  Catalyst [ Sun Oct 05, 2003 10:15 pm ]
Post subject: 

i think the draw functions are actually just mapped from the windows gdi functions, but i might be wrong

Author:  hackman [ Thu Oct 09, 2003 9:57 am ]
Post subject: 

wish i could see that now. Im in class and my ghetto school has like v0.01, well actualy 3.1. Looks like im gona have to wait another 3 classes till i get home.

Author:  hackman [ Thu Oct 09, 2003 3:13 pm ]
Post subject: 

Home finaly! Thats sweet.

Author:  LJ [ Sat Mar 06, 2004 9:06 pm ]
Post subject: 

That's sick!

Author:  the_short1 [ Sat Mar 06, 2004 10:16 pm ]
Post subject: 

ummmm LJ.... when a topic is like over 1 year old.... w/e.... anyways... some kid in my compsci class had this going and he said he got it on compsci.... sweet.... now i know its the infamous Catalyst


its REALY cool if you add a loop to the Draw tree function....and it randomizes the location each time... i made a reedit but its at school...

Author:  Jodo Yodo [ Sat Mar 06, 2004 10:26 pm ]
Post subject: 

Wow, that's a sweet tree.

Author:  programer007 [ Sun Mar 07, 2004 4:51 pm ]
Post subject: 

that a Nice tree.... whats the Gradient command all about.....
and when do you get to learn all those advanced functions in class??? gr.10?? or 11? or 12?

Author:  Catalyst [ Sun Mar 07, 2004 5:28 pm ]
Post subject: 

the AddGradient command just make a smooth blend from color1 to color2 in a certain number of steps
and you dont learn these functions in class

Author:  jonos [ Sun Mar 07, 2004 6:38 pm ]
Post subject: 

it doesn't work unless i change the colour for the Draw.ThickLine, it says it can't make a colour over 290

Author:  Catalyst [ Sun Mar 07, 2004 7:00 pm ]
Post subject: 

well turing is buggy so what works in one version doesnt always work in the next

for 4.05 try this instead of the original AddGradient

code:

var pos : int := 0
var colorTable : array 1 .. 255, 1 .. 3 of real
for i : 1 .. 255
    RGB.GetColor (i, colorTable (i, 1), colorTable (i, 2), colorTable (i, 3))
end for
proc AddGradient (c1, c2, n : int)
    var clr : int
    var r1, g1, b1, r2, g2, b2, p, p0 : real
    r1 := colorTable (c1, 1)
    g1 := colorTable (c1, 2)
    b1 := colorTable (c1, 3)
    r2 := colorTable (c2, 1)
    g2 := colorTable (c2, 2)
    b2 := colorTable (c2, 3)
    const a := 50
    for i : 1 .. n
        p := (i / n) * 100
        p0 := 100 - p
        RGB.SetColor (pos, (((r1 * p) + (r2 * p0)) / 2) / a, (((g1 * p) + (g2 * p0)) / 2) / a, (((b1 * p) + (b2 * p0)) / 2) / a)
        pos += 1
    end for
end AddGradient

Author:  WhatAmIDoing [ Mon Mar 08, 2004 12:31 pm ]
Post subject:  nice

ya thats a pretty cool program. and i know how stupid my class is

Author:  Atma Weapon [ Wed Mar 24, 2004 5:39 am ]
Post subject: 

I'm glad for that bump, that's really freaking awesome.

Catalyst 4 Turing God in 2004.

Author:  valor [ Thu Apr 01, 2004 9:54 pm ]
Post subject: 

nice. i like how it makes alot of diff branches


: