
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.




Task

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.




See also
 Angle sum of a pentagram


 
package require Tk 8.6   	;# lmap is new in Tcl/Tk 8.6
 
set pi [expr 4*atan(1)]
 
pack [canvas .c] -expand yes -fill both     ;# create the canvas
 
update          ;# draw everything so the dimensions are accurate
 
set w [winfo width .c]          ;# calculate appropriate dimensions
set h [winfo height .c]
set r [expr {min($w,$h) * 0.45}]
 
set points [lmap n {0 1 2 3 4 5} {
    set n [expr {$n * 2}]
    set y [expr {sin($pi * 2 * $n / 5) * $r + $h / 2}]
    set x [expr {cos($pi * 2 * $n / 5) * $r + $w / 2}]
    list $x $y
}]
set points [concat {*}$points]  ;# flatten the list
 
puts [.c create line $points]
 
;# a fun reader exercise is to make the shape respond to mouse events,
;# or animate it!
 