Ignore:
Timestamp:
Jul 18, 2008, 11:57:18 AM (16 years ago)
Author:
mmh
Message:

Rewritten color range code for integers and numbers.
examples/canvas rewritten.
examples/zoo/[integer|number]2 added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/spectrum.tcl

    r115 r1075  
    3636    private variable _gvals ""      ;# list of green components along axis
    3737    private variable _bvals ""      ;# list of blue components along axis
     38    private variable _spectrum 0    ;# use continuous visible spectrum
     39    private variable _specv0 0      ;# minimum value
     40    private variable _specw0 0      ;# wavelength for minimum
    3841}
    3942                                                                               
     
    6164itcl::body Rappture::Spectrum::insert {args} {
    6265    set changed 0
     66
     67    # special case. Two values in nm, then use
     68    # spectrum instead of gradient.
     69    if {[llength $args] == 4} {
     70        set cnt 0
     71        foreach {value color} $args {
     72            if {[string match "*nm" $color]} {
     73                incr cnt
     74            }
     75        }
     76        if {$cnt == 2} {
     77            set val0 [lindex $args 0]
     78            set color0 [string trimright [lindex $args 1] "nm"]
     79            set val1 [lindex $args 2]
     80            set color1 [string trimright [lindex $args 3] "nm"]
     81           
     82            if {"" != $units} {
     83                set val0 [Rappture::Units::convert $val0 \
     84                              -context $units -to $units -units off]
     85                set val1 [Rappture::Units::convert $val1 \
     86                              -context $units -to $units -units off]
     87            }
     88
     89            set _spectrum [expr (double($color1) - double($color0)) \
     90                           / (double($val1) - double($val0))]
     91            set _specv0 $val0
     92            set _specw0 $color0
     93            return
     94        }
     95    }
     96
    6397    foreach {value color} $args {
    6498        if {"" != $units} {
     
    66100                -context $units -to $units -units off]
    67101        }
    68         foreach {r g b} [winfo rgb . $color] { break }
    69 
     102        foreach {r g b} [Rappture::color::RGB $color] { break }
    70103        set i 0
    71104        foreach v $_axis {
     
    172205    switch -- $what {
    173206        -color {
     207            if {$_spectrum != 0} {
     208                # continuous spectrum. just compute wavelength
     209                set waveln [expr ($value - $_specv0) * $_spectrum + $_specw0]
     210                return [Rappture::color::wave2RGB $waveln]
     211            }
    174212            set i 0
    175213            set ilast ""
Note: See TracChangeset for help on using the changeset viewer.