It is currently Thu Jul 02, 2020 7:50 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Barnsley fern (fractal)
PostPosted: Fri Jun 22, 2018 5:13 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 328
Location: Côtes d'Azur, France
Code:
;* 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)

_________________
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS


Last edited by Fig on Sat Jun 23, 2018 7:28 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Fri Jun 22, 2018 6:44 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3525
Location: New Zealand
Timely example fig, the All Blacks are going to play against the French's this evening

add in
Code:
 StopDrawing()
    DisplaySprite(0,0,0) 
    While WindowEvent()
    Wend   
Until KeyboardPushed(#PB_Key_Escape)


so window doesn't hang.


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Fri Jun 22, 2018 7:47 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 328
Location: Côtes d'Azur, France
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Fri Jun 22, 2018 9:40 pm 
Offline
Always Here
Always Here

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7446
Location: Norway
Interesting and neat. Thanks for sharing it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Fri Jun 22, 2018 10:20 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1766
Location: Uttoxeter, UK
@Fig,

Nicely done.
Thank you for sharing. :D

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Sat Jun 23, 2018 10:52 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4685
Location: Lyon - France
Very nice, thanks 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Mon Jun 25, 2018 8:19 am 
Offline
Addict
Addict
User avatar

Joined: Wed Apr 30, 2003 8:15 am
Posts: 1027
Location: Germany
:o the magic of mathematics..

_________________
"Daddy, I'll run faster, then it is not so far..."


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Mon Jun 25, 2018 2:20 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1112
Location: Gernsbach (Germany)
Small code but nice effect.

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Mon Jun 25, 2018 6:50 pm 
Offline
User
User
User avatar

Joined: Fri Jun 17, 2016 12:06 am
Posts: 27
Really interesting! Thanks for share!

_________________
Arkanix Labs | Cosine Systems | Compilation64


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Mon Jun 25, 2018 9:50 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 328
Location: Côtes d'Azur, France
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Tue Jun 26, 2018 8:19 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3525
Location: New Zealand
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:


Top
 Profile  
Reply with quote  
 Post subject: Re: Barnsley fern (fractal)
PostPosted: Fri Sep 07, 2018 9:13 pm 
Offline
User
User
User avatar

Joined: Fri Mar 04, 2005 7:46 pm
Posts: 73
Location: argentina
:o nice!

_________________
Amd Vishera fx8350 ,16Gbram, Gtx650 ti, 2gb,Win 10pro. 13tbs. 8)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye