views:

38

answers:

1

I would like to be able to create a page using HTML and scripts to display text in which each character is of a different randomly generated color. With a javascript graphics library that supports the creation and use of RBG colors and the Math.random() method, it is simple to make randomly colored lines/shapes/etc, but I do not know how to apply that to text, let alone how to apply that to each individual character. Any ideas?

+1  A: 

Is the text generated by your script, or provided to it as HTML? If the former, try <canvas>. The latter is harder; I would wrap each character in <span style="color:#rrggbb"> using JavaScript (this will be slow).

Zack
Thanks, <canvas> was the right way to go. The text resides within a string variable that is defined within the javascript. I am using fillText() method to draw the text to the canvas. This does, however present another problem, in that I see no way to wrap the text. Would it be possible to run a CSS script inside the javascript and simply run a loop that uses javascript variables to set random color values inside CSS code for each character of the text? Thanks, Morgan
Morgan Barksdale
I don't think you can do that with canvas, no. You're going to have to do word wrapping manually.
Zack
Alright. Wrapping really isn't that important, it was just an experiment. I really appreciate your help.
Morgan Barksdale