Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watnot.UUCP Path: utzoo!watmath!watnot!cgoudeseune From: cgoudeseune@watnot.UUCP (Camille Goudeseune) Newsgroups: net.graphics,net.math Subject: Re: Exp. Math & Fractal Dragons (HELP!) (133 lines) Message-ID: <11282@watnot.UUCP> Date: Mon, 15-Jul-85 20:38:53 EDT Article-I.D.: watnot.11282 Posted: Mon Jul 15 20:38:53 1985 Date-Received: Wed, 17-Jul-85 04:08:06 EDT References: <1659@saber.UUCP> Reply-To: cgoudeseune@watnot.UUCP (Camille Goudeseune) Distribution: net Organization: U of Waterloo, Ontario Lines: 142 Keywords: dragon fractal frustration Xref: watmath net.graphics:919 net.math:2140 Summary: THE fractal dragon is an elusive beast. In response to the dragon-hunters out there who may have had more success than i've had, and those who want to attempt it soon, a plea for more info, and a few tips and pointers: 1. When writing your code, check it 10^9 times for mechanical errors. The conversion of the formula f(z)=(lambda)*z*(1-z), trivial as it may seem, caused me to waste about a week of effort, because the output STILL looked rather nifty... 2. Use a high-resolution output device if at all possible. If you have to pay for your account, I sympathize, but it makes seeing patterns in the dragons you produce possible as opposed to near-impossible. (I consider 200 by 200 the bare minimum. 2000 by 2000 is much nicer.) 3. This almost goes without saying - make your code as efficient as possible, but if you're not yet sure if you've cornered the dragon to some degree, don't spend too much time optimizing what will have to be rewritten. Trivial hints that I beg of you not to flame me for: 3.1 Do as much calculation OUTSIDE loops as possible, i.e. avoid using the computer to do the same thing twice (or n times, at that!) 3.2 At the same time, if you have two loops doing separate things that could be combined into one loop, DO SO. (Even if it throws structured programming out the window!) I've never actually seen these pointers in print, but I may have been forced to adopt these methods while I was mucking about on a ZX81, the ultimate machine for teaching efficient programming. 4. (Plea for help) I have managed to produce a reasonable replica of the dragon (on page C4 of The Fractal Geometry of Nature), but the only problem is that, where each 'tentacle' of the original consists of 'stones' connected by numerous 'wasp waists' (Mandelbrot's words), my tentacles have no wasp waists, just uniform, well, tentacles, that have frilly minitentacles attached at numerous intervals. Something like this: % % $ .,' % $ % % % & ,,. ============================ .'' ! / \ $ # % $ & !^, ~ $ % % ^ & but wigglier. If you want, each tentacle has only one stone. I am using f(z)=lambda * z * (1-z), with lambda=1.64 + 0.96*i, I've tried approximations of lambda to 0.1 each way, and the algorithm I'm using amounts to an efficient version of creating a 2k by 2k array of pixels corresponding to the square centered on zero on the complex plane with corners +- 1.4 +- 1.4i , applying the formula about 95 times for each point in the array, and if, at any time during these iterations the image of the point goes outside the circle centered on zero with 'radius' 1.4, discarding that point as not being part of the dragon. (1.4 is my approximation for infinity.) If, after all the iterations for a given point, it is still within the circle, I set that pixel to 1. (otherwise 0.) Is there something fundamentally wrong with my algorithm, or what? HELP! It seems simple enough to be bug-free; here is the Berkely pascal source code, for those who want it. If nothing else, it does produce pretty patterns at mildly shocking cpu expense (something to run on your micro at home for a week?). a few notes: my output device uses as input a binary file, one row or scan line = 264 bytes = 2112 pixels. The program generates the dragon 1 scan-line at a time, writing the bits to a file at the end of each line. Typical input for the program: 1.64 0.960 1.5 1.4 1500program main(input, output); { ******** FRACTAL DRAGON ********** } const c0 = 2111;{# of pixels} c1 = 263; {# of bytes} var e, f, m, width, i, j, a, b, r, u, v: real; c, ch, k, k1, size, scol: integer; s: array [0..c0] of char; t: array [0..8] of integer; begin t[0] := 1; {table of powers of 2, used in constructing bytes.} for k := 1 to 8 do t[k] := t[k - 1] * 2; { Input e, f, radius, square size, & output size } readln(e, f, r, m, size); width := m / (size / 2); a := -m/2; { modified starting points here... } r:=r*r; { in the sake of efficiency } while a <= m do begin b := -m * 0.75; { and here. } scol := 0; while b <= m do begin k := 0; i := a; j := b; { 90 * iterations for each pixel } while (k < 90) and (i * i + j * j < r) do begin u := j * j + i * (1 - i); { (i,j) := f(i,j) - pardon my } v := j * (i + i - 1); { use of these letters in a } i := e * u + f * v; { complex context! } j := f * u - e * v; k := k + 1; end; if k = 90 then s[scol] := 'x'; {aha! this pixel is in the dragon! } scol := scol + 1; b := b + width end; for k:= 0 to c1 do begin ch := 0; for c := 0 to 7 do {construct this byte from 8 bits} begin k1 := k * 8 + 7 - c; if s[k1] = 'x' then ch := ch + t[c]; s[k1] := ' '; {reset this pixel for next scanline } end; write(chr(ch)) {write out these 8 bits.} end; a := a + width; {next scanline...} end; end. I will be reasonably happy to answer questions about this code and hereby forfeit my right to earn a fortune on it by decreeing it to be public-domain, in the better interests of all who search for the elusive fractal dragon. (Almost as much fun as rogue :-) !) Camille Goudeseune (after august 5/85, real mail only at: 2054 waycross cres., Mississauga, Ont., Canada L5K 1H9.) =============================================================================== just because you're not paranoid doesn't mean that nobody's following you!