Visualiser une fraction

 

GS (20150418) Voici une méthode pour visualiser une fraction dans n'importe quelle base grâce aux restes successifs de la division.

 # fracdraw.tcl
 # Author:      Gerard Sookahet
 # Date:        18 Apr 2015
 # Description: Fraction visualization
 # Reference: A Postmodern View of Fractions and the Reciprocals of Fermat Primes
 #            Mathematics Magazine, Vol. 73(2000), pp. 83-97

 package require Tk
  bind all <Escape> {exit}
  option add *Button.relief flat
  option add *Button.foreground white
  option add *Button.background blue
  option add *Button.width 6
  option add *Label.foreground white
  option add *Label.background black
  option add *Entry.background lightblue
  option add *Entry.relief flat

 proc FracDraw {{n 1} {d 13} {b 10} H} {
  .c delete all
  set r1 $n
  set d_1 [expr {$d-1}]
  for {set i 1} {$i <= $d_1} {incr i} {
     set r2 [expr {(1.0*$r1*$b/$d - $r1*$b/$d)*$d}]
     set r2r [expr {$r2 - int($r2)}]
     if {$r2r >= .5} {set r2 [expr {int($r2)+1}]}
     if {$r2r < .5}  {set r2 [expr {int($r2)}]}
     set s [expr {$H/($d-1)}]
     set x1  [expr {$r1*$s}]
     set x2  [expr {$r2*$s}]
     set y1 [expr {$H-$x1}]
     set y2 [expr {$H-$x2}]
     .c create line $x1 $y1 $x1 $y2 -width 2 -fill green
     .c create line $x1 $y2 $x2 $y2 -width 2 -fill green
     if {$r2 == $n} break
     set r1 $r2
  }
 }

 wm geometry . +100+1
 set H 400
 set num 1
 set den 37
 set base 35
 pack [canvas .c -width $H -height $H -bg black]
 set f1 [frame .f1 -relief flat -bg black]
 pack $f1 -fill x
 label $f1.l1 -text numerator
 entry $f1.e1 -width 4 -textvariable num
 label $f1.l2 -text denominator
 entry $f1.e2 -width 4 -textvariable den
 label $f1.l3 -text base
 entry $f1.e3 -width 4 -textvariable base
 button $f1.br -text Run -command {FracDraw $num $den $base $H}
 button $f1.bq -text Quit -command exit
 pack {*}[winfo children $f1] -side left -padx 2

Catégorie Mathématiques