Barnsley fern: Difference between revisions
Content added Content deleted
(add F# version) |
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
||
Line 2,370: | Line 2,370: | ||
{{trans|PARI/GP}} |
{{trans|PARI/GP}} |
||
[[File:BarnsleyFernR.png|right|thumb|Output BarnsleyFernR.png]] |
[[File:BarnsleyFernR.png|right|thumb|Output BarnsleyFernR.png]] |
||
<lang |
<lang rsplus>## pBarnsleyFern(fn, n, clr, ttl, psz=600): Plot Barnsley fern fractal. |
||
## Where: fn - file name; n - number of dots; clr - color; ttl - plot title; |
## Where: fn - file name; n - number of dots; clr - color; ttl - plot title; |
||
## psz - picture size. |
## psz - picture size. |
||
Line 2,416: | Line 2,416: | ||
==='Obvious' solution=== |
==='Obvious' solution=== |
||
The matrix solution above is a clever approach, but the following solution is more readable if you're unfamiliar with linear algebra. This is very much a blind "just do what the task says" solution. It's so simple that it probably runs unadapted in S. I suspect that there is room for an interesting use of R's ifelse function somewhere, but I couldn't find a clean way. |
The matrix solution above is a clever approach, but the following solution is more readable if you're unfamiliar with linear algebra. This is very much a blind "just do what the task says" solution. It's so simple that it probably runs unadapted in S. I suspect that there is room for an interesting use of R's ifelse function somewhere, but I couldn't find a clean way. |
||
<lang |
<lang rsplus>fernOfNPoints<-function(n) |
||
{ |
{ |
||
currentX<-currentY<-newX<-newY<-0 |
currentX<-currentY<-newX<-newY<-0 |