AmiBlitz³
Barnsley fern fractal - Druckversion

+- AmiBlitz³ (https://www.amiblitz.de/community)
+-- Forum: Blitzbasic2 (https://www.amiblitz.de/community/forum-5.html)
+--- Forum: Snippets & Libraries (https://www.amiblitz.de/community/forum-11.html)
+--- Thema: Barnsley fern fractal (/thread-271.html)



Barnsley fern fractal - hackball - 26.02.2023

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:
[attachment=130]


RE: Barnsley fern fractal - asrael - 27.02.2023

Coole Sache!!!


RE: Barnsley fern fractal - hackball - 28.02.2023

Wer schreibt die erste GUI für die vielen Zahlen?