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.
Page Index Toggle Pages: 1
Animate Text (Read 590 times)
Animate Text
Oct 8th, 2007, 1:48am
 
Does anyone know how to animate text, such as make it fall; letter by letter or make it run across the screen, etc??

Thanks,
-R.
Re: Animate Text
Reply #1 - Oct 8th, 2007, 4:15am
 
This will make it bounce:

Code:

PFont myFont;
float x = 10;
float y = 40;
float vx = 100;
float vy = 0;
float dt = 1.0/30.0;
float gravity = 400;
float restitution = .9;

void setup() {
size(300, 200);
frameRate(30);
smooth();
myFont = createFont("FFScala", 24);
textFont(myFont);
}

void draw() {
fill(0,0,0,60);
rect(0,0,width,height);
fill(255);
text("Bouncing", x, y);
vy += gravity*dt;
x += vx*dt;
y += vy*dt;
if (x < 0){
x = 0;
vx *= -restitution;
} else if (x > width-100){
//The 100 here is roughly the width
//of the text
x = width-100;
vx *= -restitution;
}
if (y > height){
y = height;
vy *= -restitution;
}
}


There's a lot you can do with text; if you want to do stuff to each letter, you just need to draw the letters separately and animate them separately.
Page Index Toggle Pages: 1