Welcome Guest, you are in: Login

Fruit Of The Shed

Navigation (MMBasic)






Search the wiki

»


Colour Demos

Page discussion for Colour Demos
Speeding up Julia.bas in MMBasic 4.4/4.52018/03/03 16:55 by rave
Very nice color demos!

Since we can use EXIT FOR, why not speed up Julia.bas with a FOR loop and EXIT FOR? I've also removed repeated calculations to increase the speed further.

So I suggest the following change to the "Loop processing" part:

MODE 3
CLS

'Specify initial values
RealOffset = -1.30
ImaginOffset = -1.22
'------------------------------------------------*
'Set the Julia set constant [eg C = -1.2 + 0.8i]
CRealVal = -0.78
CImagVal = -0.20
'------------------------------------------------*
MAXIT=80 'max iterations
PixelWidth = MM.HRES
PixelHeight = MM.VRES
GAP = PixelHeight / PixelWidth
SIZE = 2.50
XDelta = SIZE / PixelWidth
YDelta = (SIZE * GAP) / PixelHeight

'Loop processing - visit every pixel
FOR X = 0 TO (PixelWidth - 1)
  CX = X * Xdelta + RealOffset
  FOR Y = 0 TO (PixelHeight - 1)
    CY = Y * YDelta + ImaginOffset
    Zr = CX
    Zi = CY
    COUNT = 0
    'Begin Iteration loop
    FOR COUNT = 0 TO MAXIT-1
      Zr2 = Zr*Zr: Zi2 = Zi*Zi
      IF Zr2+Zi2 >= 4 THEN EXIT FOR
      Zi = 2*Zr*Zi+CImagVal: Zr = Zr2-Zi2+CRealVal
    NEXT COUNT   
    PIXEL(X,Y) = COUNT MOD 8
  NEXT Y
NEXT X
DO
  a$ = INKEY$
LOOP WHILE a$ = ""