Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Barnsley fern fractal
#1
This is a fun to do fractal with lots of numbers to play with for diffferent results.

You can read more about the algorithm and example code here:

https://en.wikipedia.org/wiki/Barnsley_fern

This is a quick implementation in BlitzBasic.
Code:
WbToScreen1


num.l=1000000    ;number of iterations

Window1,0,0,ScreenWidth,ScreenHeight,$140F,"Barnsley fern fractal. it="+Str$(num),2,1

ResetTimer

x.q     = 0
y.q     = 0
nextX.q = 0
nextY.q = 0

originX =  ScreenWidth / 2

s = Min( ScreenWidth, ScreenHeight ) / 10

For i.l = 1 To num
    a.q = Rnd

    If a.q < 0.01
         nextX.q = 0
         nextY.q = 0.16 * y.q
    Else

       If a.q >= 0.01 AND a.q < 0.08

             nextX.q = 0.2 * x.q - 0.26 * y.q
             nextY.q = 0.23 * x.q + 0.22 * y.q + 1.6
       Else

         If a.q >= 0.08 AND a.q < 0.15

             nextX.q = -0.15 * x.q + 0.28 * y.q
             nextY.q = 0.26 * x.q + 0.24 * y.q + 0.44

         Else

             nextX.q = 0.85 * x.q + 0.04 * y.q
             nextY.q = -0.04 * x.q + 0.85 * y.q + 1.6

         EndIf

       EndIf

    EndIf

    x.q = nextX.q
    y.q = nextY.q

    WPlot x.q * s + originX, y.q * s,1
Next

Print Ticks," ticks"

Repeat

Until WaitEvent=$200   ;windowclose

End
and this is how it looks like:
   
Zitieren
#2
Coole Sache!!!
Zitieren
#3
Wer schreibt die erste GUI für die vielen Zahlen?
Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 2 Gast/Gäste