REBOL [ title: "Barnsley formula" author: cyphre@rebol.com type: 'graphic Purpose: { Michael Barnsley generated the fractal pattern that's now known as Barnsley's Fern. It's supposed to resemble the Black Spleenwort, Asplenium adiantum-nigrum. } ] time: func [b /local start] [ start: now/precise do b print ["Time:" difference now/precise start] ] img-size: 512x384 oftx: 200 isx: img-size/x img: make image! img-size img/rgb: 72.96.120 view/new layout [origin 0 ii: image img] barnsley: rebcode [/local x y nb t px py ry pxi pyi idx1 idx2][ set x 64.0 set y 0.0 set px 0.0 set py 0.0 set ry 0.0 set nb 10000 repeat k nb [ set t 100 randz t to-dec t div.d t 100.0 gteq.d t 0.3 either [ set.d px x mul.d px 0.781 set.d ry y mul.d ry 0.034 add.d px ry add.d px 13.76 set.d py x mul.d py -0.032 set.d ry y mul.d ry 0.739 add.d py ry add.d py 70.2 ;draw set.d x px set.d y py set pxi x to-int pxi set pyi y to-int pyi set idx1 320 sub.i idx1 pyi mul.i idx1 isx add.i idx1 pxi add.i idx1 oftx set idx2 320 sub.i idx2 pyi add.i idx2 4 mul.i idx2 isx add.i idx2 4 add.i idx2 pxi add.i idx2 oftx poke img idx1 16777215 poke img idx2 2043711 ;end draw ][ gteq.d t 0.17 either [ set.d px x mul.d px 0.17 set.d ry y mul.d ry 0.215 sub.d px ry add.d px 52.224 set.d py x mul.d py 0.222 set.d ry y mul.d ry 0.176 add.d py ry add.d py 23.218 ;draw set.d x px set.d y py set pxi x to-int pxi set pyi y to-int pyi set idx1 320 sub.i idx1 pyi mul.i idx1 isx add.i idx1 pxi add.i idx1 oftx set idx2 320 sub.i idx2 pyi add.i idx2 4 mul.i idx2 isx add.i idx2 4 add.i idx2 pxi add.i idx2 oftx poke img idx1 16777215 poke img idx2 2043711 ;end draw ][ gteq.d t 0.02 either [ set.d px x mul.d px -0.139 set.d ry y mul.d ry 0.263 add.d px ry add.d px 72.96 set.d py x mul.d py 0.246 set.d ry y mul.d ry 0.224 add.d py ry sub.d py 9.36 ;draw set.d x px set.d y py set pxi x to-int pxi set pyi y to-int pyi set idx1 320 sub.i idx1 pyi mul.i idx1 isx add.i idx1 pxi add.i idx1 oftx set idx2 320 sub.i idx2 pyi add.i idx2 4 mul.i idx2 isx add.i idx2 4 add.i idx2 pxi add.i idx2 oftx poke img idx1 16777215 poke img idx2 2043711 ;end draw ][ set.d px 64.0 set.d py 0.27 mul.d py y ] ] ] ;draw set.d x px set.d y py set pxi x to-int pxi set pyi y to-int pyi set idx1 320 sub.i idx1 pyi mul.i idx1 isx add.i idx1 pxi add.i idx1 oftx set idx2 320 sub.i idx2 pyi add.i idx2 4 mul.i idx2 isx add.i idx2 4 add.i idx2 pxi add.i idx2 oftx poke img idx1 16777215 poke img idx2 2043711 ;end draw ; apply r show [ii] ; apply r wait [0] ] ] time [barnsley] show ii wait [] ;halt