//code is written in processing, for more info see
//http://www.processing.org
//set the initial variables for the program
//initial text location
int textX = 50;
int textY = 50;
//initial text speed (X and Y)
int textSpeedX = 1;
int textSpeedY = 2;
void setup(){ /*void is a keword indicating a function
setup–Called once when the program is started.
Used to define initial enviroment properties
such as screen size, background color, loading images, etc.
before the draw() begins executing. */
size(200, 200);
}
void draw() {
//load/setup the font
PFont font; //PFont is the font class for Processing
font = loadFont(“Courier-14.vlw”); //loadFont loads a font
//into a variable of type PFont
textFont(font, 14); //textFont sets the current font
//create the trailing effect
//fill(128);
fill(128, 10);
rect(-1, -1, width+1, height+1);
//choose text color + draw text to the screen
fill(255);
text(“hello world”, textX, textY);
//reverse text direction when it reaches the edge of the window
if((textX >= (width-90)) || (textX <= 0)){
textSpeedX = textSpeedX*(-1);
}
if((textY >= height) || (textY <= 8)){
textSpeedY = textSpeedY*(-1);
}
//update the text location in the window
textX = textX+textSpeedX;
textY = textY+textSpeedY;
}
Advertisements