Page 1 of 1

Barnsley fern (fractal)

Posted: Fri Jun 22, 2018 5:13 pm
by Fig

Code: Select all

;* Barnsley fern https://en.wikipedia.org/wiki/Barnsley_fern
#x=800:#y=800
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0 Or OpenWindow(0, 0, 0, #X+1, #Y+1, "Barnsley fern", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)=0 Or OpenWindowedScreen(WindowID(0),0,0,#X+1,#Y+1,0,0,0,#PB_Screen_NoSynchronization )=0
    MessageRequester("Error", "Can't open the sprite system", 0)
    End
EndIf
x.f=0.0:y.f=0.0:xn.f=0.0:yn.f=0.0
px.f=0.0:py.f=0.0
CreateSprite(0,#x+1,#y+1)
Repeat
    FlipBuffers()
    ExamineKeyboard()
    StartDrawing(SpriteOutput(0))
    For i=1 To 100
        r.i=Random(100)
        If r<2
            xn=0
            yn=0.16*y
        ElseIf r<87
            xn=  0.85*x +  0.04*y
            yn= -0.04*x +  0.85*y + 1.6
        ElseIf r<94
            xn=  0.2* x + -0.26*y
            yn=  0.23*x +  0.22*y + 1.6
        Else
            xn= -0.15*x +  0.28*y
            yn=  0.26*x +  0.24*y + 0.44
        EndIf
        px=(xn+2.1820)*#x/4.8378
        py=yn*#y/9.9983
        py=Abs(py-#y)
        ;scale to the screen
         Plot(Int(px),Int(py),#Green)
        x=xn:y=yn
    Next i
    StopDrawing()
    DisplaySprite(0,0,0) 
    While WindowEvent() 
    Wend   
Until KeyboardPushed(#PB_Key_Escape)

Re: Barnsley fern (fractal)

Posted: Fri Jun 22, 2018 6:44 pm
by idle
Timely example fig, the All Blacks are going to play against the French's this evening

add in

Code: Select all

 StopDrawing()
    DisplaySprite(0,0,0)  
    While WindowEvent() 
    Wend   
Until KeyboardPushed(#PB_Key_Escape)

so window doesn't hang.

Re: Barnsley fern (fractal)

Posted: Fri Jun 22, 2018 7:47 pm
by Fig
yes, i often forget that in small snippets... :oops:
I corrected it, thank you.

Re: Barnsley fern (fractal)

Posted: Fri Jun 22, 2018 9:40 pm
by Trond
Interesting and neat. Thanks for sharing it.

Re: Barnsley fern (fractal)

Posted: Fri Jun 22, 2018 10:20 pm
by davido
@Fig,

Nicely done.
Thank you for sharing. :D

Re: Barnsley fern (fractal)

Posted: Sat Jun 23, 2018 10:52 pm
by Kwai chang caine
Very nice, thanks 8)

Re: Barnsley fern (fractal)

Posted: Mon Jun 25, 2018 8:19 am
by dige
:o the magic of mathematics..

Re: Barnsley fern (fractal)

Posted: Mon Jun 25, 2018 2:20 pm
by RSBasic
Small code but nice effect.

Re: Barnsley fern (fractal)

Posted: Mon Jun 25, 2018 6:50 pm
by _aNdy_
Really interesting! Thanks for share!

Re: Barnsley fern (fractal)

Posted: Mon Jun 25, 2018 9:50 pm
by Fig
idle wrote:Timely example fig, the All Blacks are going to play against the French's this evening
We all know for sure, Blacks is always the best team. :shock:
Too bad for us, poor froggies. :lol:

Thank you all for your nice comments.

Re: Barnsley fern (fractal)

Posted: Tue Jun 26, 2018 8:19 am
by idle
Fig wrote:
idle wrote:Timely example fig, the All Blacks are going to play against the French's this evening
We all know for sure, Blacks is always the best team. :shock:
Too bad for us, poor froggies. :lol:

Thank you all for your nice comments.
Problem is everytime we play the french, I bet on the French to win! :lol:

Re: Barnsley fern (fractal)

Posted: Fri Sep 07, 2018 9:13 pm
by zefiro_flashparty
:o nice!