strimj animation

set {docu(strimj animation)} { Richard Suchenwirth - As simple as as the strimj concept is, its limits are somewhere near your imagination. I woke up this morning with the idea that it might be nice to arrange several string images in a row and cyclically show one of them on a label or button - in other words, animation, running a film. See how simple it goes with strimjes... }

 namespace eval strimj {
    variable running ;# array, will hold the path(s) of running film(s)
 }

set docu(strimj::film) { Prepares a film by converting the strimjes given as arguments into photo images. Returns the list of image names, to be used with the [strimj::runFilm] command. Requires the strimj::photo routine from strimj - string image routines. }

 proc strimj::film args {
    set res {}
        foreach si $args {
        lappend res [photo $si]
    }
    set res
 }

set docu(strimj::runFilm) { Assign a film as prepared by [strimj::film] to a widget that takes an -image option (button or label). You can specify whether it shall run continuously (default: 1) and at how many frames per second (default: 25). You can later stop the show with setting strimj::running($w) to 0. }

 proc strimj::runFilm {w film args} {
    variable running
    array set opt [::concat {-continuous 1 -freq 25} $args]
    set running($w) $opt(-continuous)
    runFilm1 $w [expr {1000/$opt(-freq)}] [::concat $film {{}}]
 }

set docu(strimj::runFilm1) { This is the scheduler that checks whether to stop at end of film, and reschedules itself to show the next frame. }

 proc strimj::runFilm1 {w interval film} {
    variable running
    set first [lindex $film 0]
    if {$first==""} {
        if {$running($w)} {
            set film [::concat [lrange $film 1 end] {{}}]
            set first [lindex $film 0]
        } else return
    }
    $w configure -image $first
    set film [::concat [lrange $film 1 end] [lindex $film 0]]
    after $interval [list strimj::runFilm1 $w $interval $film]
 }
 if 0 {

Here's a stupid little demo film that is run when this file is started at toplevel (and you have the file from strimj - string image routines in your working directory). It shows, on changing background, a T (T for Tcl, of course) raising to upright position, plus a black dot drifting from left to right. Of course, the real work of making good films is only beginning... You produce your film best by writing a rectangular strimj for the background, copy it for the number of frames needed, and edit in the animated parts in Overwrite mode.

 }
 if {[file tail [info script]]==[file tail $argv0]} {
    source strimj.tcl
    pack [button .l -text "Soon showing..."] -fill both -expand 1
    .l config -command {set strimj::running(.l) 0}
    update
    strimj::runFilm .l [strimj::film {
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@
 .@@@@@@@@@@@@@@@
 .@@@@@@@@@@@@@@@
 .@@@@@@@@@@@@@@@
 .@@@@@@@@@@@@@@@
 ................
 } {
 b#bbbbbbbbbbbbbb
 bbbbbbbbbbbbbbbb
 bbbbbbbbbbbbbbbb
 bbbbbbbbbbbbbbbb
 bbbbbbbbbbbbbbbb
 bbbbbbbbbbbbbbbb
 bbbbbbbbbbbbbbbb
 bbbbbbbbbbbbbbbb
 bbbbbbbbbbbbbbbb
 bybbbbbbbbbbbbbb
 bybbbbbbbbbbbbbb
 bybbbbbbbbbbbbbb
 byyybbbbbbbbbbbb
 ybbbyyyybbbbbbbb
 ybbbbbbbyyyybbbb
 ybbbbbbbbbbbyyyy
 } {
 cc#ccccccccccccc
 cccccccccccccccc
 cccccccccccccccc
 cccccccccccccccc
 cccccccccccccccc
 cccccccccccccccc
 cccccccccccccccc
 ccccgccccccccccc
 ccccgccccccccccc
 ccccgccccccccccc
 cccgcccccccccccc
 cccgcccccccccccc
 cccggggccccccccc
 ccgccccgggcccccc
 ccgcccccccgggccc
 ccgccccccccccggg
 } {
 ggg#gggggggggggg
 gggggggggggggggg
 gggggggggggggggg
 gggggggggggggggg
 gggggggggggggggg
 ggggcggggggggggg
 ggggcggggggggggg
 gggcgggggggggggg
 gggcgggggggggggg
 ggccgggggggggggg
 gcggccgggggggggg
 gcggggccgggggggg
 cgggggggccgggggg
 cgggggggggccgggg
 ggggggggggggccgg
 ggggggggggggggcc
 } {
 yyyy#yyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyybbyyy
 yyyyyyyyybbyyyyy
 yyyyyyybbyyyyyyy
 yyyyybbybbyyyyyy
 yyybbyyyybbyyyyy
 ybbyyyyyyybbyyyy
 yyyyyyyyyyybbyyy
 yyyyyyyyyyyybbyy
 yyyyyyyyyyyyybby
 } {
 .....#..........
 ................
 ................
 ................
 ................
 ................
 ................
 ..........#####.
 ....######......
 ........##......
 .........##.....
 .........##.....
 ..........##....
 ..........##....
 ...........##...
 ...........##...
 } {
 yyyyyy#yyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyyyy
 yyyyyyyyyyymmmmy
 yyyyymmmmmmyyyyy
 yyyyyyyymmyyyyyy
 yyyyyyyymmyyyyyy
 yyyyyyyyymmyyyyy
 yyyyyyyyymmyyyyy
 yyyyyyyyymmyyyyy
 yyyyyyyyyymmyyyy
 yyyyyyyyyymmyyyy
 yyyyyyyyyymmyyyy
 } {
 ooooooo#oooooooo
 oooooooooooooooo
 oooooooooooooooo
 oooooooooooooooo
 oooooooooooooooo
 oooooooooooooooo
 oooooooooooooooo
 oooooooorrrrrroo
 oooorrrrrroooooo
 oooooooorroooooo
 oooooooorroooooo
 oooooooorroooooo
 ooooooooorrooooo
 ooooooooorrooooo
 ooooooooorrooooo
 ooooooooorrooooo
 } {
 rrrrrrrr#rrrrrrr
 rrrrrrrrrrrrrrrr
 rrrrrrrrrrrrrrrr
 rrrrrrrrrrrrrrrr
 rrrrrrrrrrrrrrrr
 rrrrrrrrrrrrrrrr
 rrrrrrrrrrrrrrrr
 rrrrrrrrrrrrrrrr
 rrroooooooooorrr
 rrrrrrroorrrrrrr
 rrrrrrroorrrrrrr
 rrrrrrroorrrrrrr
 rrrrrrroorrrrrrr
 rrrrrrroorrrrrrr
 rrrrrrroorrrrrrr
 rrrrrrroorrrrrrr
 } {
 mmmmmmmmm#mmmmmm
 mmmmmmmmmmmmmmmm
 mmmmmmmmmmmmmmmm
 mmmmmmmmmmmmmmmm
 mmmmmmmmmmmmmmmm
 mmmmmmmmmmmmmmmm
 mmmmmmmmmmmmmmmm
 mmmmmmmmmmmmmmmm
 mmmyyyyyyyyyyymm
 mmmmmmmyymmmmmmm
 mmmmmmmyymmmmmmm
 mmmmmmmyymmmmmmm
 mmmmmmmyymmmmmmm
 mmmmmmmyymmmmmmm
 mmmmmmmyymmmmmmm
 mmmmmmmyymmmmmmm
 }]
 }

Related strimj - string image routines | Arts and crafts of Tcl-Tk programming