Hi all
Found this code for qbasic and have modfiy it to work in DBPro takes about 2000 conts before it starts to look bent.
Rem Project: mandeltrees
Rem Created: 08/04/2006 10:31:47
Rem ***** Main Source File *****
REM Initialization
`SCREEN 12
set display mode 1024,768,16
randomize timer()
S = 10
`WINDOW (-S, -S)-(S, S)
REM NIter is the number of iterations
sync off
sync rate 0
NIter = 12
TPoints = 2 ^ NIter
Length# = S / 2
Stp = TPoints / 4
K# = 1 / SQRt(2)
REM a(x, y)holds the coordinates of every branch tip
DIM a(TPoints, 2) as float
REM Calculate plain tree
FOR i = 1 TO NIter - 1
FOR x = Stp TO TPoints STEP Stp * 4
IF i MOD 2 = 0
a(x, 0) = a(x + Stp, 0)
a(x + 2 * Stp, 0) = a(x + Stp, 0)
a(x, 1) = a(x + Stp, 1) - Length#
a(x + 2 * Stp, 1) = a(x + Stp, 1) + Length#
ELSE
a(x, 0) = a(x + Stp, 0) - Length#
a(x + 2 * Stp, 0) = a(x + Stp, 0) + Length#
a(x, 1) = a(x + Stp, 1)
a(x + 2 * Stp, 1) = a(x + Stp, 1)
ENDIF
NEXT x
Stp = Stp / 2
Length# = Length# * K#
NEXT i
do
CLS
REM Leave the program when pressing any key
text 0,0,str$(t)+ " fps="+str$(screen fps())
rem +" alfa#="+str$(Alfa#)+" rn="+str$(rn)+" alpha2="+str$( RND(8)* St#)+" st#="+str$(st#)
IF INKEY$() <> "" THEN END
Stp = TPoints / 4
g=50
REM Draw tree
FOR i = 1 TO NIter - 1
FOR x = Stp TO TPoints STEP Stp * 4
x0 = a(x, 0)*g
y0 = a(x, 1)*g
P2 = 2 * Stp
x1 = a(x + P2, 0)*g
y1 = a(x + P2, 1)*g
LINE (screen width()/2)-x0, (screen height()/2)-y0,(screen width()/2)-x1,(screen height()/2)-y1
NEXT x
Stp = Stp / 2
NEXT i
sync
Stp = TPoints / 4
Pi# = 3.14159
St# = Pi# / 128.0
REM Rotate Tree Randomly
FOR i = 1 TO NIter - 1
Counter = 0
FOR x = Stp TO TPoints - 1 STEP Stp * 2
P2 = 2 * Stp
Counter = Counter + 1
Ax# = a(x, 0)
Ay# = a(x, 1)
Az# = a(x, 2)
IF Counter MOD 2 = 1
Bx# = a(x + P2, 0)
By# = a(x + P2, 1)
Bz# = a(x + P2, 2)
ELSE
Bx# = a(x - P2, 0)
By# = a(x - P2, 1)
Bz# = a(x - P2, 2)
ENDIF
Mn# = SQRt((Bx# - Ax#) ^ 2 + (By# - Ay#) ^ 2 + (Bz# - Az#) ^ 2)
nx# = (Bx# - Ax#) / Mn#
ny# = (By# - Ay#) / Mn#
nz# = (Bz# - Az#) / Mn#
Alfa# = RND(8)* St#
rn=rnd(10)
if rn>5
Alfa# = -Alfa#
endif
if rn<10
alfa#=alfa#
endif
ca# = COS(Alfa#)
sa# = SIN(Alfa#)
FOR j = x - Stp + 1 TO x + Stp - 1
Px# = a(j, 0) - Ax#
Py# = a(j, 1) - Ay#
Pz# = a(j, 2) - Az#
nPEscalar# = nx# * Px# + ny# * Py# + nz# * Pz#
nnPx# = nPEscalar# * nx#
nnPy# = nPEscalar# * ny#
nnPz# = nPEscalar# * nz#
cx# = ca# * (Px# - nnPx#)
cy# = ca# * (Py# - nnPy#)
cz# = ca# * (Pz# - nnPz#)
snxPx# = sa# * (ny# * Pz# - nz# * Py#)
snxPy# = sa# * (nz# * Px# - nx# * Pz#)
snxPz# = sa# * (nx# * Py# - ny# * Px#)
a(j, 0) = nnPx# + cx# + snxPx# + Ax#
a(j, 1) = nnPy# + cy# + snxPy# + Ay#
a(j, 2) = nnPz# + cz# + snxPz# + Az#
NEXT j
NEXT x
Stp = Stp / 2
NEXT i
`sync
inc t
loop
remstart
REM Initialization
SCREEN 12
S = 10
WINDOW (-S, -S)-(S, S)
REM NIter is the number of iterations
NIter = 12
TPoints = 2 ^ NIter
Length = S / 2
Stp = TPoints / 4
K = 1 / SQR(2)
REM a(x, y)holds the coordinates of every branch tip
DIM a(TPoints, 2)
REM Calculate plain tree
FOR i = 1 TO NIter - 1
FOR x = Stp TO TPoints STEP Stp * 4
IF i MOD 2 = 0 THEN
a(x, 0) = a(x + Stp, 0)
a(x + 2 * Stp, 0) = a(x + Stp, 0)
a(x, 1) = a(x + Stp, 1) - Length
a(x + 2 * Stp, 1) = a(x + Stp, 1) + Length
ELSE
a(x, 0) = a(x + Stp, 0) - Length
a(x + 2 * Stp, 0) = a(x + Stp, 0) + Length
a(x, 1) = a(x + Stp, 1)
a(x + 2 * Stp, 1) = a(x + Stp, 1)
END IF
NEXT x
Stp = Stp / 2
Length = Length * K
NEXT i
di:
CLS
REM Leave the program when pressing any key
IF INKEY$ <> "" THEN END
Stp = TPoints / 4
REM Draw tree
FOR i = 1 TO NIter - 1
FOR x = Stp TO TPoints STEP Stp * 4
x0 = a(x, 0)
y0 = a(x, 1)
P2 = 2 * Stp
x1 = a(x + P2, 0)
y1 = a(x + P2, 1)
LINE (x0, y0)-(x1, y1)
NEXT x
Stp = Stp / 2
NEXT i
Stp = TPoints / 4
Pi = 3.14159
St = Pi / 128
REM Rotate Tree Randomly
FOR i = 1 TO NIter - 1
Counter = 0
FOR x = Stp TO TPoints - 1 STEP Stp * 2
P2 = 2 * Stp
Counter = Counter + 1
Ax = a(x, 0)
Ay = a(x, 1)
Az = a(x, 2)
IF Counter MOD 2 = 1 THEN
Bx = a(x + P2, 0)
By = a(x + P2, 1)
Bz = a(x + P2, 2)
ELSE
Bx = a(x - P2, 0)
By = a(x - P2, 1)
Bz = a(x - P2, 2)
END IF
Mn = SQR((Bx - Ax) ^ 2 + (By - Ay) ^ 2 + (Bz - Az) ^ 2)
nx = (Bx - Ax) / Mn
ny = (By - Ay) / Mn
nz = (Bz - Az) / Mn
Alfa = INT(RND * 8) * St
IF RND > .5 THEN Alfa = -Alfa
ca = COS(Alfa)
sa = SIN(Alfa)
FOR j = x - Stp + 1 TO x + Stp - 1
Px = a(j, 0) - Ax
Py = a(j, 1) - Ay
Pz = a(j, 2) - Az
nPEscalar = nx * Px + ny * Py + nz * Pz
nnPx = nPEscalar * nx
nnPy = nPEscalar * ny
nnPz = nPEscalar * nz
cx = ca * (Px - nnPx)
cy = ca * (Py - nnPy)
cz = ca * (Pz - nnPz)
snxPx = sa * (ny * Pz - nz * Py)
snxPy = sa * (nz * Px - nx * Pz)
snxPz = sa * (nx * Py - ny * Px)
a(j, 0) = nnPx + cx + snxPx + Ax
a(j, 1) = nnPy + cy + snxPy + Ay
a(j, 2) = nnPz + cz + snxPz + Az
NEXT j
NEXT x
Stp = Stp / 2
NEXT i
GOTO di
remend
has oragianl code in there as well.
might work in DBC.
ps. on a p3 1 ghz gets about 4 fps.
I'm not getting you down am I, Ho Look! another fancy Door?