Howdy johnkenyon:
Bo said:
> How 'bout this:
>
> color-text: func [intensity text][
> rejoin [
> {<FONT color="#}
> copy/part tail form to-hex to-integer intensity * 2.55 -2
> {8000">} text </FONT>]
>]
Here's another approach, a little less string-concatenatey:
;- You get back a block with two tag!s surrounding whatever 'text is
color-text: func [intensity text][
compose [ (build-tag [FONT COLOR
(mold join # [enbase/base form to-char intensity * 2.55 16 8000])])
(text) </FONT>
]
]
ENBASE is a pretty cool function. It lets the above code use less
conversions which lends it some efficiency. (An implicit integer
round off occurs with to-char by the way.) The real efficency win,
however, comes from doing less copying.
Lets see: The first example does a decimal to integer to hex to
string to a copy of part of that string joined to copies of other
strings, including the passed in text.
The second example does a decimal to a char to a string, joined (which
copies) with an empty issue made into a tag, which is dropped into a
block with the text and another tag, with out copying the original
passed in text.
Generally speaking the second example will do less copying especially
if the text passed in grows large. Also, the second example treats
numeric data in a more numeric way. Finally, the result of the second
example maintains its distinct datatypes, which could be useful if you
want distinguish tags from text in the result later on without having
to parse it. The second takes a more symbolic approach.
Not to cast any hint of aspersion on Bo's solution! (-: It certainly
suffices for your purposes just fine, and it may be more intuitive to
some. I only mean to suggest that in REBOL, as in all languages, there
is always room for optimization. REBOL is a symbolic language, so
symbolic approaches to problem solving will generally be more
efficient in REBOL than approaches based largely on string
manipulation.
But of course I don't imagine that my approach is the most optimal
either!! :-)
Just trying to be helpful....
-jeff