9-10XIST
Blinking Text
Code
String oneName = "overwhelmed";
String otherName = " ";
String displayed ="";
int interval = 500; // 0.5s
int time;
PFont font;
void setup() {
size(400, 400);
font = createFont("silom", 15);
displayed = oneName;
time = millis();
textFont(font);
fill(204,229,255);
}
void draw() {
time ++;
if(time%30==0) background(random(255),random(255),random(255));
text(displayed, width/2 - textWidth(displayed)/2, height/2);
if (millis() - time > interval) {
displayed = displayed.equals(oneName)? otherName:oneName;
time = millis();
}
}
Video Demonstration
This exercise draws texts on the screen whilst making it appear and disappear in a matter of seconds. Hence the name, the text on the screen blinks. To modify this code I changed the text, the font of the text as well as the interval from 2 seconds to 0.5 seconds. This makes the text blink faster. Lastly, I changed the colour of the background so that random colours will be drawn. Instead of creating a range of numbers that correspond with a colour, I simply inputted background(random(255), random(255), random(255)). This is an easier way of randomising a variable. The functions that the code uses include Pfont and String. There are more functions used, however, these are just a few.
(click the functions underlined to learn more about them)