The beauty of z^2 + c

Share your advanced PureBasic knowledge/code with the community.
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

The beauty of z^2 + c

Post 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
Last edited by remi_meier on Sun Jun 25, 2006 7:21 pm, edited 4 times in total.
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post 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 ? :)
Last edited by Comtois on Sun Jun 25, 2006 6:41 pm, edited 1 time in total.
Please correct my english
http://purebasic.developpez.com/
Leonhard
User
User
Posts: 55
Joined: Fri Jun 16, 2006 7:43 am

Post 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
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post 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
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

I found out that you have to disable html, there should be an announcement about this!
I like logic, hence I dislike humans but love computers.
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

Ok, worked :)
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Beautiful! Thanks. Btw, if you use WaitWindowEvent(1) it won't stop and need a mousemove.
BERESHEIT
MikeB
Enthusiast
Enthusiast
Posts: 183
Joined: Sun Apr 27, 2003 8:39 pm
Location: Cornwall UK

Post 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. :?
Mike.
(I'm never going to catch up with the improvements to this program)
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post 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 :)
Athlon64 3700+, 1024MB Ram, Radeon X1600
Post Reply