Rotation de texte avec pixane

 

Kroc 17 Juin 2008 : Comme pixane manque cruellement d'exemples, voilà une petite démo de rotation de texte :

    package require Tk
    package require tile
    package require pixane

    proc texte {texte size angle fg bg} {
        set f [pixfont create -builtin "serif"]
        foreach {l h p} [pixfont measure $f $size $texte] {}
        set p [pixane create]
        pixane resize $p $l $l
        pixane compose $p replace
        pixane color $p $bg
        pixane fill $p
        pixane compose $p over
        pixane color $p $fg
        set a [expr {$angle * acos(0) / 90}]
        pixane text $p [expr {$l/2}] [expr {$l/2}] -font $f -size $size -align center -valign middle -text $texte -angle $a
        return $p
    }

    proc tourne {src angle bg} {
        set p [pixane create]
        set a [expr {$angle * acos(0) / 90}]
        pixane resize $p [pixane width $src] [pixane height $src]
        pixane compose $p replace
        pixane color $p $bg
        pixane fill $p
        pixane compose $p over
        pixane scale $p $src -angle $a
        return $p
    }

    image create photo totof
    image create photo totoi
    pack [::ttk::label .lf] [::ttk::label .li]

    proc run {} {
        for {set a 0} {$a < 360} {incr a 3} {
            if {![info exists ::pf($a)]} {
                set ::pf($a) [texte "toto a mangé !" 35 $a #FF4C00 #FFAA00]
            }
            pixcopy $::pf($a) totof
            .lf configure -image totof
            if {![info exists ::pi($a)]} {
                set ::pi($a) [tourne $::pf(0) $a #FFAA00]
            }
            pixcopy $::pi($a) totoi
            .li configure -image totoi
            update
        }
        run
    }

    after idle run
    tkwait window .
    exit

Catégorie exemple