News:

Function Finder  Find all the functions within source code files

Main Menu

Fractal Fern - Barnsley fern

Started by kevin, February 16, 2023, 08:32:27 AM

Previous topic - Next topic

kevin

  Fractal Fern -  Barnsley fern
 
  Here's a cool little source code snippet that was posted to one of the BASIC coding groups on facebook; so decided to made a quick PlayBASIC port of the source code.

 The code draws a fractal fern....  Net sure of the logic but it's cool little demo.


 



PlayBASIC Code: [Select]
   x# = 0
y# = 0
nextX# = 0
nextY# = 0
originX = GetScreenWidth() / 2
s = MinVal(GetScreenWidth(),GetScreenHeight()) / 10


screen =NewIMage(GetScreenWidth(),GetScreenHeight(),2)


Max = 1000000
Randomize 65

Dim RandValues#(Max)
For lp=1 to Max
RandValues#(lp) = rnd#(1)
next


do

rendertoimage Screen
cls

Ink rgb(0,c,0)
inkmode 1+16
inkAlpha 0.15

t=timer()

lockbuffer
For i = 1 To Max
a# = RandValues#(i)
If a# < 0.01
nextX# = 0
nextY# = 0.16 * y#

ElseIf a# >= 0.01 And a# < 0.08
nextX# = 0.2 * x# - 0.26 * y#
nextY# = 0.23 * x# + 0.22 * y# + 1.6

ElseIf a# >= 0.08 And a# < 0.15
nextX# = -0.15 * x# + 0.28 * y#
nextY# = 0.26 * x# + 0.24 * y# + 0.44
Else
nextX# = 0.85 * x# + 0.04 * y#
nextY# = -0.04 * x# + 0.85 * y# + 1.6
EndIf
x# = nextX#
y# = nextY#
dot x# * s + originX, y# * s
Next
unlockbuffer
inkmode 1
rendertoscreen
t=Timer()-t
drawimage screen,0,0,false
print t
sync


c=(c +1) and 255

loop Spacekey()