Barnsley fern (fractal)

Advanced game related topics
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Barnsley fern (fractal)

Post 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)
Last edited by Fig on Sat Jun 23, 2018 7:28 am, edited 2 times in total.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
idle
Always Here
Always Here
Posts: 5050
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Barnsley fern (fractal)

Post 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.
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Barnsley fern (fractal)

Post by Fig »

yes, i often forget that in small snippets... :oops:
I corrected it, thank you.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Barnsley fern (fractal)

Post by Trond »

Interesting and neat. Thanks for sharing it.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Barnsley fern (fractal)

Post by davido »

@Fig,

Nicely done.
Thank you for sharing. :D
DE AA EB
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Barnsley fern (fractal)

Post by Kwai chang caine »

Very nice, thanks 8)
ImageThe happiness is a road...
Not a destination
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Barnsley fern (fractal)

Post by dige »

:o the magic of mathematics..
"Daddy, I'll run faster, then it is not so far..."
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Barnsley fern (fractal)

Post by RSBasic »

Small code but nice effect.
Image
Image
User avatar
_aNdy_
User
User
Posts: 40
Joined: Fri Jun 17, 2016 12:06 am
Contact:

Re: Barnsley fern (fractal)

Post by _aNdy_ »

Really interesting! Thanks for share!
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Barnsley fern (fractal)

Post 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.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
idle
Always Here
Always Here
Posts: 5050
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Barnsley fern (fractal)

Post 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:
Windows 11, Manjaro, Raspberry Pi OS
Image
zefiro_flashparty
User
User
Posts: 74
Joined: Fri Mar 04, 2005 7:46 pm
Location: argentina

Re: Barnsley fern (fractal)

Post by zefiro_flashparty »

:o nice!
Amd Vishera fx8350 ,16Gbram, Gtx650 ti, 2gb,Win 10pro. 13tbs. 8)
Post Reply