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 › Gradient to text
Page Index Toggle Pages: 1
Gradient to text (Read 690 times)
Gradient to text
Jul 23rd, 2005, 1:14am
 
What could be the best/simple way to do that? Drawing the texture to PGraphic and creating the mask in another PGraphic and than copy them in my PApplet? I know this is quite odd to do in p5 and so if someone has some link or suggestions about it will be very helpful.

Thanks guys, chr
Re: Gradient to text
Reply #1 - Jul 23rd, 2005, 3:16pm
 
That sounds like the best way to do it that I can think of.

You can save some effory by using textWidth to make sure your PGraphics(2,3,GL) aren't way too big/small so you only generate the minimum data required to do it.

Just knocked this up quickly, seems to work like you'd probably expect:

Code:
PGraphics3 grad;
PGraphics3 txt;
PFont f;
PImage res;
void setup()
{
size(400,200);
f=createFont("Arial",32);
textFont(f,32);
float w=textWidth("MyText");
PGraphics3 grad=new PGraphics3((int)w,50,null);
PGraphics3 txt=new PGraphics3((int)w,50,null);
grad.defaults();
txt.defaults();
grad.background(random(255));
for(int i=0;i<200;i++)
{
grad.stroke(random(255),random(255),random(255));
grad.line(random(grad.width),random(grad.height),random(grad.width),random(grad.height));
}
txt.background(0);
txt.fill(255);
txt.textFont(f,32); // this may not be needed, I don't know
txt.text("MyText",0,32);
res=grad;
res.mask(txt);
}

void draw()
{
background(255);
image(res,width/2,height/2);
}


It's probably wrong in some respects, but gives the effecty you're looking for.

(You'll have to change the fill/random stroke part to do hatever you want to get the gradient.
Re: Gradient to text
Reply #2 - Jul 23rd, 2005, 4:27pm
 
Thanks a lot john!
Page Index Toggle Pages: 1