home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / t / tripatron / !TripATron / mandtext < prev    next >
Text File  |  1990-05-15  |  6KB  |  141 lines

  1. The Complete Dobbers Guide to Mind Bending Mandelbrots.
  2. =======================================================
  3.  
  4.         The idea behind the mandelbrot is to measure the 'escape time' of a chaotic function.
  5. As the numbers are ploughed into the function over and over again, they fluctuate in output
  6. value until, eventually, they start to shoot off towards BIG-numbersville, Arizona. You are
  7. measuring the number of iterations needed for the function Z=Z*Z+C (where z,c are complex
  8. numbers) to head off towards BIG-numbersville, Arizona. To produce a picture in a 2D plane
  9. (your computer screen) you just vary the real and imaginary values of C and count the
  10. iterations, work out an appropriate colour and plot a point. It's so simple, it's stupid!!
  11.  
  12.         First work out Z*Z:
  13.  
  14.         (a+ib)(a+ib) = a*a + a*b*i + a*b*i + b*b*i*i
  15.                      = a*a + 2*a*b*i - b*b
  16.                        --------------------->
  17. so the formula is...
  18.  
  19.         zreal = zreal * zreal - zimag * zimag + creal
  20.         zimag = 2 * zreal * zimag + cimag
  21.  
  22. and repeat this calculation until it gets big. The definition of big will be magnitude greater
  23. than 2, as smaller numbers can keep fluctuating. Also keep a counter as some numbers can
  24. fluctuate forever, which can really toss up the calculations. If the counter gets too big,
  25. stop calculating and go on to the next one.
  26.  
  27.         And now write the program... This is written in generic basic. I don't know how to
  28. plot a pixel of a given colour on your computer, so I will call the function
  29. pixel(xpos,ypos,colour) and leave you to work it out. Also a function to turn on a graphics
  30. mode I shall call graphics(). If your version of BASIC doesn't like lower case letters, use
  31. upper case instead, stupid.
  32.  
  33.    10 graphics()
  34.    10 startreal = 0.109375000
  35.    20 startimag = 0.615234375
  36.    30 magnify = 400
  37.    40 picwidth = 100
  38.    50 picheight = 100
  39.    60 countermax = 64
  40.    70 FOR y = 0 TO picheight
  41.    80    FOR x = 0 TO picwidth
  42.    90       creal = x / magnify + startreal
  43.   100       cimag = y / magnify + startimag
  44.   110       zreal = 0
  45.   120       zimag = 0
  46.   130       counter = 0
  47.   140       REPEAT
  48.   150          zreal2 = zreal * zreal
  49.   160          zimag2 = zimag * zimag
  50.   170          dummy = zreal2 - zimag2 + creal
  51.   180          zimag = 2 * zreal * zimag + cimag
  52.   190          zreal = dummy
  53.   200          counter = counter + 1
  54.   210       UNTIL (zreal2 + zimag2 > 4) OR (counter = countermax)
  55.   220       pixel(x,y,counter)
  56.   230    NEXT x
  57.   240 NEXT y
  58.   250 END
  59.  
  60.         startreal,startimag are the coordinates of the bottom left of the image on the complex
  61. plane, usually somewhere in the range [-2,2]. magnify is the magnification factor which can be
  62. of the order of thousands. picheight,picwidth is the number of pixels the image is made of and
  63. countermax is the maximum number of iterations allowed. By setting countermax to a low value,
  64. the picture will be quickly drawn but will not be very crinkly. It is useful to keep this
  65. value low (about 16 or 32) when searching for something to look at and crank it up for a full
  66. picture. When you do this, don't forget to change the colour selection to make the picture
  67. intelligable. To do this as described below.
  68.         The real art to these pictures is the colour selection. If you only have 16 colours,
  69. you can set countermax to 255 and use:
  70.  
  71.          ...
  72.          pixel(x,y,counter/16)
  73.          ...
  74.  
  75. to spread out the colour bands. In black and white, the best idea is to use bands of black and
  76. white by using:
  77.  
  78.         ...
  79.         pixel(x,y,(counter/16)MOD2)
  80.         ...
  81.  
  82. which both spreads out the colours and sets the pixel colour to either 1 to 0. This method can
  83. be used with 16 colour graphics again by using:
  84.  
  85.         ...
  86.         pixel(x,y,counter MOD 16)
  87.         ...
  88.  
  89. which will give you bands of 0..15,0..15 over and over again. MOD n just finds the remainder
  90. in a division and is useful for repeating sections of 0..n again and again with a rising
  91. counter.
  92.  
  93.  
  94.         To get other pretty pictures, try altering the values of startreal and startimag,
  95. using magnify to zoom in. Some suggested values are:
  96.  
  97.         startreal       startimag       magnify
  98.         =======================================
  99.  
  100.         -0.3984375      0.64546875      600
  101.         -0.935078125    0.253671875     600
  102.         -0.681171875    0.43992187      600
  103.         0.438801331     -0.39064172     2000
  104.         
  105.         If you're feeling really wacky, another set of pictures that are cool can be generated
  106. by keeping C constant and varying the start values for Z over the picture. This is done by
  107. rewriting these lines...
  108.  
  109.         90 creal = startreal
  110.        100 cimag = startimag
  111.        110 zreal = (x-(picwidth/2)) / magnify
  112.        120 zimag = (y-(picheight/2)) / magnify
  113.  
  114.         These shapes are called Julia sets, as used by The Shamen, and they're best done in
  115. black and white, but the colour bands are cool.
  116.         Finally, a strange quickie. It's called POPCORN.
  117.  
  118.    10 graphics()
  119.    50 col = 0
  120.    60 h=.1
  121.    70 FOR j=1TO50
  122.    80    FOR k=1TO50
  123.    90       xo=-6+.24*j
  124.   100       yo=-6+.24*k
  125.   110       x=xo
  126.   120       y=yo
  127.   130       FOR n=1TO50
  128.   140          xx=x-h*SIN(y+TAN(3*y))
  129.   150          yy=y-h*SIN(x+TAN(3*x))
  130.   160          x=xx
  131.   170          y=yy
  132.   180          jp = 4.166*x+25
  133.   190          kp = 4.166*y+25
  134.   200          pixel(jp*5+100,kp*5+100,col)
  135.   210       NEXT
  136.   220    NEXT
  137.   230    col=col+1
  138.   240 NEXT
  139.  
  140. Go to it, matey, and no falling into them and not coming out again...
  141.