'=========================================================================== ' Subject: MARTIN FRACTALS Date: 03-23-99 (08:41) ' Author: Jernej Simoncic Code: QB, QBasic, PDS ' Origin: jernej.simoncic@guest.arnes.si Packet: GRAPHICS.ABC '=========================================================================== ' Martin fractal program, by Alan Meiss ' Converted to basic by Jernej Simoncic ' ' Formula from "Dynamical Systems and Fractals", ' by Karl-Heinz Becker and Michael D”rfler, ' Cambridge University Press, 1990 ' DECLARE FUNCTION sign% (x AS DOUBLE) DECLARE SUB plot (x AS DOUBLE, y AS DOUBLE, clr%) DECLARE SUB martin1 (a AS DOUBLE, b AS DOUBLE, c AS DOUBLE, s AS DOUBLE) DECLARE SUB getparam () DEFINT A-Z DIM SHARED xmax, ymax, t, tcmax, tc, clr, cx, cy, code DIM SHARED sa AS DOUBLE, sav AS DOUBLE, sb AS DOUBLE, sc AS DOUBLE DIM SHARED ch AS STRING * 1 RANDOMIZE TIMER xmax = 639 ymax = 479 cx = INT(.5 + xmax / 2!) cy = INT(.5 + ymax / 2!) SCREEN 12 getparam DO sa = RND * 100! - 50! sb = RND * 100! - 50! sc = RND * 100! - 50! sav = (ABS(sa) + ABS(sb) + ABS(sc)) / 3! martin1 sa, sb, sc, 6! - ABS(sav / 10!) LOOP UNTIL ch = CHR$(27) OR ch = "q" OR ch = "Q" SCREEN 0 SUB getparam tcmax = VAL(COMMAND$) IF tcmax <= 0 THEN tcmax = 10 END SUB SUB martin1 (a AS DOUBLE, b AS DOUBLE, c AS DOUBLE, s AS DOUBLE) DIM xold AS DOUBLE, yold AS DOUBLE, xnew AS DOUBLE, ynew AS DOUBLE begin: xold = 0 yold = 0 clr = 9 + INT(.5 + INT(RND * 7)) t = 0 tc = 0 ch = "a" DO plot xold * s, yold * s, clr xnew = yold - sign(xold) * SQR(ABS(b * xold - c))' { <- This is it! These two } ynew = a - xold ' { <- lines generate the } xold = xnew ' { entire fractal! } yold = ynew t = t + 1 IF t > 1000 THEN tc = tc + 1 clr = clr + 1 IF clr > 15 THEN clr = 9 t = 0 END IF k$ = INKEY$ IF k$ <> "" THEN keypressed = -1 LOOP UNTIL keypressed OR ((tc > (tcmax - 1)) AND (tcmax > 0)) CLS IF keypressed THEN ch = k$ END SUB SUB plot (x AS DOUBLE, y AS DOUBLE, clr) PSET (INT(.5 + x) + cx, INT(.5 + y) + cy), clr END SUB FUNCTION sign (x AS DOUBLE) SELECT CASE x CASE 0 sign = 0 CASE IS < 0 sign = -1 CASE ELSE sign = 1 END SELECT END FUNCTION