Version 8 of Rolling credits

Updated 2007-01-24 09:45:28

Richard Suchenwirth 2007-01-23 - Waiting for a lengthy zipping, I hacked up this plaything that simulates credits of a movie, rolling over the canvas screen.

http://mini.net/files/credits.jpg

 package require Tk
 proc titleshow {w title} {
    set -fill black
    set -font {Helvetica 16}
    set x [expr {[winfo width $w]/2}]
    set y [winfo height $w]
    foreach line [split $title \n] {
        set line [string trim $line]
        if [string match -* $line] {
            eval [linsert $line 0 set]
        } else {
            $w create text $x $y -text $line -fill ${-fill} -font ${-font} \
                -justify center -tag title
            incr y 48
        }
    }
    every 40 "if !\[titleshow'roll $w title -2\] return"
 }
 proc titleshow'roll  {w tag dy} {
    $w move $tag 0 $dy ;# (1)
    foreach i [$w find withtag $tag] {
        set y1 [lindex [$w bbox $i] end]
        if {$y1<0} {$w delete $i}
    }
    llength [$w find withtag $tag]
 }
 proc every {ms body} {eval $body; after $ms [info level 0]}

# That's all the code, here's a testing demo. Lines starting with - set parameters, the others are displayed:

 pack [canvas .c -bg black]
 tkwait visibility .c

 titleshow .c {
    -fill white
    -font {Helvetica 18 italic}
    Richard Suchenwirth presents
    -font {Helvetica 24 bold}
    -fill yellow
    THE IMPORTANCE
    OF BEING UNEARNEST
    -font {Helvetica 18}
    -fill white
    with
    -font {Helvetica 24}
    -fill yellow
    MARILYN MONROE
    GARY COOPER
    PETER SELLERS

    -font {Helvetica 18}
    Camera     Alphonse de Lumiere
    Gaffer     Joe Smith

    -font {Helvetica 10}
    (c) United Hackers, Inc. MMVII
 }

JM Richard, this is very nice!

do we have something in the wiki to scroll text in the same line? like the news at the bottom of the TV screen? - RS: You mean, what is sometimes called a "ticker"? You could either modify the code above (the line marked (1) in titleshow'roll has 0 for horizontal movement, put your desired value there); or, you can do it with a plain label like this. First, a proc that "cycles" a string variable, so that "abcd" becomes "bcda":

 proc string'cycle _str {
    upvar 1 $_str str
    set str [string range $str 1 end][string index $str 0]
 }

# Example for test and demo:

 pack [label .l -textvar ticker -anchor w -width 50]
 set ticker "For all those who like to read news while watching a movie, \
 here is a little ticker that displays at the bottom +++ "
 every 100 {string'cycle ::ticker}

HE and here is every


Category Animation