We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › text with two or more colors
Page Index Toggle Pages: 1
text with two or more colors? (Read 697 times)
text with two or more colors?
Jul 22nd, 2007, 5:49pm
 
Hi,

Does anyone know how one can display a text with two or more colors?

For example, I want to display the word "COLOR" and I want it display in the way that each letter has a different color.

Thanks!
Daniel
Re: text with two or more colors?
Reply #1 - Jul 23rd, 2007, 11:31am
 
I have modified this example. You can use the same technique to style each letter.

- Break the string down to separate letters
- Draw letter, save location
- Draw the next letter (previous letter location + letter width) etc.

Quote:

PFont font;
int fontSize = 30;
int leftmargin = 10;
int rightmargin = 20;
String buff = "Color color";

void setup() {
 size(200, 200);
 font = createFont("Ariel", fontSize);
 textFont(font, fontSize);
}

void draw() {
 background(255);

 float rPos;
 // Store the cursor rectangle's position
 rPos = textWidth(buff)+leftmargin;

 fill(0);
 pushMatrix();
 translate(rPos,10+25);
 char k;
 for(int i=buff.length()-1; i>=0; i--){
   k = buff.charAt(i);
   translate(-textWidth(k),0);
   fill(200-(i*20),i*20,130);
   text(k,0,0);
 }
 popMatrix();
}
Re: text with two or more colors?
Reply #2 - Jul 23rd, 2007, 2:37pm
 
see also:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Suggestions;action=display;num=1181324002
Re: text with two or more colors?
Reply #3 - Jul 25th, 2007, 5:48pm
 
Wow, thanks a bunch!! It works very well!

By the way, is there a way to make the text to be bold without creating and loading another font?

Daniel
Page Index Toggle Pages: 1