ulis, le 12-07-2005. Avec les rosaces, les Mathématiques nous font une fleur. Pas par le nom : conchoïde, mais par le dessin.
Pourquoi
C'est si facile avec el canvas !
Comment
Les conchoïdes de rosace dessinent des fleurs grâce à leur courbe paramétrée :
ro = a * (1 + e * cos(n * theta))
Avec ro et theta, on peut calculer les coordonnées cartésiennes :
x = ro * cos(theta) y = ro * sin(theta)
Et dessiner les points sur un canvas (ou dans une image).
Le script
# http://www.mathcurve.com/courbes2d/conchoidderosace/conchoidderosace.shtml
package require Tk
# ro = a * (1 + e * cos(n * theta))
set ::a 48
set ::e 3
set ::p 37
set ::q 3
set ::count 12
set ::size 400
set ::pi2 [expr {acos(0)}]
set ::delta 1.e-3
set ::d2 [expr {$::size / 2}]
proc createGUI {} \
{
wm title . rosace
frame .f
scale .f.a -orient horizontal \
-variable ::a -label " size" \
-from 1 -to 64 -resolution 1 -command redraw
scale .f.e -orient horizontal \
-variable ::e -label " kind" \
-from 0 -to 5 -resolution 0.1 -command redraw
scale .f.c1 -orient horizontal \
-variable ::p -label " coef 1" \
-from 1 -to 50 -resolution 0.5 -command redraw
scale .f.c2 -orient horizontal \
-variable ::q -label " coef 2" \
-from 2 -to 20 -resolution 0.5 -command redraw
scale .f.t -orient horizontal \
-variable ::count -label " turns" -digits 4 \
-from 1 -to 40 -resolution 1 -command redraw
frame .g
canvas .g.c -bd 0 -highlightt 0 \
-width $::size -height $::size
grid .f -row 0 -column 0 -sticky ns
grid .g -row 0 -column 1 -sticky nsew
grid .f.a
grid .f.e
grid .f.c1
grid .f.c2
grid .f.t
grid .g.c -sticky nsew
grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1
}
proc rosace {} \
{
.g.c delete all
set n [expr {$::p / double($::q)}]
set cnt 0
for {set theta 0} {$theta < $::count * $::pi2} {set theta [expr {$theta + $::delta}]} \
{
set ro [expr {$::a * ( 1 + $::e * cos($n * $theta) )}]
set x [expr {-int($ro * cos($theta)) + $::d2}]
set y [expr {int($ro * sin($theta)) + $::d2}]
.g.c create line $x $y [incr x] [incr y]
if {[incr cnt] == 100} { set cnt 0; update }
}
}
proc redraw {args} \
{
catch { after cancel $::after }
set ::after [after 500 rosace]
}
createGUI
redrawVoir aussi
GS Superbe. Cela me rappel le Spirographe du temps jadis.
Catégorie Exemple | Catégorie Mathématiques