• Welcome to Dark Bit Factory & Gravity.
 

Tree Trouble

Started by ScottyBrosious, June 18, 2007

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ScottyBrosious

I am haveing trouble makeing this look like a real tree.
Can anyone help?

dim bt(126)

dim xtemp(126)
dim ytemp(126)

screen 18

screenwidth  = 640
screenheight = 480

angle = 35

mult = 1
add  = 1

bt(0) = 90

bt(index + mult + position) = bt(0) + angle
bt(index + mult + position + add) = bt(0) - angle

print bt(0)

mult = mult * 2
num2 = 2

a = 1

for j = 0 to 4

num = mult - 1

for i = num to num2

if i <  mult then position = 0
if i >= mult then position = position + 1

bt(i + mult + position) = bt(a) + angle
bt(i + mult + position + add) = bt(a) - angle

print bt(i);" ";

a = a + 1

next i

print

old = old + mult
mult = mult * 2

num2 = old + mult

next j

print

gosub render

sleep

end

render:

a = 1
b = 2
c = 0

mult1 = 2
mult2 = 4

pi# = 3.1415926

x1 = screenwidth / 2
y1 = screenheight

lenght = screenheight / 4

xtemp(0) = x1 + -cos(bt(0) * pi# / 180) * lenght
ytemp(0) = y1 + -sin(bt(0) * pi# / 180) * lenght

line(x1,y1)-(xtemp(0),ytemp(0)),15

for j = 0 to 4

lenght = lenght / 1.4

for i = a to b

if j > 0 and d = 0 then c = c + 1

xtemp(i) = xtemp(c) + -cos(bt(i) * pi# / 180) * lenght
ytemp(i) = ytemp(c) + -sin(bt(i) * pi# / 180) * lenght

line(xtemp(c),ytemp(c))-(xtemp(i),ytemp(i)),15

d = d + 1
if d = 2 then d = 0

next i

if j > 0 then mult1 = mult1 * 2
if j > 0 then mult2 = mult2 * 2

a = a + mult1
b = b + mult2

next j

return



Jim

I guess the problem is that it's a little too regular.  One thing you can do is add some randomness in.  For instance I just had a quick go changing

bt(i + mult + position) = bt(a) + angle
bt(i + mult + position + add) = bt(a) - angle

to

bt(i + mult + position) = bt(a) + angle * rnd()
bt(i + mult + position + add) = bt(a) - angle * rnd()

and

xtemp(i) = xtemp(c) + -cos(bt(i) * pi# / 180) * lenght
ytemp(i) = ytemp(c) + -sin(bt(i) * pi# / 180) * lenght

to

xtemp(i) = xtemp(c) + -cos(bt(i) * pi# / 180) * lenght * rnd()
ytemp(i) = ytemp(c) + -sin(bt(i) * pi# / 180) * lenght * rnd()


That makes an enormous difference.  The other thing you might want to look in to is splitting some branches more than others, or splitting in to more than two parts.

Jim
Challenge Trophies Won:

Shockwave

Needs to be rendered out of something more organig looking too, maybe using sprites instead of lines or something.
Nice enough fractal though :)
Shockwave ^ Codigos
Challenge Trophies Won: