|
|
Line 205: |
Line 205: |
|
(star-polygon 100 5 2 "outline" (make-pen "blue" 4 "solid" "round" "round")) |
|
(star-polygon 100 5 2 "outline" (make-pen "blue" 4 "solid" "round" "round")) |
|
(star-polygon 100 5 2 "solid" "cyan"))</lang> |
|
(star-polygon 100 5 2 "solid" "cyan"))</lang> |
⚫ |
|
|
⚫ |
This implementation draws a simple pentagram on a [http://wiki.tcl.tk/1415 Canvas] widget. |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
package require Tk 8.6 ;# lmap is new in Tcl/Tk 8.6 |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
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 r [expr {min($w,$h) * 0.45}] |
|
|
|
|
⚫ |
set points [lmap n {0 1 2 3 4 5} { |
|
⚫ |
|
|
⚫ |
set y [expr {sin($pi * 2 * $n / 5) * $r + $h / 2}] |
|
⚫ |
set x [expr {cos($pi * 2 * $n / 5) * $r + $w / 2}] |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
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, |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
|
|
=={{header|REXX}}== |
|
=={{header|REXX}}== |
Line 405: |
Line 376: |
|
Numeric Digits prec |
|
Numeric Digits prec |
|
Return r+0</lang> |
|
Return r+0</lang> |
|
|
|
|
⚫ |
|
|
⚫ |
This implementation draws a simple pentagram on a [http://wiki.tcl.tk/1415 Canvas] widget. |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
package require Tk 8.6 ;# lmap is new in Tcl/Tk 8.6 |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
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 r [expr {min($w,$h) * 0.45}] |
|
|
|
|
⚫ |
set points [lmap n {0 1 2 3 4 5} { |
|
⚫ |
|
|
⚫ |
set y [expr {sin($pi * 2 * $n / 5) * $r + $h / 2}] |
|
⚫ |
set x [expr {cos($pi * 2 * $n / 5) * $r + $w / 2}] |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
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, |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
|
|
|
|