Pentagram: Difference between revisions

Added Sidef
(Added Sidef)
Line 526:
Numeric Digits prec
Return r+0</lang>
 
=={{header|Sidef}}==
{{trans|Perl 6}}
Generates a SVG image to STDOUT.
<lang ruby>func pentagram(dim=200, sides=5) {
var pentagram = <<-EOT
<?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="#{dim*2}" width="#{dim*2}" style="" xmlns="http://www.w3.org/2000/svg">
<rect height="100%" width="100%" style="fill:black;" />
EOT
 
func cis(x) {
cos(x) + sin(x).i
}
 
func pline(q) {
<<-EOT
<polyline points="#{[q..., q[0], q[1]].map{|n| '%0.3f' % n }.join(' ')}"
style="fill:blue; stroke:white; stroke-width:3;"
transform="translate(#{dim}, #{dim}) rotate(-18)" />
EOT
}
 
var v = sides.range.map {|k| 0.9 * dim * cis(k * Num.tau / sides) }
pentagram += pline([v[range(0, v.end, 2)], v[range(1, v.end, 2)]].map{.reals})
pentagram += '</svg>'
 
return pentagram
}
 
say pentagram()</lang>
{{out}}
<pre>
<?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:black;" />
<polyline points="180.000 0.000 -145.623 105.801 55.623 -171.190 55.623 171.190 -145.623 -105.801 180.000 0.000"
style="fill:blue; stroke:white; stroke-width:3;"
transform="translate(200, 200) rotate(-18)" />
</svg>
</pre>
 
=={{header|Tcl}}==
2,747

edits