How to resolve the algorithm Pentagram step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pentagram step by step in the zkl programming language
Table of Contents
Problem Statement
A pentagram is a star polygon, consisting of a central pentagon of which each side forms the base of an isosceles triangle. The vertex of each triangle, a point of the star, is 36 degrees.
Draw (or print) a regular pentagram, in any orientation. Use a different color (or token) for stroke and fill, and background. For the fill it should be assumed that all points inside the triangles and the pentagon are inside the pentagram.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Pentagram step by step in the zkl programming language
Source code in the zkl programming language
const DIM=200, SIDES=5, A=360/SIDES, R=DIM.toFloat();
vs:=[0.0..360-A,A].apply("toRad"); // angles of vertices
#<<<
0'|
"http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
|
#<<<
.fmt(DIM*2, DIM*2).println();
var vertices=vs.pump(List,fcn(a){ R.toRectangular(a) }); //( (x,y), (x,y)...
SIDES.pump(String,pline).println(); // the line pairs that draw the pentagram
fcn pline(n){ a:=(n + 2)%SIDES; // (n,a) are the endpoints of the right leg
pts:=String("\"", ("% 0.3f,% 0.3f "*2), "\" "); // two points
vs:='wrap(){ T(n,a).pump(List,vertices.get).flatten() }; //(x,y, x,y)
String(
(0'|
0'|style="fill:seashell; stroke:blue; stroke-width:3;" |,
0'|transform="translate(%d,%d) rotate(-18)"|.fmt(DIM,DIM),
" />\n"
);
}
println("");
You may also check:How to resolve the algorithm Yin and yang step by step in the Logo programming language
You may also check:How to resolve the algorithm Munchausen numbers step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the Ada programming language
You may also check:How to resolve the algorithm Factorial step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Ramanujan primes/twins step by step in the F# programming language