How to resolve the algorithm Sierpinski carpet step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sierpinski carpet step by step in the zkl programming language
Table of Contents
Problem Statement
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this: The use of the # character is not rigidly required for ASCII art. The important requirement is the placement of whitespace and non-whitespace characters.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sierpinski carpet step by step in the zkl programming language
Source code in the zkl programming language
fcn drawPat(x0,y0,s,img){ // Draw 3x3 pattern with hole in middle
foreach y,x in (3,3){
if(x.isEven or y.isEven){ // don't draw middle pattern
if(s>1) self.fcn(x*s + x0, y*s + y0, s/3, img); // recurse
else img[x + x0, y + y0]=0xff0000; // red
}
}
}
img:=PPM(800,800);
drawPat(0,0,(3).pow(5),img);
img.write(File("foo.ppm","wb"));
You may also check:How to resolve the algorithm DNS query step by step in the REXX programming language
You may also check:How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Raku programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the M4 programming language
You may also check:How to resolve the algorithm Parsing/Shunting-yard algorithm step by step in the C programming language
You may also check:How to resolve the algorithm Function definition step by step in the HicEst programming language