text fade in out over specified time
in
Programming Questions
•
1 year ago
hi,
I have created a string array and the strings are randomly selected and diplayed after the DISPLAY_TIME.
Now I want to fade out and in using alphaVal over exact this time period, so that each time the string changes
the alphaVal starts changing from 0 ->255, ->255-0.
Any help appreciated.
regards
rettnoise
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("ArialUnicodeMS-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(quotes.length));
textSize(random(20, 30));
rx = random(10, 220);
ry = random(10, 120);
alphaVal = 255;
lastTime = millis();
}
fill(66, 140, 255, alphaVal);
text(quotes[counter], rx, ry, 400, 300);
alphaVal -= a;
// if (alphaVal < 0 || alphaVal > 255) {
// a *= -1;
// }
}
String[] quotes = {
"string_1",
"string_1",
"string_1",
"string_1",
};
I have created a string array and the strings are randomly selected and diplayed after the DISPLAY_TIME.
Now I want to fade out and in using alphaVal over exact this time period, so that each time the string changes
the alphaVal starts changing from 0 ->255, ->255-0.
Any help appreciated.
regards
rettnoise
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("ArialUnicodeMS-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(quotes.length));
textSize(random(20, 30));
rx = random(10, 220);
ry = random(10, 120);
alphaVal = 255;
lastTime = millis();
}
fill(66, 140, 255, alphaVal);
text(quotes[counter], rx, ry, 400, 300);
alphaVal -= a;
// if (alphaVal < 0 || alphaVal > 255) {
// a *= -1;
// }
}
String[] quotes = {
"string_1",
"string_1",
"string_1",
"string_1",
};
1