How to resolve the algorithm Barnsley fern step by step in the PARI/GP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Barnsley fern step by step in the PARI/GP programming language
Table of Contents
Problem Statement
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS).
Create this fractal fern, using the following transformations: Starting position: x = 0, y = 0
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Barnsley fern step by step in the PARI/GP programming language
Source code in the pari/gp programming language
\\ Barnsley fern fractal
\\ 6/17/16 aev
pBarnsleyFern(size,lim)={
my(X=List(),Y=X,x=y=xw=yw=0.0,r);
print(" *** Barnsley Fern, size=",size," lim=",lim);
plotinit(0); plotcolor(0,6); \\green
plotscale(0, -3,3, 0,10); plotmove(0, 0,0);
for(i=1, lim,
r=random(100);
if(r<=1, xw=0;yw=0.16*y,
if(r<=8, xw=0.2*x-0.26*y;yw=0.23*x+0.22*y+1.6,
if(r<=15, xw=-0.15*x+0.28*y;yw=0.26*x+0.24*y+0.44,
xw=0.85*x+0.04*y;yw=-0.04*x+0.85*y+1.6)));
x=xw;y=yw; listput(X,x); listput(Y,y);
);\\fend i
plotpoints(0,Vec(X),Vec(Y));
plotdraw([0,-3,-0]);
}
{\\ Executing:
pBarnsleyFern(530,100000); \\ BarnsleyFern.png
}
You may also check:How to resolve the algorithm Cuban primes step by step in the Go programming language
You may also check:How to resolve the algorithm Polynomial long division step by step in the OCaml programming language
You may also check:How to resolve the algorithm Empty string step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the OCaml programming language
You may also check:How to resolve the algorithm Maze generation step by step in the OCaml programming language