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 › find position of letters in a text
Page Index Toggle Pages: 1
find position of letters in a text (Read 1933 times)
find position of letters in a text
May 31st, 2010, 2:54pm
I'm looking for displaying text and link all the letters "a" by a line.
in order to do that I need to know the position (x,y) of each letters in my text.

i've begin that but I absolutely don't know how to find the position (x,y) of all my letters "a" in the text

there the beginning of my prog:


PFont fontA;
char[] lettres;
int taillems;
String chaine="";
String montexte;
String[] paragraphe;
ArrayList positionA;
int lesA;
int lesespaces;

void setup() {
 size(1024, 768);
 // Set the font and its size (in units of pixels)
 fontA = loadFont("AvantGardeLT-Book-48.vlw");
 textFont(fontA, 32);
 //loading text
 paragraphe= loadStrings("essai.txt");
 // initialisation variables
 lesA = 0;
 positionA=new ArrayList();
 //decouper la chaine en element individuels/////////////////////////////////////////////
 for(int i = 0; i < paragraphe.length; i++) {
   chaine += paragraphe[ i];  
 //detecter les a dans une chaine caractere//////////////////////////////////////////////
 for (int i = 0; i < taillems; i = i+1) {
 println("il y a " + lesA + " A");

void draw(){

thanks to help me I go crazy
Re: find position of letters in a text
Reply #1 - Jun 1st, 2010, 3:11am
You are getting the character positions for the letters A/a once you have that you can calculate the number of pixels from the start of the string to the character using textWidth(); e.g.

// if p is the charater position in string s then
// px = number of pixels to start of character
px = textWidth(s.substring(p));

Re: find position of letters in a text
Reply #2 - Jun 1st, 2010, 3:48pm
When I have the time I'll help you with a nice "classy" way of doing it! Would be fun.
Re: find position of letters in a text
Reply #3 - Jun 1st, 2010, 3:49pm
if a monospaced type is an option you probably save a lot of work as you know that every char has the same width.
Page Index Toggle Pages: 1