We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Problem with the text() function
Page Index Toggle Pages: 1
Problem with the text() function (Read 583 times)
Problem with the text() function
Apr 17th, 2010, 4:16am
 
Hi, I'm having some issues with the text() function that I haven't had before. I'm creating a timeline of books read, and it relies upon a .tsv table (imported using Ben Fry's Table class code from his website). All of that's fine, and I haven't had trouble like this before, but when I go to create text for when the mouse hovers over one of the points on the timeline, it only shows text if it refers to a number (whether int or float), not a bunch of letters.

Below is my code (not including the Table code - that's available on Ben Fry's website):

Code:
//Books that changed my life
//by Meiko Georgouras

PFont headerFont;
PFont titleFont;
PFont bodyFont;
PShape bookShape;
Table bookList;
int rowCount;

void setup() {
size(800, 500);
headerFont = loadFont("1942report-22.vlw");
titleFont = loadFont("BookmanOldStyle-BoldItalic-12.vlw");
bodyFont = loadFont("BookmanOldStyle-12.vlw");
bookList = new Table("booklist.tsv");
bookShape = loadShape("book.svg");
rowCount = bookList.getRowCount();
}

void draw() {
background(200,210,214);
smooth();
shape(bookShape, 30, 30, 120, 96);
fill(0);
textFont(headerFont, 22);
text("The Books that Shaped My Life", 200, 80);
fill(173,201,203);
noStroke();
rect(0, 350, 800, 150);
for (int row = 0; row < rowCount; row++) {
String header = bookList.getRowName(row);
float title = bookList.getFloat(row, 0);
float author = bookList.getFloat(row, 1);
float name = bookList.getFloat(row,5);
int read = bookList.getInt(row, 2);
int birth = bookList.getInt(row, 3);
int yr = bookList.getInt(row, 4);
int l = (yr-birth)*10;
fill(255, 30);
textFont(bodyFont,12);
noStroke();
rect(30, 349, l, 2);
stroke(255);
line(30,349, 30, 359);
text(birth, 15, 380);
line(30+l, 349, 30+l, 359);
text(yr, l+15, 380);
int x = (read-birth)*10+30;
fill(255);
noStroke();
ellipse(x,350,6,6);
fill(0);
if (mouseX<=x+6 && mouseY<=350+6 && mouseX>=x-6 && mouseY>=350-6) {
fill(0);
text(read,mouseX+5,mouseY);
fill(255,0,0);
text(author,mouseX+3, mouseY+10);
} else {
fill(0);
text(" ",mouseX,mouseY);
}

}
}


However, this other project I did has no problem working and happily shows both the area's name and the indicator:

Code:
PImage mapImage;
PFont font;
Table locationTable;
int rowCount;

void setup() {
size(1126,732);
font = loadFont("Calibri-12.vlw");
textFont(font, 12);
mapImage = loadImage("vic3.png");
locationTable = new Table("vic_financialstress.tsv");
rowCount = locationTable.getRowCount();
}

void draw() {
background(255);
image(mapImage, 0, 0);
smooth();
noStroke();
for (int row = 0; row < rowCount; row++) {
String title = locationTable.getRowName(row);
float name = locationTable.getFloat(row,0);
float x = locationTable.getFloat(row, 1);
float y = locationTable.getFloat(row, 2);
float mapping = locationTable.getFloat(row, 3);
int number = locationTable.getInt(row, 4);
float colour = locationTable.getFloat(row, 5);
fill(#b22222, number*3);
ellipse(x, y, colour/6, colour/6);
if (mouseX<=x+10 && mouseY<=y+10 && mouseX>=x-10 && mouseY>=y-10) {
fill(0);
text(title,mouseX+5,mouseY);
fill(255,0,0);
text(number,mouseX+3, mouseY+10);
} else {
fill(0);
text(" ",mouseX,mouseY);
}
}
}


Could you please help me with this?
Re: Problem with the text() function
Reply #1 - Apr 17th, 2010, 8:59am
 
   float title = bookList.getFloat(row, 0);
   float author = bookList.getFloat(row, 1);    
   float name = bookList.getFloat(row,5);

name, title, author won't be floats.

http://processing.org/reference/float.html
http://processing.org/reference/String.html
Page Index Toggle Pages: 1