Imaginäre Zahl berechnen (Fraktale)

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

Firstdeathmaker

Betreff: Imaginäre Zahl berechnen (Fraktale)

BeitragMi, Mai 05, 2004 19:48
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi, ich beschäftige mich gerade mit Fraktalen, bin aber erst gerade auf das Thema gestoßen, und wollte jetzt selber auch mal eines errechnen lassen. Ich hab mir auf http://home.t-online.de/home/Siegfried.Beyer/
mal das Tutorial zum Apfelmännchen durchgelesen, aber ich weis nicht wie ich die Formel richtig in BB umsetzten soll. Kann mir jmd dabei helfen?

Bis jetzt habe ich das so verstanden:

Man setzt einfach den Bildschirmnullpunkt in die Mitte. Dann muss man nachher nur noch die y-Werte umkehren.

Dann berechnet man mit folgender Formel den neuen Zahlenwert:

Z=Z²+C

Wobei C für C=xpos,ypos*i steht. i ist eine Imaginäre Zahl (-1)²

Also habe ich ein Dim Feld erstellt, mit genau so vielen Feldern drin wie ich Pixel auf dem Bildschirm hab.
Dim Pixel$(Graphics_X,Graphics_Y,0) ;Graphics_X+Y hab ich vorher als Const festgelegt und mit den Werten auch initialisiert.

Jetzt hab ich aber das Problem: Wie kann ich in BB mit einer Imaginären Zahl rechnen?
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon
Gewinner des BCC #57 User posted image
 

walski

Ehemaliger Admin

BeitragDo, Mai 06, 2004 15:15
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich hab den beiliegenden Pascal Code mal nach BB übersetzt, allerdings ohne mir den irgendwie dabei zu verinnerlichen Smile

Naja, vielleicht lernst du ja so was.

Code: [AUSKLAPPEN]

; (C) Siegfried Beyer, 2001
; nach Benoit Mandelbrot
; siehe U. Beck: "Computergrafik", S. 240 - 254 }
; translated to BlitzBasic 2004 by T.Schroeder

; max = maximale Iterationszahl | amin,amax = minimale und maximale Abszisse || bmin,bmax = minimale und maximale Ordinate || xsmax,ysmax = Bildgroesse
Const max# = 25,amin# = -2.40,amax# = 1.60,bmin# = -1.75,bmax# = 1.75,xsmax = 639,ysmax = 479

Local radius#,a#,b#,da#,db#,x#,y#,xneu#,yneu#
Local gd,gm,n,xs,ys


Graphics xsmax,ysmax,32,2

  da = (amax-amin) / xsmax
  db = (bmax-bmin) / ysmax

  ; pixelweise Durchmusterung des Bildes
  a = amin
  For xs=0 To xsmax
    b = bmax
    For ys=0 To Int(ysmax / 2)
      x=a
     y=b                                       
      n=0

      ; Iterationsschleife
      Repeat
        xneu = x*x - y*y + a
        yneu = 2*x*y + b
        x = xneu
       y = yneu                       
        radius = x*x + y*y
        n = n + 1
      Until (n > max) Or (radius > 9)                          ; wird Kreis verlassen
      If n < max Then
        pas_color(n Mod 16)
      Plot xs, ys              ; dann Punkt faerben
     EndIf
   
      If n < max Then
      pas_color(n Mod 16)
      Plot xs, ysmax-ys        ; Symmetrie
     EndIf

      b = b - db                               ; Imaginaerteil des Pixels
    Next ;ys-Schleife
    a = a + da                                       ; Realteil des Pixels
  Next ;xs-Schleife

WaitKey()


;sets the color with pascal color code
Function pas_color(pas_color)
   Select pas_color
      Case 0
         Color 0,0,0
      Case 1
         Color 0,0,200
      Case 2
         Color 0,200,0
      Case 3
         Color 0,200,200
      Case 4
         Color 200,0,0
      Case 5
         Color 200,0,200
      Case 6
         Color 128,64,0
      Case 7
         Color 200,200,200
      Case 8
         Color 100,100,100
      Case 9
         Color 0,0,255
      Case 10
         Color 0,255,0
      Case 11
         Color 0,255,255
      Case 12
         Color 255,0,0
      Case 13
         Color 255,0,255
      Case 14
         Color 255,255,0
      Case 15
         Color 255,255,255
   End Select
End Function


Die Farben sind sicher sehr grausam, aber ich hab wie gesagt alles so übernommen, wie es war.

walski
buh!

Firstdeathmaker

BeitragDo, Mai 06, 2004 15:45
Antworten mit Zitat
Benutzer-Profile anzeigen
Vielen Dank! Dann werd ich mal den Code untersuchen und versuchen den ganzen Kram zu verstehen.
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon
Gewinner des BCC #57 User posted image

Travis

BeitragMi, Jul 14, 2004 19:17
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich habe mir mal erlaubt ein bisschen Speedtuning an dem Code vorzunehmen und habe es nach WritePixelFast umgestellt und eine Zeitmessfunktion eingebaut.

Code: [AUSKLAPPEN]

; (C) Siegfried Beyer, 2001
; nach Benoit Mandelbrot
; siehe U. Beck: "Computergrafik", S. 240 - 254 }
; translated to BlitzBasic 2004 by T.Schroeder
; speedoptimiert by D.Nobis

; max = maximale Iterationszahl | amin,amax = minimale und maximale Abszisse || bmin,bmax = minimale und maximale Ordinate || xsmax,ysmax = Bildgroesse
Const max# = 25,amin# = -2.40,amax# = 1.60,bmin# = -1.75,bmax# = 1.75,xsmax = 1024,ysmax = 768

Local radius#,a#,b#,da#,db#,x#,y#,xneu#,yneu#
Local gd,gm,n,xs,ys


Graphics xsmax,ysmax,16,1

da = (amax-amin) / xsmax
db = (bmax-bmin) / ysmax

start = MilliSecs() ; Startzeit

LockBuffer FrontBuffer()

; pixelweise Durchmusterung des Bildes
a = amin
 For xs=0 To xsmax
  b = bmax
   For ys=0 To Int(ysmax / 2)
    x=a
    y=b
    n=0

    ; Iterationsschleife
    Repeat
     xneu = x*x - y*y + a
     yneu = 2*x*y + b
     x = xneu
     y = yneu
     radius = x*x + y*y
     n = n + 1
    Until (n > max) Or (radius > 9) ; wird Kreis verlassen

    If n < max Then WritePixelFast xs, ys, pas_color(n Mod 16)        ; dann Punkt faerben
    If n < max Then WritePixelFast xs, ysmax-ys, pas_color(n Mod 16)  ; Symmetrie
 
    b = b - db                      ; Imaginaerteil des Pixels
   Next                             ; ys-Schleife
  a = a + da                        ; Realteil des Pixels
Next                                ; xs-Schleife


UnlockBuffer FrontBuffer()
Color 0,0,0: Rect 0,0,80,15
Color 255,255,255: Text 0,0, (MilliSecs()-Start) + " ms"
WaitKey()
End


;sets the color with pascal color code
Function pas_color(pas_color)

Select pas_color
 Case 0
  Color 0,0,0
  Return a*$1000000 + 0*$10000 + 0*$100 + 0 
 Case 1
  Color 0,0,200
  Return a*$1000000 + 0*$10000 + 0*$100 + 200 
 Case 2
  Color 0,200,0
  Return a*$1000000 + 0*$10000 + 200*$100 + 0 
 Case 3
  Color 0,200,200
  Return a*$1000000 + 0*$10000 + 200*$100 + 200
 Case 4
  Color 200,0,0
  Return a*$1000000 + 200*$10000 + 0*$100 + 0 
 Case 5
  Color 200,0,200
  Return a*$1000000 + 200*$10000 + 0*$100 + 200 
 Case 6
  Color 128,64,0
  Return a*$1000000 + 128*$10000 + 64*$100 + 0 
 Case 7
  Color 200,200,200
  Return a*$1000000 + 200*$10000 + 200*$100 + 200 
 Case 8
  Color 100,100,100
  Return a*$1000000 + 100*$10000 + 100*$100 + 100
 Case 9
  Color 0,0,255
  Return a*$1000000 + 0*$10000 + 0*$100 + 255
 Case 10
  Color 0,255,0
  Return a*$1000000 + 0*$10000 + 255*$100 + 0
 Case 11
  Color 0,255,255
  Return a*$1000000 + 0*$10000 + 255*$100 + 255
 Case 12
  Color 255,0,0
  Return a*$1000000 + 255*$10000 + 0*$100 + 0
 Case 13
  Color 255,0,255
  Return a*$1000000 + 255*$10000 + 0*$100 + 255
 Case 14
  Color 255,255,0
  Return a*$1000000 + 255*$10000 + 255*$100 + 0
 Case 15
  Color 255,255,255
  Return a*$1000000 + 255*$10000 + 255*$100 + 255
 End Select

End Function
www.funforge.org

Ich hasse WASD-Steuerung.

Man kann alles sagen, man muss es nur vernünftig begründen können.

sbrog

BeitragMi, Jul 14, 2004 21:36
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich hab mal die Juliamenge übersetzt und mit Travis' beispiel aufgepeppt
Hier sieht man ungefähr, wie sich das Bild immer weiter aufbaut .

Code: [AUSKLAPPEN]

Const  amin# = -2.40, amax# = 2.40 ,bmin# = -1.75,bmax# = 1.75,xsmax = 1279, ysmax = 1023 

Global max = 1                             
Global   radius#,a#,b#,da#,db#,x#,y#,xneu#,yneu#
Global   gd,gm,n,xs,ys


gd=0

Graphics 1280,1024
SetBuffer BackBuffer()


Repeat
Cls


    da = (amax-amin) / xsmax                 
  db = (bmax-bmin) / ysmax
                 

LockBuffer BackBuffer()

  a = amin

  For xs=0 To xsmax
    b = bmax
    For ys=0 To Int(ysmax/2)
      x=a
      y=b                                         
      n=0

     
      Repeat
        xneu = x*x - y*y - 0.8
        yneu = 2*x*y + 0.15
        x = xneu
        y = yneu                       
        radius = x*x + y*y
        n = n + 1
      Until (n > max) Or (radius > 9)

             
      If n < max Then
     
      WritePixelFast xs,ys,pas_color(n Mod 16)
     EndIf
        
      If n < max Then
    
     WritePixelFast xsmax-xs,ysmax-ys,pas_color(n Mod 16)
        EndIf

      b = b - db                               
    Next 
    a = a + da   
Next                                   
UnlockBuffer BackBuffer() 


max = max +1
Flip
Until KeyHit(1)

 
End

;sets the color with pascal color code
Function pas_color(pas_color)
Select pas_color
Case 0
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 0
 Case 1
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 17
 Case 2
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 34
 Case 3
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 51
 Case 4
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 68
 Case 5
 
  Return z*$1000000 + 0*$10000 + 0*$100 +85
 Case 6
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 102
 Case 7
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 119
 Case 8
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 136
 Case 9
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 153
 Case 10
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 170
 Case 11
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 187
 Case 12
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 204
 Case 13
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 221
 Case 14
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 238
 Case 15
 
  Return z*$1000000 + 0*$10000 + 0*$100 + 255

        End Select   
End Function

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group