Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:46 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : (MM) Mandelbrot & Julia set fractals

Author Message
loki
Newbie

Joined: 23/12/2011
Location: Australia
Posts: 7
Posted: 03:16am 10 Aug 2012
Copy link to clipboard 
Print this post

Hi all,

below are some fractals for your entertainment done on the MM.












The first one is the famous Mandelbrot set of course, and the next 4
are Julia sets. Julia sets are related mathematically to Mandelbrot sets.

To generate a new Julia set image just alter the values of one or both of
'CRealVal' or 'CImagVal'. Keep them both in the range -2 to +2 .
Best images seem to be when values are between -1 and 1.
By defining new values you are setting a new C constant value, where C
is the constant in the iteration algorithm for Julia sets Z <-> Z^2+C
(here Z=x+iy & C=Cx+iCy and 'i' is the imaginary number equal to the
square root of -1, or i^2=-1).

The algorithms for each type of fractal are similar:
*For Julia sets the constant is assigned a fixed value and the initial Z value
varies for each pixel on the screen.
*For Mandelbrot sets the initial Z value is always 0 and it is the C value
that varies for each pixel on the screen.

You can zoom in on both Mandelbrot and Julia sets by altering the SIZE variable.
Make the value smaller, so try 2.4, 2.3, 2.2 ... etc. The only catch is that the
zoom moves towards the top left corner, as that is (0,0) in the x,y grid. But you
can then adjust the Real and Imaginary axis (x,y) offset values,
'RealOffset' & 'ImaginOffset', to re-centre the image. It will also take longer
to render the more you zoom in.

The higher you set max. iterations MAXIT value, the more clearly defined the
'inner sea' coastlines will be, at the cost of taking longer to draw. The inner
sea represents those points that have hit the max iterations count and therefore
are part of the set.

These fractals will take many minutes to render on the MM, so probably not the
best platform for exploring fractals, but it's still interesting and fun to do.

Since there are only 2 colours on the MM, the colours are assigned via the
command COUNT MOD 2. If there were N colours you could use COUNT MOD N
(assuming PIXEL(X,Y) takes values {0,1,2,...,N-1} ).

It would be interesting to see some fractals on the new colour MM due soon. Could
be a nice way to show off the colour palette.

cheers
rob

(The mandelbrot pseudo-code I started with came from:
'Your computer' magazine 1991 - Mandelbrot article - p.90)

Some C value pairs for Julia sets that give interesting pics are:

CRealVal CImagVal
-0.71 0.35
-0.64 0.42
-0.61 0.44
-0.59 0.46
-0.59 -0.66
-0.60 -0.66
-0.80 0.39
-0.62 -0.45
-0.58 -0.65
-0.71 -0.52
-0.73 -0.22
-0.78 -0.20
0.29 -0.49

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Julia Set algorithm listing
~~~~~~~~~~~~~~~~~~~~~~~~~~~

100 'JULIA.BAS - Draws Julia set fractal images
105 'Specify initial values
120 RealOffset = -1.30
125 ImaginOffset = -1.22
126 '------------------------------------------------*
130 'Set the Julia set constant [eg C = -1.2 + 0.8i]
135 CRealVal = -0.78
140 CImagVal = -0.20
141 '------------------------------------------------*
145 MAXIT=80 'max iterations
180 PixelWidth = MM.HRES
185 PixelHeight = MM.VRES
190 GAP = PixelHeight / PixelWidth
200 SIZE = 2.50
205 XDelta = SIZE / PixelWidth
210 YDelta = (SIZE * GAP) / PixelHeight
215 CLS
220 'Loop processing - visit every pixel
225 FOR X = 0 TO (PixelWidth - 1)
230 CX = X * Xdelta + RealOffset
235 FOR Y = 0 TO (PixelHeight - 1)
240 CY = Y * YDelta + ImaginOffset
245 Zr = CX
250 Zi = CY
255 COUNT = 0
260 'Begin Iteration loop
265 DO WHILE (( COUNT <= MAXIT ) AND (( Zr * Zr + Zi * Zi ) < 4 ))
270 new_Zr = Zr * Zr - Zi * Zi + CRealVal
275 new_Zi = 2 * Zr * Zi + CImagVal
280 Zr = new_Zr
285 Zi = new_Zi
290 COUNT = COUNT + 1
295 LOOP
415 PIXEL(X,Y) = COUNT MOD 2
500 NEXT Y
510 NEXT X
520 DO
530 a$ = INKEY$
540 LOOP WHILE a$ = ""
600 'End listing


~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mandelbrot algorithm listing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

100 'MANDELBROT.BAS - Draws mandelbrot set fractal images
105 'Specify initial values
110 RealOffset = -2.0
115 ImaginOffset = -1.2
130 MAXIT=70 'max iterations
165 PixelWidth = MM.HRES
170 PixelHeight = MM.VRES
175 GAP = PixelHeight / PixelWidth
180 SIZE = 2.8
185 XDelta = SIZE / PixelWidth
190 YDelta = (SIZE * GAP) / PixelHeight
195 CLS
200 'Loop processing - visit every pixel in screen area and base colour of pixel
201 ' on the number of iterations required to escape boundary conditions
202 ' If count hits max iterations then pixel hasn't escaped and is part of the set (the 'inner sea')
205 FOR X = 0 TO (PixelWidth - 1)
210 Cx = X * Xdelta + RealOffset
215 FOR Y = 0 TO (PixelHeight - 1)
220 Cy = Y * YDelta + ImaginOffset
225 Zr = 0.0
230 Zi = 0.0
235 COUNT = 0
240 'Begin Iteration loop, checking boundary conditions on each loop
250 DO WHILE (( COUNT <= MAXIT ) AND (( Zr * Zr + Zi * Zi ) <= 4 ))
255 new_Zr = Zr * Zr - Zi * Zi + Cx
260 new_Zi = 2 * Zr * Zi + Cy
265 Zr = new_Zr
270 Zi = new_Zi
275 COUNT = COUNT + 1
280 LOOP
415 PIXEL(X,Y) = ((COUNT MOD 2) - 1) * -1
500 NEXT Y
510 NEXT X
520 DO
530 a$ = INKEY$
540 LOOP WHILE a$ = ""
600 'End listing

 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 01:03am 11 Aug 2012
Copy link to clipboard 
Print this post

Colour Pictures, done on the ubw32 colourMM. Used savebmp at end of render..





Cheers MM_Wombat

Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024