Loading...
Logo
Processing Forum
Hi, I'm trying to display two Strings of text along two different curves in a sketch. 

I'm bringing tweets in from an excel sheet thats 100 rows in length, and I want the first 50 to display off/around one circle and the next fifty to display off/around a second circle. I can do the first fifty alright, but I can't get the second lot to display around the second ellipse that I've drawn.

The code I've included is a slimmed down version of the code that I'm working with (the code I'm working with is a bit messy and long) but if I get it working on a basic level I can transfer it over. 

Any and all help will be greatly appreciated! 
Martin
Copy code
  1. // The message to be displayed
  2. String message = "text";
  3. String message2 = "aaaa";
  4. PFont f;
  5. // The radius of a circle
  6. float r = 100;
  7. float q = r*2;

  8. float r2 = 100;
  9. float q2 = r2*2;

  10. void setup() {
  11.   size(800, 800);
  12.   f = createFont("Georgia",40,true);
  13.   textFont(f);
  14.   // The text must be centered!
  15.   textAlign(CENTER);
  16.   smooth();
  17. }

  18. void draw() {
  19.   background(255);

  20.   // Start in the center and draw the circle
  21.   translate(width / 2, height / 2);
  22.   noFill();
  23.   stroke(0);
  24.   ellipse(00, 00, r*2, r*2);

  25.   ellipse (100, 50, r2*2, r2*2);
  26.   
  27.   // We must keep track of our position along the curve
  28.   float arclength = 0;
  29.   float arclength2 = 0;

  30.     // Instead of a constant width, we check the width of each character.
  31.     //char currentChar = message.charAt(i);
  32.     float w = textWidth(message);
  33.     float w2 = textWidth(message2);
  34.     
  35.     // Each box is centered so we move half the width
  36.     arclength += w/2;
  37.     arclength += w2/2;
  38.     // Angle in radians is the arclength divided by the radius
  39.     // Starting on the left side of the circle by adding PI
  40.     float theta = PI + arclength / r;   
  41.     float theta2 = PI + arclength2 / r2;   

  42.     pushMatrix();
  43.     // Polar to cartesian coordinate conversion
  44.     translate(r*cos(theta), r*sin(theta));
  45.     translate(r2*cos(theta2), r2*sin(theta2));
  46.     // Rotate the box
  47.     rotate(theta+PI/1); // rotation is offset by 90 degrees
  48.     rotate(theta2+PI/1);
  49.     // Display the character
  50.     fill(0);
  51.     text(message,q,0);
  52.     text(message2,q2,0);
  53.     popMatrix();
  54.     // Move halfway again
  55.     arclength += w/2;
  56.     arclength += w2/2;
  57.   //}
  58. }