How to resolve the algorithm Chaos game step by step in the PARI/GP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chaos game step by step in the PARI/GP programming language
Table of Contents
Problem Statement
The Chaos Game is a method of generating the attractor of an iterated function system (IFS). One of the best-known and simplest examples creates a fractal, using a polygon and an initial point selected at random.
Play the Chaos Game using the corners of an equilateral triangle as the reference points. Add a starting point at random (preferably inside the triangle). Then add the next point halfway between the starting point and one of the reference points. This reference point is chosen at random. After a sufficient number of iterations, the image of a Sierpinski Triangle should emerge.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Chaos game step by step in the PARI/GP programming language
Source code in the pari/gp programming language
\\ Chaos Game (Sierpinski triangle) 2/15/17 aev
pChaosGameS3(size,lim)={
my(sz1=size\2,sz2=sz1*sqrt(3),M=matrix(size,size),x,y,xf,yf,v);
x=random(size); y=random(sz2);
for(i=1,lim, v=random(3);
if(v==0, x/=2; y/=2;);
if(v==1, x=sz1+(sz1-x)/2; y=sz2-(sz2-y)/2;);
if(v==2, x=size-(size-x)/2; y/=2;);
xf=floor(x); yf=floor(y); if(xf<1||xf>size||yf<1||yf>size, next);
M[xf,yf]=1;
);\\fend
plotmat(M);
}
\\ Test:
pChaosGameS3(600,30000); \\ SierpTri1.png
You may also check:How to resolve the algorithm Stable marriage problem step by step in the OCaml programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Ring programming language
You may also check:How to resolve the algorithm Loops/Do-while step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the Julia programming language
You may also check:How to resolve the algorithm Multiple distinct objects step by step in the Ruby programming language