Pentagram: Difference between revisions

2,287 bytes added ,  7 years ago
(→‎{{header|Java}}: more compact)
(→‎{{header|Tcl}}: added zkl)
Line 515:
</lang>
 
=={{header|zkl}}==
{{trans|Perl 6}}
Generate an SVG file to STDOUT. Redirect to a file to capture and display it.
<lang zkl>const DIM=200, SIDES=5, A=360/SIDES, R=DIM.toFloat();
vs:=[0.0..360-A,A].walk(); // angles of vertices
#<<<
0'|<?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
<svg height="%d" width="%d" style="" xmlns="http://www.w3.org/2000/svg">
<rect height="100%" width="100%" style="fill:bisque;" />|
#<<<
.fmt(DIM*2, DIM*2).println();
var vertices=vs.pump(List,fcn(a){ R.toRectangular(a.toRad()) }); //( (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'|<polyline points=| + pts).fmt(vs().xplode()),
0'|style="fill:seashell; stroke:blue; stroke-width:3;" |,
0'|transform="translate(%d,%d) rotate(-18)"|.fmt(DIM,DIM),
" />\n"
);
}
println("</svg>");</lang>
{{out}}
<pre>
$ zkl bbb > pentagram.svg
$ cat pentagram.svg
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
<svg height="400" width="400" style="" xmlns="http://www.w3.org/2000/svg">
<rect height="100%" width="100%" style="fill:bisque;" />
<polyline points=" 200.000, 0.000 -161.803, 117.557 " style="fill:seashell; stroke:blue; stroke-width:3;" transform="translate(200,200) rotate(-18)" />
<polyline points=" 61.803, 190.211 -161.803,-117.557 " style="fill:seashell; stroke:blue; stroke-width:3;" transform="translate(200,200) rotate(-18)" />
<polyline points="-161.803, 117.557 61.803,-190.211 " style="fill:seashell; stroke:blue; stroke-width:3;" transform="translate(200,200) rotate(-18)" />
<polyline points="-161.803,-117.557 200.000, 0.000 " style="fill:seashell; stroke:blue; stroke-width:3;" transform="translate(200,200) rotate(-18)" />
<polyline points=" 61.803,-190.211 61.803, 190.211 " style="fill:seashell; stroke:blue; stroke-width:3;" transform="translate(200,200) rotate(-18)" />
 
</svg>
</pre>
 
 
Anonymous user