Text to follow mouse
in
Programming Questions
•
10 months ago
I am currently working on a project where I would like for the text that is generated in Processing to follow the mouse. The closest example I can think of would be this here:
http://bestiario.org/web/media/19/preview/index.php?id_proyecto=19
Here is my current code:
int[] xpos = new int[1];
int[] ypos = new int[1];
PImage girl;
PFont myFont;
PFont myFont2;
ArrayList myPhrases;
//String[] allFonts = {
// myFont = loadFont("Serif-48.vlw"),
// myFont2 = loadFont("PTSans-Regular-48.vlw")
// };
String[] allPhrases = {
"Hola",
"Konichiwa",
"Hi"
};
void setup() {
size(600, 600);
myPhrases = new ArrayList() ;
for (int i=0; i < 30; i++) {
myPhrases.add(new Phrase());
}
girl = loadImage ("girl.png");
smooth();
for (int i = 0; i < xpos.length; i ++ ) {
xpos[i] = 0;
ypos[i] = 0;
}
}
void draw() {
background(255);
//For the mouse
for (int i = 0; i < xpos.length-1; i ++ ) {
xpos[i] = xpos[i+1];
ypos[i] = ypos[i+1];
}
xpos[xpos.length-1] = mouseX;
ypos[ypos.length-1] = mouseY;
for (int i = 0; i < xpos.length; i ++ ) {
noStroke();
fill(0);
image(girl, xpos[i], ypos[i]);
}
for ( int i =0; i < myPhrases.size(); i++) {
Phrase temp = (Phrase) myPhrases.get(i);
temp.display();
temp.drive();
}
}
------- Words Tab -------
class Phrase {
// Attributes
PVector myLocation;
String myPhrase = "" ;
String[] myFonts = {"PTSans-Regular-48.vlw","Serif-48.vlw","JUICERegular-48.vlw"};
PFont myFont ;
PFont myFont2 ;
int mySize ;
int CallFont;
// Constructor
Phrase() {
myLocation = new PVector(random(width), random(height)) ;
myPhrase = allPhrases[int(random(allPhrases.length))] ;
//myFonts = allFonts[int(random(allFonts.length))] ;
//myFont2 = loadFont("PTSans-Regular-48.vlw");
CallFont = int(random(3));
myFont = loadFont(myFonts[CallFont]) ;
mySize = int(random(24, 64)) ;
}
// Methods
void display () {
textFont(myFont, mySize) ;
text(myPhrase, myLocation.x, myLocation.y) ;
}
void drive() {
myLocation.x = myLocation.x+1;
if (myLocation.x > width) {
myLocation.x = 0;
}
}
}
------
Any help would be appreciated. Thank you.
1