Version 6 of Darts

Updated 2010-06-21 22:22:22 by gold

HJG 2007-07-13 - A dartboard, as specified at http://www.dartswdf.com/aa_darts/playdarts.html and http://en.wikipedia.org/wiki/Darts

Sorry, no gameplay yet. I think about adding some scoring.


  package require Tk

  grid [canvas .c -width 290 -height 290]
  .c config -scrollregion {-145 -145 145 145}

  set twopi    6.283185
  set halfpi   1.570796
  set SectSize 0.31415925  ;# 360/20 deg = 18 deg

  proc int x {expr int($x)}

  proc deg2rad deg { expr {$deg * atan(1)*8/360} }
  #: Convert angle from degree to radians

  proc rect_to_polar { x y } {
  #: Convert rectangular co-ordinates $x, $y to polar co-ordinates $r, $theta
     set r     [expr { hypot( $x, $y ) }]
     set theta [expr { atan2( $y, $x ) }]
     return [list $r $theta]
  }

  proc polar_to_rect { r theta } {
  #: Convert polar co-ordinates $r, $theta to rectangular co-ordinates $x, $y
     set x [expr { $r * cos($theta) }]
     set y [expr { $r * sin($theta) }]
     return [list $x $y]
  }

 #########1#########2#########3#########4#########5#########6#########7#####

  foreach {r1 c1 v1} {144 black Out  106 green Double  100 yellow Single \
                       66 red Triple  60 yellow Single  10 green DBull  4 red Bull } {
    .c create oval  -$r1 -$r1  $r1 $r1  -fill $c1  -tag $v1 -outline black
  }

 # h --> Sector
  for { set h 1 } { $h <= 20 } { incr h } {
    set angle [expr { $halfpi - $SectSize * $h }]
    set x [expr { 0 + 130 * cos($angle) }]
    set y [expr { 0 - 130 * sin($angle) }]
    set Sector [lindex {x 1 18 4 13 6 10 15 2 17 3 18 7 16 8 11 14 9 12 5 20} $h]
    .c create text $x $y -text $Sector  -font {Helvetica -14} -fill white ;# -tag wire
  }

  set xm 0
  set ym 0
  set r  106
  for {set d 9} {$d<360} {set d [expr {$d+360./20.}]} {
     set rad [deg2rad $d]
     set x [expr {$xm+cos($rad)*$r}]
     set y [expr {$ym+sin($rad)*$r}]
     .c create line $xm $ym $x $y -tag "wire"
  }


Category Graphics - Category Toys