Page 1 of 1

The beauty of z^2 + c

Posted: Sun Jun 25, 2006 6:25 pm
by remi_meier
Code updated For 5.20+

Found this a year ago while experimenting with Mandelbrot's set. Just
animated it a bit. Enjoy!
(if it stops, just move the cursor over the window)

Code: Select all

    #S = 512
    img = CreateImage(#PB_Any, #S, #S)


    OpenWindow(0, 200, 200, #S, #S, "Test")
;     CreateGadgetList(WindowID(0))
    ImageGadget(0, 0, 0, #S, #S, ImageID(img))


    anzFelder.l = #S
    aktseite.f = 2.5
    ecke_re.f = -1.65
    ecke_im.f = -1.25
    spalt.f = aktseite / anzFelder
    Repeat
      StartDrawing(ImageOutput(img))
      Box(0, 0, anzFelder, anzFelder, 0)
      ecke_re + 0.0001
      For n.l = 0 To anzFelder - 1 Step 11
        c_re.f = ecke_re + n * spalt
        For m.l = 0 To anzFelder - 1 Step 11
          c_im.f = ecke_im + m * spalt
         
          z_re.f = 0
          z_im.f = 0
         
          zaehler.l = 0
          Repeat
            t.f = 2 * z_re * z_im + c_im
            z_re = z_re * z_re - z_im * z_im + c_re
            z_im = t
           
            x = (z_re - ecke_re) / spalt
            y = (z_im - ecke_im) / spalt
            If x < #S And  y < #S And x >= 0 And y >= 0
              Plot(x, y, zaehler * 1.27)
            EndIf
           
            zaehler + 1
          Until zaehler > 200
        Next
      Next
      StopDrawing()
     
      SetGadgetState(0, ImageID(img))
    Until WaitWindowEvent() = #PB_Event_CloseWindow

Posted: Sun Jun 25, 2006 6:37 pm
by Comtois
Syntax error

Code: Select all

 If x >= #S Or y >= #S Or x < 0 Or y <0> 200
so i write

Code: Select all

If x >= #S Or y >= #S Or x < 0 Or y <or> 200
Then i gate
---------------------------
PureBasic
---------------------------
Ligne 36: Another 'End Condition' operand is expected here
---------------------------
OK
---------------------------


Can you post all the code please ? :)

Posted: Sun Jun 25, 2006 6:39 pm
by Leonhard

Code: Select all

If x >= #S Or y >= #S Or x < 0 Or y <0> 200
to

Code: Select all

If x >= #S Or y >= #S Or x < 0 Or y < 0
Else
Plot(x, y, zaehler * 1.27)
EndIf

Posted: Sun Jun 25, 2006 6:43 pm
by remi_meier
:shock:
That was the forum! In the German forum the code was correctly shown :!:

Fred :?:

Edit: Damn, there is no way I can post it correctly here :shock:
You have to go to
http://www.purebasic.fr/german/viewtopi ... 8857#98857

Posted: Sun Jun 25, 2006 7:15 pm
by Joakim Christiansen
I found out that you have to disable html, there should be an announcement about this!

Posted: Sun Jun 25, 2006 7:22 pm
by remi_meier
Ok, worked :)

Posted: Mon Jun 26, 2006 1:35 am
by netmaestro
Beautiful! Thanks. Btw, if you use WaitWindowEvent(1) it won't stop and need a mousemove.

Posted: Mon Jun 26, 2006 10:52 am
by MikeB
I don't know what is wrong, but it does not seem to work for me. I downloaded from the German forum and tried it and after having a blank window for about 10 seconds it eventually drew a pattern that then never changed. :(

I added the (1) to the WaitWindowEvent() and it started making a slight change to the dots about every 10 seconds, but if you don't keep watching you would not see a difference. As far as I can see it keeps changing from one pattern to the other every 10 seconds and then back again. :(

I feel sure it must be supposed to do more than that, but that is all that happens here. Incidentally, if I click on the window it stops altogether and says "not responding" in the titlebar. :?

Posted: Mon Jun 26, 2006 12:45 pm
by remi_meier
Yes, it needs a lot of CPU.
To speed up, you can do the following things:
- make #S smaller
- use FastImageOutput of S.M.
- increase the Step values (11)
- decrease the number in "Until zaehler > 200", for the right colors, you
also have to change the Plot color to "zaehler * 255.0 / 200" where 200
is your number (same as in Until...).

I hope this helps :)