How to resolve the algorithm Pentagram step by step in the jq programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pentagram step by step in the jq 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 jq programming language
Source code in the jq programming language
# Input: {svg, minx, miny, maxx, maxy}
def svg:
# viewBox = <min-x> <min-y> <width> <height>
"<svg viewBox='\(.minx - 4|floor) \(.miny - 4 |floor) \(6 + .maxx - .minx|ceil) \(6 + .maxy - .miny|ceil)'",
" preserveAspectRatio='xMinYmin meet'",
" xmlns='http://www.w3.org/2000/svg' >",
.svg,
"</svg>" ;
# Input: an array of [x,y] points
def minmax:
{minx: (map(.[0])|min),
miny: (map(.[1])|min),
maxx: (map(.[0])|max),
maxy: (map(.[1])|max)} ;
# Input: an array of [x,y] points
def Polyline($fill; $stroke; $transform):
def rnd: 1000*.|round/1000;
def linearize: map( map(rnd) | join(" ") ) | join(", ");
"<polyline points='"
+ linearize
+ "'\n style='fill:\($fill); stroke: \($stroke); stroke-width:3;'"
+ "\n transform='\($transform)' />" ;
# Output: {minx, miny, maxx, maxy, svg}
def pentagram($dim):
(8 * (1|atan)) as $tau
| 5 as $sides
| [ (0, 2, 4, 1, 3, 0)
| [ 0.9 * $dim * (($tau * $v / $sides) | cos),
0.9 * $dim * (($tau * $v / $sides) | sin) ] ]
| minmax
+ {svg: Polyline("seashell"; "blue"; "rotate(-18)" )} ;
pentagram(200)
| svg
You may also check:How to resolve the algorithm Additive primes step by step in the Go programming language
You may also check:How to resolve the algorithm Exceptions step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the Logtalk programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the RPL programming language
You may also check:How to resolve the algorithm Find largest left truncatable prime in a given base step by step in the Fortran programming language