# Fractale

September 21 2010 at 5:23 AM

Draw this fractal they write about in known site, with the condition to use a recursive sub. This is mandatory, alas beyond my skills.

First figure is a ...

First, the main program draws draws the initial triangle. Then it calls the recursive subroutine to draw an upside-down triangle in the center of it :

http://tinyurl.com/38zhmm4

In the example, only 1 triangle is drawn at each recursion... in the right lower corner, so this is easy.

Another question is how to make recursion when at some step the number of variable is growing allot... (computing exponentials)

Thanks, l

 Respond to this message
David

# It;'s called a Sierpinski Gasket

September 21 2010, 10:37 AM
 SCREEN 12 DEFLNG A DEFDBL G, P-Z DATA 0,0,0,0,31,63,0,63,63,0,63,0,31,63,0,63,63,0,63,31,0,63,0,0,63,47,47,63,63,63 FOR I = 0 TO 9 READ A1, A2, A3 PALETTE I, A1 * 65536 + A2 * 256 + A3 NEXT I RANDOMIZE TIMER PI = 3.1415927# N = 3 mm = 1 M = 1 DIM X(N), Y(N) FOR I = 1 TO N Y(I) = COS(2 * PI * I / N) X(I) = SIN(2 * PI * I / N) NEXT I FOR j = 1 TO N k = j + 1 IF k > N THEN k = 1 LINE (300 + 240 * X(j), 230 - (Y(j) * 230))-(300 + 240 * X(k), 230 - (230 * Y(k))) NEXT j QX = RND * 620 + 10 QY = RND * 460 + 10 QX = X(1): QY = Y(1) FOR I = 1 TO 150000 F = INT(RND * N) + 1 GX = (mm * QX + M * X(F)) / (mm + M) GY = (mm * QY + M * Y(F)) / (mm + M) IGX = 300 + INT(240 * GX + .5): IGY = 230 - INT(230 * GY + .5) Z = POINT(IGX, IGY) + 1 IF Z > 9 THEN Z = 1 IF I > 10 THEN PSET (IGX, IGY), Z QX = GX: QY = GY NEXT I END
 Respond to this message
Lisztfr

# *Amazing colors, and depth !

September 22 2010, 1:35 AM
 Takes about 5 second to compute on a 750 P III.
 Respond to this message

R

# * Comes up instantly in QB64

September 23 2010, 11:40 PM
 Respond to this message
Anonymous

# look at this

September 28 2010, 10:02 PM
 SCREEN 12 xx = 510 FOR y = 0 TO 480 FOR x = 0 TO xx IF (x AND y) = 0 THEN PSET (x - xx / 2 + 320, 480 - y) NEXT xx = xx - 1 NEXT
 Respond to this message
Lisztfr

# Sierpinski ?

October 2 2010, 5:48 AM
 Well done... Someone means that mine isn't a real Sierpinski, why ? Because there are only lines, the inverted figure is not fully painted ?
 Respond to this message
Lisztfr

# Ugly...

October 2 2010, 6:27 AM
 Why is it supposed to work ? How to set the depth ? Why not write in in assembly it would be more understandable. Dear newbies, pass away, "Horseman, pass by" (Keats)
 Respond to this message

# Sierpinsky recursiv

September 28 2010, 12:17 PM
 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
 Respond to this message
david

# Why limit yourself to triangles?

October 6 2010, 4:49 AM
 SCREEN 12 DEFLNG A DEFDBL G, P-Z DATA 0,0,0,0,31,63,0,63,63,0,63,0,31,63,0,63,63,0,63,31,0,63,0,0,63,47,47,63,63,63 FOR I = 0 TO 9 READ A1, A2, A3 PALETTE I, A1 * 65536 + A2 * 256 + A3 NEXT I RANDOMIZE TIMER PI = 3.1415927# n = 5 mm = .8 M = 1.2 DIM X(n), Y(n) FOR I = 1 TO n Y(I) = COS(2 * PI * I / n) X(I) = SIN(2 * PI * I / n) NEXT I FOR j = 1 TO n k = j + 1 IF k > n THEN k = 1 LINE (300 + 240 * X(j), 230 - (Y(j) * 230))-(300 + 240 * X(k), 230 - (230 * Y(k))) NEXT j FOR I = 1 TO 150000 f = INT(RND * n) + 1 GX = (mm * QX + M * X(f)) / (mm + M) GY = (mm * QY + M * Y(f)) / (mm + M) IGX = 300 + INT(240 * GX + .5): IGY = 230 - INT(230 * GY + .5) Z = POINT(IGX, IGY) + 1 IF Z > 9 THEN Z = 1 IF I > 10 THEN PSET (IGX, IGY), Z QX = GX: QY = GY NEXT I END
 Respond to this message
Clippy
R

# * VERY nice!

October 8 2010, 11:32 AM

 This message has been edited by burger2227 on Oct 8, 2010 11:40 AM

 Respond to this message