# Triangle fractal recursiv

DECLARE SUB TRI (X, BY, B, H, C, n)

COMMON SHARED B, BY, C

SCREEN 12

n = 8

CONST EQ = .8860254#
B = 200 ' half edge
H = (B * 2 * EQ) ' high
X = 320 ' Sommet 0
C = 15 ' Color
BY = 480 - ((480 - (B * 2 * EQ)) / 2) ' Base line

' coordinates :

'BL = (320 - B, BY) ' base left
'BR = (320 + B, BY)
'S = (320, BY - (B * 2 * .866)) ' peak

'PSET (320, 240)

LINE (X - B, BY)-(X + B, BY), C
LINE -(X, BY - H), C
LINE -(X - B, BY), C

'Upside Down :

'S = (320, BY)
'RU = (320 + B / 2, BY - ((B * 2 * EQ)) / 2)
'LU = (320 - B / 2, BY - ((B * 2 * EQ)) / 2)

LINE (X, BY)-(X + B / 2, BY - H / 2), C
LINE -(X - B / 2, BY - H / 2), C
LINE -(X, BY), C

CALL TRI(X, BY, B, H, C, n)

a\$ = INPUT\$(1)

SYSTEM

END

SUB TRI (X, BY, B, H, C, n)

IF n <= 1 THEN EXIT SUB

LINE (X, BY)-(X + B / 2, BY - H / 2), C
LINE -(X - B / 2, BY - H / 2), C
LINE -(X, BY), C

CALL TRI(X - B / 2, BY, B / 2, H / 2, C, n - 1)
CALL TRI(X + B / 2, BY, B / 2, H / 2, C, n - 1)

CALL TRI(X, BY - H / 2, B / 2, H / 2, C, n - 1)

END SUB

Posted on Sep 28, 2010, 12:19 PM

 Response Title Author and Date Beautiful! ... TheBOB on Sep 28 Colors Lisztfr on Sep 28 *The colors thing is great, and yes, I should have commented on the code -- very elegant! TheBOB on Sep 28 *Thanks, but not running in XP ? Lisztfr on Sep 29 I have Windows 7... TheBOB on Sep 29 Vesa stuff .. ? Lisztfr on Sep 30 I didn't make the patch. Found it at Phatcode.net. Clippy on Sep 30 Micro\$oft's goal is to eventually create operating systems that any idiot can run... Not Really Bill Gates on Sep 30 *I would love to see how many they would sell, if they didn't come bundled with new comps! TheBOB on Oct 1