### Author Topic: Fraktal-Bäume  (Read 3563 times)

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10762
• here on my island the sea says 'hello'
##### Fraktal-Bäume
« on: 2004-Mar-29 »
Na, wie wär's mit schönen 3D-Bäumen mit Blättern usw...? Hier ist ein einfaches Grundgerüst dafür:

Code: (glbasic) [Select]
// --------------------------------- //
// Project:
// Start: Monday, March 29, 2004
// IDE Version: 1.40327

// rule = â€œl [ + l ] l [ - l] lâ€ [Jürgens Hartmut, Peitgen Heinz-Otto, Saupe Dietmar:
//                                Fraktale - eine neue Sprache für komplexe Strukturen,
//                                Spektrum der Wissenschaft (9/1989), p.62.] with
// l = line
// + = +28.58 degrees
// - = -28.58 degrees
// [ = start of a branch
// ] = end of a branch

NewBranch(200,200,0, 0, -90, 0, 10)
SHOWSCREEN
MOUSEWAIT

// ------------------------------------------------------------- //
// -=#  NEWBRANCH  #=-
// ------------------------------------------------------------- //
FUNCTION NewBranch: x, y, z, phi, psi, depth, maxdepth

LOCAL ex, ey, ez, px, py, pz, lngth, ln_bottom, dphi, dpsi
LOCAL n, nbranches, col
lngth = 100/(1+depth)
ln_bottom = lngth*COS(psi)
nbranches = 2

ex = x + COS(phi)*ln_bottom
ey = y + SIN(psi)*lngth
ez = z + SIN(phi)*ln_bottom

IF (depth FOR n=1 TO nbranches
pos = n/(nbranches+1)
px = x+(ex-x)*pos
py = y+(ey-y)*pos
pz = z+(ez-z)*pos

dphi = phi + (RND(2)-1)*28.58
dpsi = psi + (RND(2)-1)*28.58
NewBranch(px, py, pz, dphi, dpsi, depth+1, maxdepth)
NEXT
ENDIF

col = RGB(200 - 200*(depth/maxdepth), 64+128*(depth/maxdepth), 0)
// Front
DRAWLINE x, y, ex, ey, col
// Left
DRAWLINE z+120, y, ez+120, ey, col
// Top
DRAWLINE x, z+320, ex, ez+320, col
ENDFUNCTION

Und ein Bild: