Domanda

To set a color of node in ns2 with TCL script we use

set n0 [$ns node]
set n1 [$ns node]

$n0 color red
$n1 color green

This works fine, but what to write in the script so that we can use hexadecimal values like #0000FF, #FF00FF etc. or RGB values to set color of node.

È stato utile?

Soluzione

Assuming that the color just gets passed through to Tk for display, you would just write:

$n0 color "#FF0000"

(It's only in quotes because of the syntax highlighting here on Stack Overflow; Tcl only interprets # as meaning a comment at the start of a command.)

The order of color components is red (2 hex digits normally), green (2 hex), blue (2 hex). If you're wanting to generate the value from three numbers in the range 0–255, use this sort of road-tested recipe:

$n0 color [format "#%02x%02x%02x" $r $g $b]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top