1

I am matching each word in a given phrase with any corresponding words found in a provided sample text. I am matching the words from my given phrase with the sample text by drawing a bezier curve at each instance. My issue is the following: after I place the sample Text into an array, I don't know of a good way to draw the text again without getting weird spacing between each word. I am currently drawing each word from the array, but it's not proving to be very effect. Perhaps my entire approach is incorrect...any suggestions are greatly appreciated. This is all new to me. Thanks!

String sampleText = "this is where my sample text goes";

String phrasePart1 = "this";
String phrasePart2 = "is";
String phrasePart3 = "text";

float x = 30;
float y = 70;

size(1000, 800);
background(#FFFFFF);
smooth();

String[] wordSet = split(sampleText, " ");

fill(0);

text(phrasePart1, width/2-30, 30);
text(phrasePart2, width/2+10, 30);
text(phrasePart3, width/2+30, 30);

for (int i = 0; i < wordSet.length; i++) {

  textSize(6);
  text(wordSet[i], x, y);


  if (wordSet[i].equals(phrasePart1)) {
    noFill();
    stroke(153);
    smooth();
    bezier(width/2-35, 27, 30, 30, 40, random(30, 200), x+5, y-9);
  }

    if (wordSet[i].equals(phrasePart2)) {
    noFill();
    stroke(153);
    smooth();
    bezier(width/2+13, 33, 670, 30, 680, random(30, 200), x+5, y-9);
    }

  if (wordSet[i].equals(phrasePart3)) {
    noFill();
    stroke(153);
    smooth();
    bezier(width/2+50, 27, 670, 30, 680, random(30, 200), x+5, y-9);
  }

  x = x + wordSet[i].length()*3+4;


  if (x > width-50) {
    x = 30;
    y = y + 12;
  }
}
3
  • What graphics API are you using? Commented Oct 27, 2013 at 10:11
  • 1
    What language is this? Is this Java? I looks like Java except for this line: background(#FFFFFF); Commented Oct 27, 2013 at 10:20
  • 1
    "Processing" is the language. I love it, but it's got a pretty confusing name... Commented Oct 28, 2013 at 14:03

1 Answer 1

2

Try replacing

x = x + wordSet[i].length()*3+4;

at the bottom of your for loop with textWidth

x = x + textWidth(wordSet[i] + " " );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.