Fade text out
in
Programming Questions
•
5 months ago
I have a sketch that randomly pulls words from a .txt document and places them in random spots on the sketch. I want the words to fade out after a few seconds, but can't figure out how. Here is the code:
float r;
float g;
float b;
float a;
float diam;
float x;
float y;
void setup() {
size(1280,720, P3D);
background(0);
smooth();
frameRate(2);
// textSize(30);
PFont font;
font = loadFont("SansSerif-48.vlw");
textFont(font, 40);
fill(255);
text("I'M SORRY.", 30, 50);
text("I'M HAPPY.", 30, 86);
textSize(15);
}
void draw() {
// Each time through draw(), new random numbers are picked for a new ellipse.
r = random(125,255);
g = random(125,255);
b = random(125,255);
a = random(0,255);
x = random(0,1280);
y = random(100,720);
String[] wordy=loadStrings("http://thepanthernaut.com/happyregrets/answers.txt");
//diam = random(20);
// x = random(width);
// y = random(height);
// Use values to draw an ellipse
noStroke();
fill(r,g,b,a);
int index = int (random(wordy.length));
text(wordy[index],x,y);
}
I want the words to act like they do in the following sketch, but need them to appear on the sketch more often than one at a time:
PFont font;
int counter;
final int DISPLAY_TIME = 3000; // 2000 ms = 2 seconds
int lastTime; // When the current image was first displayed
float rx = 120;
float ry = 160;
float alphaVal = 255;
float a = 1.5;
void setup() {
size(640, 480);
background(255);
font = loadFont("Calibri-48.vlw");
textFont(font);
textSize(random(22, 35));
fill(66, 190, 255);
lastTime = millis();
}
void draw()
{
background(255);
if (millis() - lastTime >= DISPLAY_TIME) // Time to display next image
{
counter = int(random(wordy.length));
textSize(random(20, 30));
rx = random(10, 220);
ry = random(10, 120);
alphaVal = 255;
lastTime = millis();
}
fill(66, 140, 255, alphaVal);
text(wordy[counter], rx, ry, 400, 300);
alphaVal -= a;
// if (alphaVal < 0 || alphaVal > 255) {
// a *= -1;
// }
}
String[] wordy=loadStrings("http://thepanthernaut.com/happyregrets/answers.txt");
Help is very appreciated!
1